Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(options1): follows requirements #3

Open
wants to merge 2 commits into
base: solutions
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions exercises/options/options1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
// We use the 24-hour system here, so 10PM is a value of 22 and 12AM is a value of 0
// The Option output should gracefully handle cases where time_of_day > 23.
if time_of_day <= 10 {
if time_of_day > 23 {
None
} else if time_of_day < 22 {
Some(5)
} else if time_of_day <= 23 {
Some(0)
} else {
None
Some(0)
}
}

Expand All @@ -32,7 +32,11 @@ mod tests {
#[test]
fn raw_value() {
// TODO: Fix this test. How do you get at the value contained in the Option?
let icecreams = maybe_icecream(12);
assert_eq!(icecreams, Some(0));
let result = maybe_icecream(12);

match result {
Some(icecreams) => assert_eq!(icecreams, 5),
None => println!("Err"),
}
}
}