std::iterator: Add back .rposition() test

This commit is contained in:
blake2-ppc 2013-09-01 16:43:47 +02:00
parent 43ef5ad184
commit 04845f0aeb
2 changed files with 25 additions and 10 deletions

View file

@ -2367,6 +2367,31 @@ mod tests {
assert_eq!(it.next_back(), None)
}
#[test]
fn test_rposition() {
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert_eq!(v.iter().rposition(f), Some(3u));
assert!(v.iter().rposition(g).is_none());
}
#[test]
#[should_fail]
fn test_rposition_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do v.iter().rposition |_elt| {
if i == 2 {
fail!()
}
i += 1;
false
};
}
#[cfg(test)]
fn check_randacc_iter<A: Eq, T: Clone + RandomAccessIterator<A>>(a: T, len: uint)
{

View file

@ -2910,16 +2910,6 @@ mod tests {
assert!(v1.position_elem(&4).is_none());
}
#[test]
fn test_rposition() {
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
assert_eq!(v.iter().rposition(f), Some(3u));
assert!(v.iter().rposition(g).is_none());
}
#[test]
fn test_bsearch_elem() {
assert_eq!([1,2,3,4,5].bsearch_elem(&5), Some(4));