Skip to content

Commit 04845f0

Browse files
author
blake2-ppc
committed
std::iterator: Add back .rposition() test
1 parent 43ef5ad commit 04845f0

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/libstd/iterator.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,31 @@ mod tests {
23672367
assert_eq!(it.next_back(), None)
23682368
}
23692369

2370+
#[test]
2371+
fn test_rposition() {
2372+
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
2373+
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
2374+
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
2375+
2376+
assert_eq!(v.iter().rposition(f), Some(3u));
2377+
assert!(v.iter().rposition(g).is_none());
2378+
}
2379+
2380+
#[test]
2381+
#[should_fail]
2382+
fn test_rposition_fail() {
2383+
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
2384+
let mut i = 0;
2385+
do v.iter().rposition |_elt| {
2386+
if i == 2 {
2387+
fail!()
2388+
}
2389+
i += 1;
2390+
false
2391+
};
2392+
}
2393+
2394+
23702395
#[cfg(test)]
23712396
fn check_randacc_iter<A: Eq, T: Clone + RandomAccessIterator<A>>(a: T, len: uint)
23722397
{

src/libstd/vec.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,16 +2910,6 @@ mod tests {
29102910
assert!(v1.position_elem(&4).is_none());
29112911
}
29122912

2913-
#[test]
2914-
fn test_rposition() {
2915-
fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' }
2916-
fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' }
2917-
let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')];
2918-
2919-
assert_eq!(v.iter().rposition(f), Some(3u));
2920-
assert!(v.iter().rposition(g).is_none());
2921-
}
2922-
29232913
#[test]
29242914
fn test_bsearch_elem() {
29252915
assert_eq!([1,2,3,4,5].bsearch_elem(&5), Some(4));

0 commit comments

Comments
 (0)