1- // This function returns how much icecream there is left in the fridge.
1+ // This function returns how much ice cream there is left in the fridge.
22// If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00,
3- // someone eats it all, so no icecream is left (value 0). Return `None` if
3+ // someone eats it all, so no ice cream is left (value 0). Return `None` if
44// `hour_of_day` is higher than 23.
5- fn maybe_icecream ( hour_of_day : u16 ) -> Option < u16 > {
5+ fn maybe_ice_cream ( hour_of_day : u16 ) -> Option < u16 > {
66 match hour_of_day {
77 0 ..=21 => Some ( 5 ) ,
88 22 ..=23 => Some ( 0 ) ,
@@ -21,19 +21,19 @@ mod tests {
2121 #[ test]
2222 fn raw_value ( ) {
2323 // Using `unwrap` is fine in a test.
24- let icecreams = maybe_icecream ( 12 ) . unwrap ( ) ;
24+ let ice_creams = maybe_ice_cream ( 12 ) . unwrap ( ) ;
2525
26- assert_eq ! ( icecreams , 5 ) ;
26+ assert_eq ! ( ice_creams , 5 ) ;
2727 }
2828
2929 #[ test]
30- fn check_icecream ( ) {
31- assert_eq ! ( maybe_icecream ( 0 ) , Some ( 5 ) ) ;
32- assert_eq ! ( maybe_icecream ( 9 ) , Some ( 5 ) ) ;
33- assert_eq ! ( maybe_icecream ( 18 ) , Some ( 5 ) ) ;
34- assert_eq ! ( maybe_icecream ( 22 ) , Some ( 0 ) ) ;
35- assert_eq ! ( maybe_icecream ( 23 ) , Some ( 0 ) ) ;
36- assert_eq ! ( maybe_icecream ( 24 ) , None ) ;
37- assert_eq ! ( maybe_icecream ( 25 ) , None ) ;
30+ fn check_ice_cream ( ) {
31+ assert_eq ! ( maybe_ice_cream ( 0 ) , Some ( 5 ) ) ;
32+ assert_eq ! ( maybe_ice_cream ( 9 ) , Some ( 5 ) ) ;
33+ assert_eq ! ( maybe_ice_cream ( 18 ) , Some ( 5 ) ) ;
34+ assert_eq ! ( maybe_ice_cream ( 22 ) , Some ( 0 ) ) ;
35+ assert_eq ! ( maybe_ice_cream ( 23 ) , Some ( 0 ) ) ;
36+ assert_eq ! ( maybe_ice_cream ( 24 ) , None ) ;
37+ assert_eq ! ( maybe_ice_cream ( 25 ) , None ) ;
3838 }
3939}
0 commit comments