From 439778465d87c3d9d450b83ec5ee496fa7e117ba Mon Sep 17 00:00:00 2001 From: Rock070 Date: Sun, 31 Dec 2023 03:17:45 +0800 Subject: [PATCH] Fix maybe_icecream function to handle time_of_day correctly --- exercises/12_options/options1.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/exercises/12_options/options1.rs b/exercises/12_options/options1.rs index e131b48b..5338b929 100644 --- a/exercises/12_options/options1.rs +++ b/exercises/12_options/options1.rs @@ -13,7 +13,13 @@ fn maybe_icecream(time_of_day: u16) -> Option { // 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)); } }