From 04845f0aebd6928bb924147fd93de8dac13ff850 Mon Sep 17 00:00:00 2001 From: blake2-ppc Date: Sun, 1 Sep 2013 16:43:47 +0200 Subject: std::iterator: Add back .rposition() test --- src/libstd/iterator.rs | 25 +++++++++++++++++++++++++ src/libstd/vec.rs | 10 ---------- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index d1b59c30978..77e51e01c0c 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -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: T, len: uint) { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 39560bd47e6..f8aaf653645 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -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)); -- cgit 1.4.1-3-g733a5