mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-12 13:49:19 +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 :(
|
// all, so there'll be no more left :(
|
||||||
// TODO: Return an Option!
|
// TODO: Return an Option!
|
||||||
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
|
fn maybe_icecream(time_of_day: u16) -> Option<u16> {
|
||||||
// We use the 24-hour system here, so 10PM is a value of 22
|
if time_of_day < 22 {
|
||||||
// The Option output should gracefully handle cases where time_of_day > 24.
|
Some(5)
|
||||||
???
|
} else if time_of_day >= 22 && time_of_day <= 24 {
|
||||||
|
Some(0)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -29,7 +33,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn raw_value() {
|
fn raw_value() {
|
||||||
// TODO: Fix this test. How do you get at the value contained in the Option?
|
// 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);
|
assert_eq!(icecreams, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user