Skip to content

Commit 81cd979

Browse files
authored
Merge pull request #1487 from lionel-rowe/patch-1
feat(options2): better test for layered_option
2 parents ccf4a78 + 8361342 commit 81cd979

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

exercises/options/options2.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@ mod tests {
1818

1919
#[test]
2020
fn layered_option() {
21-
let mut range = 10;
22-
let mut optional_integers: Vec<Option<i8>> = Vec::new();
23-
for i in 0..(range + 1) {
21+
let range = 10;
22+
let mut optional_integers: Vec<Option<i8>> = vec![None];
23+
24+
for i in 1..(range + 1) {
2425
optional_integers.push(Some(i));
2526
}
2627

28+
let mut cursor = range;
29+
2730
// TODO: make this a while let statement - remember that vector.pop also adds another layer of Option<T>
28-
// You can stack `Option<T>`'s into while let and if let
31+
// You can stack `Option<T>`s into while let and if let
2932
integer = optional_integers.pop() {
30-
assert_eq!(integer, range);
31-
range -= 1;
33+
assert_eq!(integer, cursor);
34+
cursor -= 1;
3235
}
36+
37+
assert_eq!(cursor, 0);
3338
}
3439
}

0 commit comments

Comments
 (0)