library/core/test/iter add newlines between tests
This commit is contained in:
parent
3ce97000e1
commit
1e3a2def67
@ -23,6 +23,7 @@ fn test_iterator_chain() {
|
||||
}
|
||||
assert_eq!(i, expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_advance_by() {
|
||||
fn test_chain(xs: &[i32], ys: &[i32]) {
|
||||
@ -55,6 +56,7 @@ fn test_iterator_chain_advance_by() {
|
||||
test_chain(&[0, 1, 2, 3, 4, 5], &[]);
|
||||
test_chain(&[0, 1, 2, 3, 4, 5], &[30, 40, 50, 60]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_advance_back_by() {
|
||||
fn test_chain(xs: &[i32], ys: &[i32]) {
|
||||
@ -87,6 +89,7 @@ fn test_iterator_chain_advance_back_by() {
|
||||
test_chain(&[0, 1, 2, 3, 4, 5], &[]);
|
||||
test_chain(&[0, 1, 2, 3, 4, 5], &[30, 40, 50, 60]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_nth() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -102,6 +105,7 @@ fn test_iterator_chain_nth() {
|
||||
assert_eq!(it.nth(5), Some(&5));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_nth_back() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -117,6 +121,7 @@ fn test_iterator_chain_nth_back() {
|
||||
assert_eq!(it.nth_back(5), Some(&0));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_last() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -127,6 +132,7 @@ fn test_iterator_chain_last() {
|
||||
assert_eq!(ys.iter().chain(&zs).last(), Some(&60));
|
||||
assert_eq!(zs.iter().chain(&zs).last(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_count() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -135,6 +141,7 @@ fn test_iterator_chain_count() {
|
||||
assert_eq!(xs.iter().chain(&ys).count(), 10);
|
||||
assert_eq!(zs.iter().chain(&ys).count(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_find() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -147,6 +154,7 @@ fn test_iterator_chain_find() {
|
||||
assert_eq!(iter.find(|&&i| i == 100), None);
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_size_hint() {
|
||||
// this chains an iterator of length 0 with an iterator of length 1,
|
||||
@ -161,6 +169,7 @@ fn test_iterator_chain_size_hint() {
|
||||
assert_eq!(iter.next_back(), Some(()));
|
||||
assert_eq!(iter.size_hint(), (0, Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_chain_unfused() {
|
||||
// Chain shouldn't be fused in its second iterator, depending on direction
|
||||
@ -174,6 +183,7 @@ fn test_iterator_chain_unfused() {
|
||||
iter.next_back().unwrap();
|
||||
iter.next_back().unwrap_none();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chain_fold() {
|
||||
let xs = [1, 2, 3];
|
||||
@ -185,6 +195,7 @@ fn test_chain_fold() {
|
||||
iter.fold((), |(), &elt| result.push(elt));
|
||||
assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chain_try_folds() {
|
||||
let c = || (0..10).chain(10..20);
|
||||
|
@ -16,6 +16,7 @@ fn test_cloned() {
|
||||
assert_eq!(it.len(), 0);
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cloned_side_effects() {
|
||||
let mut count = 0;
|
||||
@ -32,6 +33,7 @@ fn test_cloned_side_effects() {
|
||||
}
|
||||
assert_eq!(count, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cloned_try_folds() {
|
||||
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
@ -8,6 +8,7 @@ fn test_iterator_enumerate() {
|
||||
assert_eq!(i, x);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_enumerate_nth() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -29,6 +30,7 @@ fn test_iterator_enumerate_nth() {
|
||||
assert_eq!(i, x);
|
||||
assert_eq!(i, 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_enumerate_nth_back() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -46,11 +48,13 @@ fn test_iterator_enumerate_nth_back() {
|
||||
assert_eq!(i, x);
|
||||
assert_eq!(i, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_enumerate_count() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
assert_eq!(xs.iter().enumerate().count(), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_enumerate_fold() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -74,6 +78,7 @@ fn test_iterator_enumerate_fold() {
|
||||
});
|
||||
assert_eq!(i, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enumerate_try_folds() {
|
||||
let f = &|acc, (i, x)| usize::checked_add(2 * acc, x / (i + 1) + i);
|
||||
|
@ -5,6 +5,7 @@ fn test_iterator_filter_count() {
|
||||
let xs = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
assert_eq!(xs.iter().filter(|&&x| x % 2 == 0).count(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_filter_fold() {
|
||||
let xs = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
@ -23,6 +24,7 @@ fn test_iterator_filter_fold() {
|
||||
});
|
||||
assert_eq!(i, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_try_folds() {
|
||||
fn p(&x: &i32) -> bool {
|
||||
|
@ -5,6 +5,7 @@ fn test_filter_map() {
|
||||
let it = (0..).step_by(1).take(10).filter_map(|x| if x % 2 == 0 { Some(x * x) } else { None });
|
||||
assert_eq!(it.collect::<Vec<usize>>(), [0 * 0, 2 * 2, 4 * 4, 6 * 6, 8 * 8]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_map_fold() {
|
||||
let xs = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
|
@ -12,6 +12,7 @@ fn test_iterator_flat_map() {
|
||||
}
|
||||
assert_eq!(i, ys.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_flat_map_fold() {
|
||||
let xs = [0, 3, 6];
|
||||
@ -34,6 +35,7 @@ fn test_iterator_flat_map_fold() {
|
||||
});
|
||||
assert_eq!(i, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flat_map_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(acc * 2 / 3, x);
|
||||
|
@ -13,6 +13,7 @@ fn test_iterator_flatten() {
|
||||
}
|
||||
assert_eq!(i, ys.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_flatten_fold() {
|
||||
let xs = [0, 3, 6];
|
||||
@ -35,6 +36,7 @@ fn test_iterator_flatten_fold() {
|
||||
});
|
||||
assert_eq!(i, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flatten_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(acc * 2 / 3, x);
|
||||
@ -52,6 +54,7 @@ fn test_flatten_try_folds() {
|
||||
assert_eq!(iter.try_rfold(0, i8::checked_add), None);
|
||||
assert_eq!(iter.next_back(), Some(35));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flatten_non_fused_outer() {
|
||||
let mut iter = NonFused::new(once(0..2)).flatten();
|
||||
@ -60,6 +63,7 @@ fn test_flatten_non_fused_outer() {
|
||||
assert_eq!(iter.next(), Some(0));
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flatten_non_fused_inner() {
|
||||
let mut iter = once(0..1).chain(once(1..3)).flat_map(NonFused::new);
|
||||
|
@ -11,6 +11,7 @@ fn test_fuse_nth() {
|
||||
assert_eq!(it.nth(2), None);
|
||||
assert_eq!(it.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fuse_last() {
|
||||
let xs = [0, 1, 2];
|
||||
@ -19,6 +20,7 @@ fn test_fuse_last() {
|
||||
assert_eq!(it.len(), 3);
|
||||
assert_eq!(it.last(), Some(&2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fuse_count() {
|
||||
let xs = [0, 1, 2];
|
||||
@ -28,6 +30,7 @@ fn test_fuse_count() {
|
||||
assert_eq!(it.count(), 3);
|
||||
// Can't check len now because count consumes.
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fuse_fold() {
|
||||
let xs = [0, 1, 2];
|
||||
|
@ -10,6 +10,7 @@ fn test_inspect() {
|
||||
assert_eq!(n, xs.len());
|
||||
assert_eq!(&xs[..], &ys[..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inspect_fold() {
|
||||
let xs = [1, 2, 3, 4];
|
||||
|
@ -17,6 +17,7 @@ fn test_intersperse() {
|
||||
let mut it = ys[..0].iter().map(|x| *x).intersperse(1);
|
||||
assert!(it.next() == None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_intersperse_size_hint() {
|
||||
let iter = std::iter::empty::<i32>().intersperse(0);
|
||||
@ -33,6 +34,7 @@ fn test_intersperse_size_hint() {
|
||||
|
||||
assert_eq!([].iter().intersperse(&()).size_hint(), (0, Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fold_specialization_intersperse() {
|
||||
let mut iter = (1..2).intersperse(0);
|
||||
@ -44,6 +46,7 @@ fn test_fold_specialization_intersperse() {
|
||||
let mut iter = (1..4).intersperse(0);
|
||||
iter.clone().for_each(|x| assert_eq!(Some(x), iter.next()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_fold_specialization_intersperse_ok() {
|
||||
let mut iter = (1..2).intersperse(0);
|
||||
@ -64,6 +67,7 @@ fn test_try_fold_specialization_intersperse_ok() {
|
||||
Some(())
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_intersperse_with() {
|
||||
#[derive(PartialEq, Debug)]
|
||||
@ -84,6 +88,7 @@ fn test_intersperse_with() {
|
||||
let r = (0..3).intersperse_with(separator).collect::<Vec<_>>();
|
||||
assert_eq!(r, vec![0, 200, 1, 400, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_intersperse_fold() {
|
||||
let v = (1..4).intersperse(9).fold(Vec::new(), |mut acc, x| {
|
||||
@ -112,6 +117,7 @@ fn test_intersperse_fold() {
|
||||
let v = NoneAtStart(0).intersperse(1000).fold(0, |a, b| a + b);
|
||||
assert_eq!(v, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_intersperse_collect_string() {
|
||||
let contents = vec![1, 2, 3];
|
||||
|
@ -22,6 +22,7 @@ fn test_find_map() {
|
||||
if x % 2 == 0 { Some(x / 2) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_map_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
@ -34,6 +35,7 @@ fn test_map_try_folds() {
|
||||
assert_eq!(iter.try_rfold(0, i8::checked_add), None);
|
||||
assert_eq!(iter.next_back(), Some(46));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_map_try_folds() {
|
||||
let mp = &|x| if 0 <= x && x < 10 { Some(x * 2) } else { None };
|
||||
|
@ -59,6 +59,7 @@ fn test_iterator_peekable() {
|
||||
assert!(it.next_back().is_none());
|
||||
assert_eq!(it.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_count() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -82,6 +83,7 @@ fn test_iterator_peekable_count() {
|
||||
let mut it = zs.iter().peekable();
|
||||
assert_eq!(it.peek(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_nth() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -95,6 +97,7 @@ fn test_iterator_peekable_nth() {
|
||||
assert_eq!(it.nth(2), Some(&5));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_last() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -113,6 +116,7 @@ fn test_iterator_peekable_last() {
|
||||
assert_eq!(it.peek(), None);
|
||||
assert_eq!(it.last(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_fold() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -124,6 +128,7 @@ fn test_iterator_peekable_fold() {
|
||||
});
|
||||
assert_eq!(i, xs.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_rfold() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
@ -135,6 +140,7 @@ fn test_iterator_peekable_rfold() {
|
||||
});
|
||||
assert_eq!(i, xs.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_next_if_eq() {
|
||||
// first, try on references
|
||||
@ -158,6 +164,7 @@ fn test_iterator_peekable_next_if_eq() {
|
||||
assert_eq!(it.next_if_eq("speed"), Some("speed".into()));
|
||||
assert_eq!(it.next_if_eq(""), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_mut() {
|
||||
let mut it = vec![1, 2, 3].into_iter().peekable();
|
||||
@ -168,6 +175,7 @@ fn test_iterator_peekable_mut() {
|
||||
}
|
||||
assert_eq!(it.collect::<Vec<_>>(), vec![5, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_remember_peek_none_1() {
|
||||
// Check that the loop using .peek() terminates
|
||||
@ -185,6 +193,7 @@ fn test_iterator_peekable_remember_peek_none_1() {
|
||||
}
|
||||
assert_eq!(n, data.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_remember_peek_none_2() {
|
||||
let data = [0];
|
||||
@ -193,6 +202,7 @@ fn test_iterator_peekable_remember_peek_none_2() {
|
||||
assert_eq!(iter.peek(), None);
|
||||
assert_eq!(iter.last(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_peekable_remember_peek_none_3() {
|
||||
let data = [0];
|
||||
@ -205,6 +215,7 @@ fn test_iterator_peekable_remember_peek_none_3() {
|
||||
assert_eq!(iter.peek(), None);
|
||||
assert_eq!(iter.nth(0), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_peek_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
@ -251,6 +262,7 @@ fn test_peek_try_folds() {
|
||||
assert_eq!(iter.peek(), None);
|
||||
assert_eq!(iter.try_rfold((), |(), x| Err(x)), Ok(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_peekable_non_fused() {
|
||||
let mut iter = NonFused::new(empty::<i32>()).peekable();
|
||||
|
@ -14,6 +14,7 @@ fn test_iterator_skip() {
|
||||
assert_eq!(i, ys.len());
|
||||
assert_eq!(it.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_doubleended() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
|
||||
@ -51,6 +52,7 @@ fn test_iterator_skip_doubleended() {
|
||||
let it = xs.iter().skip(5).rev();
|
||||
assert_eq!(it.last(), Some(&13));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_nth() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
|
||||
@ -66,6 +68,7 @@ fn test_iterator_skip_nth() {
|
||||
let mut it = xs.iter().skip(12);
|
||||
assert_eq!(it.nth(0), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_count() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
|
||||
@ -76,6 +79,7 @@ fn test_iterator_skip_count() {
|
||||
assert_eq!(xs.iter().skip(12).count(), 0);
|
||||
assert_eq!(xs.iter().skip(13).count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_last() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
|
||||
@ -90,6 +94,7 @@ fn test_iterator_skip_last() {
|
||||
assert_eq!(it.next(), Some(&13));
|
||||
assert_eq!(it.last(), Some(&30));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_fold() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19, 20, 30];
|
||||
@ -127,6 +132,7 @@ fn test_iterator_skip_fold() {
|
||||
});
|
||||
assert_eq!(i, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
@ -139,6 +145,7 @@ fn test_skip_try_folds() {
|
||||
assert_eq!(iter.try_rfold(0, i8::checked_add), None);
|
||||
assert_eq!(iter.next_back(), Some(24));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_nth_back() {
|
||||
let xs = [0, 1, 2, 3, 4, 5];
|
||||
|
@ -12,6 +12,7 @@ fn test_iterator_skip_while() {
|
||||
}
|
||||
assert_eq!(i, ys.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_skip_while_fold() {
|
||||
let xs = [0, 1, 2, 3, 5, 13, 15, 16, 17, 19];
|
||||
@ -31,6 +32,7 @@ fn test_iterator_skip_while_fold() {
|
||||
});
|
||||
assert_eq!(i, ys.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_while_try_fold() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
|
@ -23,6 +23,7 @@ fn test_steps_between() {
|
||||
None,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_step_forward() {
|
||||
assert_eq!(Step::forward_checked(55_u8, 200_usize), Some(255_u8));
|
||||
@ -59,6 +60,7 @@ fn test_step_forward() {
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_step_backward() {
|
||||
assert_eq!(Step::backward_checked(255_u8, 200_usize), Some(55_u8));
|
||||
|
@ -29,6 +29,7 @@ fn test_iterator_step_by() {
|
||||
assert_eq!(it.next_back(), Some(0));
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_nth() {
|
||||
let mut it = (0..16).step_by(5);
|
||||
@ -46,6 +47,7 @@ fn test_iterator_step_by_nth() {
|
||||
assert_eq!(it.clone().nth(4), None);
|
||||
assert_eq!(it.clone().nth(42), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_nth_overflow() {
|
||||
#[cfg(target_pointer_width = "8")]
|
||||
@ -91,6 +93,7 @@ fn test_iterator_step_by_nth_overflow() {
|
||||
(&mut it).step_by(1).nth(usize::MAX);
|
||||
assert_eq!(it.0, (usize::MAX as Bigger) * 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_nth_try_fold() {
|
||||
let mut it = (0..).step_by(10);
|
||||
@ -107,6 +110,7 @@ fn test_iterator_step_by_nth_try_fold() {
|
||||
assert_eq!(it.next(), Some(100));
|
||||
assert_eq!(it.try_fold(0, i8::checked_add), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_nth_back() {
|
||||
let mut it = (0..16).step_by(5);
|
||||
@ -131,6 +135,7 @@ fn test_iterator_step_by_nth_back() {
|
||||
assert_eq!(it().nth_back(4), None);
|
||||
assert_eq!(it().nth_back(42), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_nth_try_rfold() {
|
||||
let mut it = (0..100).step_by(10);
|
||||
@ -148,12 +153,14 @@ fn test_iterator_step_by_nth_try_rfold() {
|
||||
assert_eq!(it.next_back(), Some(100));
|
||||
assert_eq!(it.try_fold(0, i8::checked_add), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_iterator_step_by_zero() {
|
||||
let mut it = (0..).step_by(0);
|
||||
it.next();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_step_by_size_hint() {
|
||||
struct StubSizeHint(usize, Option<usize>);
|
||||
@ -232,6 +239,7 @@ fn test_iterator_step_by_size_hint() {
|
||||
assert!(TrustedLenCheck::test(a.iter()));
|
||||
assert!(!TrustedLenCheck::test(a.iter().step_by(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_step_by_skip() {
|
||||
assert_eq!((0..640).step_by(128).skip(1).collect::<Vec<_>>(), [128, 256, 384, 512]);
|
||||
|
@ -27,6 +27,7 @@ fn test_iterator_take() {
|
||||
assert_eq!(i, ys.len());
|
||||
assert_eq!(it.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_take_nth() {
|
||||
let xs = [0, 1, 2, 4, 5];
|
||||
@ -50,6 +51,7 @@ fn test_iterator_take_nth() {
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_take_nth_back() {
|
||||
let xs = [0, 1, 2, 4, 5];
|
||||
@ -70,6 +72,7 @@ fn test_iterator_take_nth_back() {
|
||||
assert_eq!(it.nth_back(1), Some(&1));
|
||||
assert_eq!(it.nth_back(1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_take_short() {
|
||||
let xs = [0, 1, 2, 3];
|
||||
@ -96,6 +99,7 @@ fn test_iterator_take_short() {
|
||||
assert_eq!(i, xs.len());
|
||||
assert_eq!(it.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_take_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
|
@ -12,6 +12,7 @@ fn test_iterator_take_while() {
|
||||
}
|
||||
assert_eq!(i, ys.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_take_while_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
|
@ -17,6 +17,7 @@ fn test_zip_nth() {
|
||||
let mut it = ys.iter().zip(&xs);
|
||||
assert_eq!(it.nth(3), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_nth_side_effects() {
|
||||
let mut a = Vec::new();
|
||||
@ -38,6 +39,7 @@ fn test_zip_nth_side_effects() {
|
||||
assert_eq!(a, vec![1, 2, 3, 4, 5]);
|
||||
assert_eq!(b, vec![200, 300, 400, 500, 600]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_next_back_side_effects() {
|
||||
let mut a = Vec::new();
|
||||
@ -63,6 +65,7 @@ fn test_zip_next_back_side_effects() {
|
||||
assert_eq!(a, vec![6, 5, 4, 3]);
|
||||
assert_eq!(b, vec![800, 700, 600, 500, 400]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_nth_back_side_effects() {
|
||||
let mut a = Vec::new();
|
||||
@ -83,6 +86,7 @@ fn test_zip_nth_back_side_effects() {
|
||||
assert_eq!(a, vec![6, 5, 4, 3]);
|
||||
assert_eq!(b, vec![800, 700, 600, 500, 400]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_next_back_side_effects_exhausted() {
|
||||
let mut a = Vec::new();
|
||||
@ -107,6 +111,7 @@ fn test_zip_next_back_side_effects_exhausted() {
|
||||
assert_eq!(a, vec![1, 2, 3, 4, 6, 5]);
|
||||
assert_eq!(b, vec![200, 300, 400]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_cloned_sideffectful() {
|
||||
let xs = [CountClone::new(), CountClone::new(), CountClone::new(), CountClone::new()];
|
||||
@ -125,6 +130,7 @@ fn test_zip_cloned_sideffectful() {
|
||||
assert_eq!(&xs, &[1, 1][..]);
|
||||
assert_eq!(&ys, &[1, 1, 0, 0][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_map_sideffectful() {
|
||||
let mut xs = [0; 6];
|
||||
@ -143,6 +149,7 @@ fn test_zip_map_sideffectful() {
|
||||
assert_eq!(&xs, &[1, 1, 1, 1]);
|
||||
assert_eq!(&ys, &[1, 1, 1, 1, 0, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_map_rev_sideffectful() {
|
||||
let mut xs = [0; 6];
|
||||
@ -166,6 +173,7 @@ fn test_zip_map_rev_sideffectful() {
|
||||
assert_eq!(&xs, &[1, 1, 1, 1, 1, 1]);
|
||||
assert_eq!(&ys, &[1, 1, 1, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_nested_sideffectful() {
|
||||
let mut xs = [0; 6];
|
||||
@ -178,6 +186,7 @@ fn test_zip_nested_sideffectful() {
|
||||
}
|
||||
assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_nth_back_side_effects_exhausted() {
|
||||
let mut a = Vec::new();
|
||||
@ -202,6 +211,7 @@ fn test_zip_nth_back_side_effects_exhausted() {
|
||||
assert_eq!(a, vec![1, 2, 3, 4, 6, 5]);
|
||||
assert_eq!(b, vec![200, 300, 400]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zip_trusted_random_access_composition() {
|
||||
let a = [0, 1, 2, 3, 4];
|
||||
|
@ -6,6 +6,9 @@ mod traits;
|
||||
use core::cell::Cell;
|
||||
use core::convert::TryFrom;
|
||||
use core::iter::*;
|
||||
|
||||
pub fn is_trusted_len<I: TrustedLen>(_: I) {}
|
||||
|
||||
#[test]
|
||||
fn test_multi_iter() {
|
||||
let xs = [1, 2, 3, 4];
|
||||
@ -13,6 +16,7 @@ fn test_multi_iter() {
|
||||
assert!(xs.iter().eq(ys.iter().rev()));
|
||||
assert!(xs.iter().lt(xs.iter().skip(2)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_counter_from_iter() {
|
||||
let it = (0..).step_by(5).take(10);
|
||||
@ -20,7 +24,6 @@ fn test_counter_from_iter() {
|
||||
assert_eq!(xs, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
|
||||
}
|
||||
|
||||
pub fn is_trusted_len<I: TrustedLen>(_: I) {}
|
||||
#[test]
|
||||
fn test_functor_laws() {
|
||||
// identity:
|
||||
@ -41,6 +44,7 @@ fn test_functor_laws() {
|
||||
}
|
||||
assert_eq!((0..10).map(f).map(g).sum::<usize>(), (0..10).map(h).sum());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monad_laws_left_identity() {
|
||||
fn f(x: usize) -> impl Iterator<Item = usize> {
|
||||
@ -48,10 +52,12 @@ fn test_monad_laws_left_identity() {
|
||||
}
|
||||
assert_eq!(once(42).flat_map(f.clone()).sum::<usize>(), f(42).sum());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monad_laws_right_identity() {
|
||||
assert_eq!((0..10).flat_map(|x| once(x)).sum::<usize>(), (0..10).sum());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_monad_laws_associativity() {
|
||||
fn f(x: usize) -> impl Iterator<Item = usize> {
|
||||
@ -77,6 +83,7 @@ pub fn extend_for_unit() {
|
||||
}
|
||||
assert_eq!(x, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_fold_specialization_intersperse_err() {
|
||||
let orig_iter = ["a", "b"].iter().copied().intersperse("-");
|
||||
|
@ -23,6 +23,7 @@ fn test_range() {
|
||||
(isize::MAX as usize + 2, Some(isize::MAX as usize + 2))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_range() {
|
||||
use std::char;
|
||||
@ -37,6 +38,7 @@ fn test_char_range() {
|
||||
assert_eq!(('\u{D7FF}'..'\u{E000}').count(), 1);
|
||||
assert_eq!(('\u{D7FF}'..'\u{E000}').size_hint(), (1, Some(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_exhaustion() {
|
||||
let mut r = 10..10;
|
||||
@ -65,6 +67,7 @@ fn test_range_exhaustion() {
|
||||
assert_eq!(r.next_back(), None);
|
||||
assert_eq!(r, 100..10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_exhaustion() {
|
||||
let mut r = 10..=10;
|
||||
@ -124,6 +127,7 @@ fn test_range_inclusive_exhaustion() {
|
||||
assert_eq!(r.next_back(), None);
|
||||
assert_eq!(r, 100..=10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_nth() {
|
||||
assert_eq!((10..15).nth(0), Some(10));
|
||||
@ -139,6 +143,7 @@ fn test_range_nth() {
|
||||
assert_eq!(r.nth(10), None);
|
||||
assert_eq!(r, 20..20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_nth_back() {
|
||||
assert_eq!((10..15).nth_back(0), Some(14));
|
||||
@ -155,6 +160,7 @@ fn test_range_nth_back() {
|
||||
assert_eq!(r.nth_back(10), None);
|
||||
assert_eq!(r, 10..10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_from_nth() {
|
||||
assert_eq!((10..).nth(0), Some(10));
|
||||
@ -171,6 +177,7 @@ fn test_range_from_nth() {
|
||||
|
||||
assert_eq!((0..).size_hint(), (usize::MAX, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_from_take() {
|
||||
let mut it = (0..).take(3);
|
||||
@ -183,11 +190,13 @@ fn test_range_from_take() {
|
||||
assert_eq!((0..).take(0).size_hint(), (0, Some(0)));
|
||||
assert_eq!((0..).take(usize::MAX).size_hint(), (usize::MAX, Some(usize::MAX)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_from_take_collect() {
|
||||
let v: Vec<_> = (0..).take(3).collect();
|
||||
assert_eq!(v, vec![0, 1, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_nth() {
|
||||
assert_eq!((10..=15).nth(0), Some(10));
|
||||
@ -210,6 +219,7 @@ fn test_range_inclusive_nth() {
|
||||
assert_eq!(r, exhausted_via_next);
|
||||
assert_eq!(ExactSizeIterator::is_empty(&r), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_nth_back() {
|
||||
assert_eq!((10..=15).nth_back(0), Some(15));
|
||||
@ -233,6 +243,7 @@ fn test_range_inclusive_nth_back() {
|
||||
assert_eq!(r, exhausted_via_next_back);
|
||||
assert_eq!(ExactSizeIterator::is_empty(&r), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_len() {
|
||||
assert_eq!((0..10_u8).len(), 10);
|
||||
@ -241,6 +252,7 @@ fn test_range_len() {
|
||||
assert_eq!((11..10_u8).len(), 0);
|
||||
assert_eq!((100..10_u8).len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_len() {
|
||||
assert_eq!((0..=10_u8).len(), 11);
|
||||
@ -249,6 +261,7 @@ fn test_range_inclusive_len() {
|
||||
assert_eq!((11..=10_u8).len(), 0);
|
||||
assert_eq!((100..=10_u8).len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_step() {
|
||||
#![allow(deprecated)]
|
||||
@ -271,6 +284,7 @@ fn test_range_step() {
|
||||
assert_eq!((i16::MIN..i16::MAX).step_by(i16::MAX as usize).size_hint(), (3, Some(3)));
|
||||
assert_eq!((isize::MIN..isize::MAX).step_by(1).size_hint(), (usize::MAX, Some(usize::MAX)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_step() {
|
||||
assert_eq!((0..=50).step_by(10).collect::<Vec<_>>(), [0, 10, 20, 30, 40, 50]);
|
||||
@ -278,6 +292,7 @@ fn test_range_inclusive_step() {
|
||||
assert_eq!((200..=255u8).step_by(10).collect::<Vec<_>>(), [200, 210, 220, 230, 240, 250]);
|
||||
assert_eq!((250..=255u8).step_by(1).collect::<Vec<_>>(), [250, 251, 252, 253, 254, 255]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_last_max() {
|
||||
assert_eq!((0..20).last(), Some(19));
|
||||
@ -288,6 +303,7 @@ fn test_range_last_max() {
|
||||
assert_eq!((-20..0).max(), Some(-1));
|
||||
assert_eq!((5..5).max(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_last_max() {
|
||||
assert_eq!((0..=20).last(), Some(20));
|
||||
@ -304,12 +320,14 @@ fn test_range_inclusive_last_max() {
|
||||
r.next();
|
||||
assert_eq!(r.max(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_min() {
|
||||
assert_eq!((0..20).min(), Some(0));
|
||||
assert_eq!((-20..0).min(), Some(-20));
|
||||
assert_eq!((5..5).min(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_min() {
|
||||
assert_eq!((0..=20).min(), Some(0));
|
||||
@ -319,6 +337,7 @@ fn test_range_inclusive_min() {
|
||||
r.next();
|
||||
assert_eq!(r.min(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_folds() {
|
||||
assert_eq!((1..=10).sum::<i32>(), 55);
|
||||
@ -356,6 +375,7 @@ fn test_range_inclusive_folds() {
|
||||
assert_eq!(it.try_rfold(0, |a, b| Some(a + b)), Some(0));
|
||||
assert!(it.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_size_hint() {
|
||||
assert_eq!((0..0usize).size_hint(), (0, Some(0)));
|
||||
@ -379,6 +399,7 @@ fn test_range_size_hint() {
|
||||
assert_eq!((imin..imax).size_hint(), (usize::MAX, Some(usize::MAX)));
|
||||
assert_eq!((imin..imax + 1).size_hint(), (usize::MAX, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_inclusive_size_hint() {
|
||||
assert_eq!((1..=0usize).size_hint(), (0, Some(0)));
|
||||
|
@ -9,6 +9,7 @@ fn test_repeat() {
|
||||
assert_eq!(it.next(), Some(42));
|
||||
assert_eq!(repeat(42).size_hint(), (usize::MAX, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_take() {
|
||||
let mut it = repeat(42).take(3);
|
||||
@ -21,11 +22,13 @@ fn test_repeat_take() {
|
||||
assert_eq!(repeat(42).take(0).size_hint(), (0, Some(0)));
|
||||
assert_eq!(repeat(42).take(usize::MAX).size_hint(), (usize::MAX, Some(usize::MAX)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_take_collect() {
|
||||
let v: Vec<_> = repeat(42).take(3).collect();
|
||||
assert_eq!(v, vec![42, 42, 42]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_with() {
|
||||
#[derive(PartialEq, Debug)]
|
||||
@ -36,6 +39,7 @@ fn test_repeat_with() {
|
||||
assert_eq!(it.next(), Some(NotClone(42)));
|
||||
assert_eq!(repeat_with(|| NotClone(42)).size_hint(), (usize::MAX, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_with_take() {
|
||||
let mut it = repeat_with(|| 42).take(3);
|
||||
@ -48,6 +52,7 @@ fn test_repeat_with_take() {
|
||||
assert_eq!(repeat_with(|| 42).take(0).size_hint(), (0, Some(0)));
|
||||
assert_eq!(repeat_with(|| 42).take(usize::MAX).size_hint(), (usize::MAX, Some(usize::MAX)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_repeat_with_take_collect() {
|
||||
let mut curr = 1;
|
||||
@ -60,6 +65,7 @@ fn test_repeat_with_take_collect() {
|
||||
.collect();
|
||||
assert_eq!(v, vec![1, 2, 4, 8, 16]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_successors() {
|
||||
let mut powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10));
|
||||
@ -70,12 +76,14 @@ fn test_successors() {
|
||||
assert_eq!(empty.next(), None);
|
||||
assert_eq!(empty.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_once() {
|
||||
let mut it = once(42);
|
||||
assert_eq!(it.next(), Some(42));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_once_with() {
|
||||
let count = Cell::new(0);
|
||||
@ -92,6 +100,7 @@ fn test_once_with() {
|
||||
assert_eq!(it.next(), None);
|
||||
assert_eq!(count.get(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let mut it = empty::<i32>();
|
||||
|
@ -7,6 +7,7 @@ fn test_iterator_sum() {
|
||||
assert_eq!(v.iter().cloned().sum::<i32>(), 55);
|
||||
assert_eq!(v[..0].iter().cloned().sum::<i32>(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_sum_result() {
|
||||
let v: &[Result<i32, ()>] = &[Ok(1), Ok(2), Ok(3), Ok(4)];
|
||||
@ -31,6 +32,7 @@ fn test_iterator_sum_result() {
|
||||
let v: &[Result<i32, ()>] = &[Ok(1), Err(()), Ok(3), Ok(4)];
|
||||
assert_eq!(v.iter().cloned().sum::<S>(), S(Err(())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_sum_option() {
|
||||
let v: &[Option<i32>] = &[Some(1), Some(2), Some(3), Some(4)];
|
||||
@ -38,6 +40,7 @@ fn test_iterator_sum_option() {
|
||||
let v: &[Option<i32>] = &[Some(1), None, Some(3), Some(4)];
|
||||
assert_eq!(v.iter().cloned().sum::<Option<i32>>(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_product() {
|
||||
let v: &[i32] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
@ -45,6 +48,7 @@ fn test_iterator_product() {
|
||||
assert_eq!(v[1..5].iter().cloned().product::<i32>(), 24);
|
||||
assert_eq!(v[..0].iter().cloned().product::<i32>(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_product_result() {
|
||||
let v: &[Result<i32, ()>] = &[Ok(1), Ok(2), Ok(3), Ok(4)];
|
||||
@ -52,6 +56,7 @@ fn test_iterator_product_result() {
|
||||
let v: &[Result<i32, ()>] = &[Ok(1), Err(()), Ok(3), Ok(4)];
|
||||
assert_eq!(v.iter().cloned().product::<Result<i32, _>>(), Err(()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_product_option() {
|
||||
let v: &[Option<i32>] = &[Some(1), Some(2), Some(3), Some(4)];
|
||||
|
@ -6,6 +6,7 @@ fn test_iterator_rev_nth_back() {
|
||||
}
|
||||
assert_eq!(v.iter().rev().nth_back(v.len()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_rev_nth() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -14,6 +15,7 @@ fn test_iterator_rev_nth() {
|
||||
}
|
||||
assert_eq!(v.iter().rev().nth(v.len()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_len() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
@ -21,6 +23,7 @@ fn test_iterator_len() {
|
||||
assert_eq!(v[..10].iter().count(), 10);
|
||||
assert_eq!(v[..0].iter().count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rev() {
|
||||
let xs = [2, 4, 6, 8, 10, 12, 14, 16];
|
||||
@ -29,6 +32,7 @@ fn test_rev() {
|
||||
it.next();
|
||||
assert!(it.rev().cloned().collect::<Vec<isize>>() == vec![16, 14, 12, 10, 8, 6]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_map() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
@ -41,6 +45,7 @@ fn test_double_ended_map() {
|
||||
assert_eq!(it.next_back(), Some(-4));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_enumerate() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
@ -53,6 +58,7 @@ fn test_double_ended_enumerate() {
|
||||
assert_eq!(it.next_back(), Some((2, 3)));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_zip() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
@ -66,6 +72,7 @@ fn test_double_ended_zip() {
|
||||
assert_eq!(it.next_back(), Some((3, 3)));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_filter() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
@ -75,6 +82,7 @@ fn test_double_ended_filter() {
|
||||
assert_eq!(it.next().unwrap(), &2);
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_filter_map() {
|
||||
let xs = [1, 2, 3, 4, 5, 6];
|
||||
@ -84,6 +92,7 @@ fn test_double_ended_filter_map() {
|
||||
assert_eq!(it.next().unwrap(), 4);
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_chain() {
|
||||
let xs = [1, 2, 3, 4, 5];
|
||||
@ -127,6 +136,7 @@ fn test_double_ended_chain() {
|
||||
assert_eq!(CrazyIterator::new().chain(0..10).rev().last(), Some(0));
|
||||
assert!((0..10).chain(CrazyIterator::new()).rev().any(|i| i == 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_flat_map() {
|
||||
let u = [0, 1];
|
||||
@ -143,6 +153,7 @@ fn test_double_ended_flat_map() {
|
||||
assert_eq!(it.next(), None);
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_flatten() {
|
||||
let u = [0, 1];
|
||||
@ -159,6 +170,7 @@ fn test_double_ended_flatten() {
|
||||
assert_eq!(it.next(), None);
|
||||
assert_eq!(it.next_back(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double_ended_range() {
|
||||
assert_eq!((11..14).rev().collect::<Vec<_>>(), [13, 12, 11]);
|
||||
@ -171,6 +183,7 @@ fn test_double_ended_range() {
|
||||
panic!("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rev_try_folds() {
|
||||
let f = &|acc, x| i32::checked_add(2 * acc, x);
|
||||
|
@ -68,6 +68,7 @@ fn test_lt() {
|
||||
assert!(c.iter().gt(b.iter()) == (c[0] > b[0]));
|
||||
assert!(c.iter().ge(b.iter()) == (c[0] >= b[0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cmp_by() {
|
||||
use core::cmp::Ordering;
|
||||
@ -83,6 +84,7 @@ fn test_cmp_by() {
|
||||
assert_eq!(xs().cmp_by(ys().rev(), f), Ordering::Less);
|
||||
assert_eq!(xs().cmp_by(ys().take(2), f), Ordering::Greater);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partial_cmp_by() {
|
||||
use core::cmp::Ordering;
|
||||
@ -105,6 +107,7 @@ fn test_partial_cmp_by() {
|
||||
assert_eq!(xs().partial_cmp_by(ys(), f), None);
|
||||
assert_eq!(ys().partial_cmp_by(xs(), f), Some(Ordering::Greater));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eq_by() {
|
||||
let f = |x: i32, y: i32| x * x == y;
|
||||
@ -120,6 +123,7 @@ fn test_eq_by() {
|
||||
assert!(!xs().eq_by(ys().take(3), f));
|
||||
assert!(xs().take(3).eq_by(ys().take(3), f));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_nth() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -128,6 +132,7 @@ fn test_iterator_nth() {
|
||||
}
|
||||
assert_eq!(v.iter().nth(v.len()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_nth_back() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -136,6 +141,7 @@ fn test_iterator_nth_back() {
|
||||
}
|
||||
assert_eq!(v.iter().nth_back(v.len()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_advance_by() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -150,6 +156,7 @@ fn test_iterator_advance_by() {
|
||||
assert_eq!(v.iter().advance_by(v.len()), Ok(()));
|
||||
assert_eq!(v.iter().advance_by(100), Err(v.len()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_advance_back_by() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -164,6 +171,7 @@ fn test_iterator_advance_back_by() {
|
||||
assert_eq!(v.iter().advance_back_by(v.len()), Ok(()));
|
||||
assert_eq!(v.iter().advance_back_by(100), Err(v.len()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_rev_advance_back_by() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
@ -178,12 +186,14 @@ fn test_iterator_rev_advance_back_by() {
|
||||
assert_eq!(v.iter().rev().advance_back_by(v.len()), Ok(()));
|
||||
assert_eq!(v.iter().rev().advance_back_by(100), Err(v.len()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_last() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
assert_eq!(v.iter().last().unwrap(), &4);
|
||||
assert_eq!(v[..1].iter().last().unwrap(), &0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_max() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
@ -192,6 +202,7 @@ fn test_iterator_max() {
|
||||
assert_eq!(v[..0].iter().cloned().max(), None);
|
||||
assert_eq!(v.iter().cloned().map(Mod3).max().map(|x| x.0), Some(8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_min() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
@ -200,6 +211,7 @@ fn test_iterator_min() {
|
||||
assert_eq!(v[..0].iter().cloned().min(), None);
|
||||
assert_eq!(v.iter().cloned().map(Mod3).min().map(|x| x.0), Some(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_size_hint() {
|
||||
let c = (0..).step_by(1);
|
||||
@ -239,6 +251,7 @@ fn test_iterator_size_hint() {
|
||||
assert_eq!(vi.clone().map(|&i| i + 1).size_hint(), (10, Some(10)));
|
||||
assert_eq!(vi.filter_map(|_| Some(0)).size_hint(), (0, Some(10)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_all() {
|
||||
let v: Box<[isize]> = Box::new([1, 2, 3, 4, 5]);
|
||||
@ -247,6 +260,7 @@ fn test_all() {
|
||||
assert!(!v.iter().all(|&x| x > 100));
|
||||
assert!(v[..0].iter().all(|_| panic!()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_any() {
|
||||
let v: Box<[isize]> = Box::new([1, 2, 3, 4, 5]);
|
||||
@ -255,6 +269,7 @@ fn test_any() {
|
||||
assert!(!v.iter().any(|&x| x > 100));
|
||||
assert!(!v[..0].iter().any(|_| panic!()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find() {
|
||||
let v: &[isize] = &[1, 3, 9, 27, 103, 14, 11];
|
||||
@ -262,6 +277,7 @@ fn test_find() {
|
||||
assert_eq!(*v.iter().find(|&&x| x % 3 == 0).unwrap(), 3);
|
||||
assert!(v.iter().find(|&&x| x % 12 == 0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_find() {
|
||||
let xs: &[isize] = &[];
|
||||
@ -287,6 +303,7 @@ fn test_try_find() {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_try_find_api_usability() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let a = ["1", "2"];
|
||||
@ -300,6 +317,7 @@ fn test_try_find_api_usability() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_position() {
|
||||
let v = &[1, 3, 9, 27, 103, 14, 11];
|
||||
@ -307,6 +325,7 @@ fn test_position() {
|
||||
assert_eq!(v.iter().position(|x| *x % 3 == 0).unwrap(), 1);
|
||||
assert!(v.iter().position(|x| *x % 12 == 0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count() {
|
||||
let xs = &[1, 2, 2, 1, 5, 9, 0, 2];
|
||||
@ -314,26 +333,31 @@ fn test_count() {
|
||||
assert_eq!(xs.iter().filter(|x| **x == 5).count(), 1);
|
||||
assert_eq!(xs.iter().filter(|x| **x == 95).count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_by_key() {
|
||||
let xs: &[isize] = &[-3, 0, 1, 5, -10];
|
||||
assert_eq!(*xs.iter().max_by_key(|x| x.abs()).unwrap(), -10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_max_by() {
|
||||
let xs: &[isize] = &[-3, 0, 1, 5, -10];
|
||||
assert_eq!(*xs.iter().max_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), -10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_by_key() {
|
||||
let xs: &[isize] = &[-3, 0, 1, 5, -10];
|
||||
assert_eq!(*xs.iter().min_by_key(|x| x.abs()).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_by() {
|
||||
let xs: &[isize] = &[-3, 0, 1, 5, -10];
|
||||
assert_eq!(*xs.iter().min_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_by_ref() {
|
||||
let mut xs = 0..10;
|
||||
@ -342,6 +366,7 @@ fn test_by_ref() {
|
||||
assert_eq!(partial_sum, 10);
|
||||
assert_eq!(xs.next(), Some(5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_sorted() {
|
||||
assert!([1, 2, 2, 9].iter().is_sorted());
|
||||
@ -354,6 +379,7 @@ fn test_is_sorted() {
|
||||
assert!(!["c", "bb", "aaa"].iter().is_sorted());
|
||||
assert!(["c", "bb", "aaa"].iter().is_sorted_by_key(|s| s.len()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_partition() {
|
||||
fn check(xs: &mut [i32], ref p: impl Fn(&i32) -> bool, expected: usize) {
|
||||
@ -389,6 +415,7 @@ fn test_partition() {
|
||||
check(xs, |&x| x < 3, 3); // small
|
||||
check(xs, |&x| x > 6, 3); // large
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iterator_rev_advance_by() {
|
||||
let v: &[_] = &[0, 1, 2, 3, 4];
|
||||
|
@ -19,11 +19,13 @@ fn test_rposition() {
|
||||
assert_eq!(v.iter().rposition(f), Some(3));
|
||||
assert!(v.iter().rposition(g).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rev_rposition() {
|
||||
let v = [0, 0, 1, 1];
|
||||
assert_eq!(v.iter().rev().rposition(|&x| x == 1), Some(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_rposition_panic() {
|
||||
|
Loading…
Reference in New Issue
Block a user