check_specialization for all specialized methods
@@ -33,32 +33,43 @@ fn test_specializations<IterItem, Iter>(
IterItem: Eq + Debug + Clone,
Iter: Iterator<Item = IterItem> + Clone,
{
- let size = it.clone().count();
check_specialized(it, |i| i.count());
check_specialized(it, |i| i.last());
+ check_specialized(it, |i| i.collect::<Vec<_>>());
+ check_specialized(it, |i| {
+ let mut parameters_from_fold = vec![];
+ let fold_result = i.fold(vec![], |mut acc, v: IterItem| {
+ parameters_from_fold.push((acc.clone(), v.clone()));
+ acc.push(v);
+ acc
+ });
+ (parameters_from_fold, fold_result)
+ });
+ check_specialized(it, |mut i| {
+ let mut parameters_from_all = vec![];
+ let first = i.next();
+ let all_result = i.all(|x| {
+ parameters_from_all.push(x.clone());
+ Some(x)==first
+ });
+ (parameters_from_all, all_result)
+ });
+ let size = it.clone().count();
for n in 0..size + 2 {
check_specialized(it, |mut i| i.nth(n));
}
+ // size_hint is a bit harder to check
let mut it_sh = it.clone();
for n in 0..size + 2 {
let len = it_sh.clone().count();
let (min, max) = it_sh.size_hint();
- assert_eq!((size - n.min(size)), len);
+ assert_eq!(size - n.min(size), len);
assert!(min <= len);
if let Some(max) = max {
assert!(len <= max);
}
it_sh.next();
}
- check_specialized(it, |i| {
- let mut parameters_from_fold = vec![];
- let fold_result = i.fold(vec![], |mut acc, v: IterItem| {
- parameters_from_fold.push((acc.clone(), v.clone()));
- acc.push(v);
- acc
- });
- (parameters_from_fold, fold_result)
- });
}
fn put_back_test(test_vec: Vec<i32>) {
