diff --git a/exercises/options/options1.rs b/exercises/options/options1.rs index d1735c2f..41d3ea2c 100644 --- a/exercises/options/options1.rs +++ b/exercises/options/options1.rs @@ -8,9 +8,13 @@ // all, so there'll be no more left :( // TODO: Return an Option! fn maybe_icecream(time_of_day: u16) -> Option { - // We use the 24-hour system here, so 10PM is a value of 22 - // The Option output should gracefully handle cases where time_of_day > 24. - ??? + if time_of_day < 22 { + Some(5) + } else if time_of_day >= 22 && time_of_day <= 24 { + Some(0) + } else { + None + } } #[cfg(test)] @@ -29,7 +33,7 @@ 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); + let icecreams = maybe_icecream(12).expect("Unexpected None value");; assert_eq!(icecreams, 5); } }