Fix maybe_icecream function to handle time_of_day correctly

This commit is contained in:
Rock070 2023-12-31 03:17:45 +08:00
parent b4cf7e4ef8
commit 439778465d

View File

@ -13,7 +13,13 @@ fn maybe_icecream(time_of_day: u16) -> Option<u16> {
// value of 0 The Option output should gracefully handle cases where
// time_of_day > 23.
// TODO: Complete the function body - remember to return an Option!
???
if time_of_day >= 22 && time_of_day <= 24 {
return Some(0);
} else if time_of_day >= 24 {
return None;
}
Option::Some(5)
}
#[cfg(test)]
@ -34,6 +40,6 @@ mod tests {
// TODO: Fix this test. How do you get at the value contained in the
// Option?
let icecreams = maybe_icecream(12);
assert_eq!(icecreams, 5);
assert_eq!(icecreams, Some(5));
}
}