Created
June 23, 2014 20:56
-
-
Save eightbitraptor/2d33d1dd9a3c68478f94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn last_but_one(list: Vec<int>) -> Option<int> { | |
println!("{}", list.reverse()); | |
match list.is_empty() { | |
true => { None } | |
false => { list.reverse().get(1) } | |
}; | |
} | |
#[test] | |
fn test_last_but_one_with_empty_list() { | |
assert_eq!(last_but_one(Vec::<int>::new()), None) | |
} | |
#[test] | |
fn test_gets_penultimate_element() { | |
assert_eq!(last_but_one(vec!(1, 5, 6, 7, 2, 4)), Some(2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment