mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
finished option1 excercise
This commit is contained in:
parent
0971fb6dec
commit
b25970e131
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user