finished option1 excercise

This commit is contained in:
Ruud Salym J Erie 2022-12-12 23:22:49 -03:00
parent 0971fb6dec
commit b25970e131

View File

@ -8,9 +8,13 @@
// all, so there'll be no more left :(
// TODO: Return an Option!
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
// 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);
}
}