diff --git a/tests/quick.rs b/tests/quick.rs index 5829d1c1d..a37b71de7 100644 --- a/tests/quick.rs +++ b/tests/quick.rs @@ -258,12 +258,12 @@ where let mut it = get_it(); for _ in 0..(counts.len() - 1) { - if let None = it.next() { + if it.next().is_none() { panic!("Iterator shouldn't be finished, may not be deterministic"); } } - if let None = it.next() { + if it.next().is_none() { break 'outer; } @@ -438,7 +438,7 @@ quickcheck! { } assert_eq!(answer, actual); - assert_eq!(answer.into_iter().last(), a.clone().multi_cartesian_product().last()); + assert_eq!(answer.into_iter().last(), a.multi_cartesian_product().last()); } #[allow(deprecated)] @@ -498,9 +498,7 @@ quickcheck! { exact_size(it) } - fn equal_merge(a: Vec, b: Vec) -> bool { - let mut sa = a.clone(); - let mut sb = b.clone(); + fn equal_merge(mut sa: Vec, mut sb: Vec) -> bool { sa.sort(); sb.sort(); let mut merged = sa.clone(); @@ -517,7 +515,7 @@ quickcheck! { exact_size(multizip((a, b, c))) } fn size_zip_rc(a: Iter, b: Iter) -> bool { - let rc = rciter(a.clone()); + let rc = rciter(a); correct_size_hint(multizip((&rc, &rc, b))) } @@ -526,11 +524,8 @@ quickcheck! { correct_size_hint(izip!(filt, b.clone(), c.clone())) && exact_size(izip!(a, b, c)) } - fn equal_kmerge(a: Vec, b: Vec, c: Vec) -> bool { + fn equal_kmerge(mut sa: Vec, mut sb: Vec, mut sc: Vec) -> bool { use itertools::free::kmerge; - let mut sa = a.clone(); - let mut sb = b.clone(); - let mut sc = c.clone(); sa.sort(); sb.sort(); sc.sort(); @@ -610,7 +605,7 @@ quickcheck! { fn size_2_zip_longest(a: Iter, b: Iter) -> bool { let it = a.clone().zip_longest(b.clone()); let jt = a.clone().zip_longest(b.clone()); - itertools::equal(a.clone(), + itertools::equal(a, it.filter_map(|elt| match elt { EitherOrBoth::Both(x, _) => Some(x), EitherOrBoth::Left(x) => Some(x), @@ -618,7 +613,7 @@ quickcheck! { } )) && - itertools::equal(b.clone(), + itertools::equal(b, jt.filter_map(|elt| match elt { EitherOrBoth::Both(_, y) => Some(y), EitherOrBoth::Right(y) => Some(y), @@ -721,7 +716,7 @@ quickcheck! { assert_eq!(expected_first, curr_perm); - while let Some(next_perm) = perms.next() { + for next_perm in perms { assert!( next_perm > curr_perm, "next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}", @@ -943,8 +938,7 @@ quickcheck! { fn fuzz_group_by_lazy_1(it: Iter) -> bool { let jt = it.clone(); let groups = it.group_by(|k| *k); - let res = itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x)); - res + itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x)) } } @@ -1286,7 +1280,7 @@ quickcheck! { .map(|i| (i % modulo, i)) .into_group_map() .into_iter() - .map(|(key, vals)| (key, vals.into_iter().fold(0u64, |acc, val| acc + val))) + .map(|(key, vals)| (key, vals.into_iter().sum())) .collect::>(); assert_eq!(lookup, group_map_lookup); @@ -1304,7 +1298,7 @@ quickcheck! { acc + val }); - // TODO: Swap `fold1` with stdlib's `fold_first` when it's stabilized + #[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce` let group_map_lookup = a.iter() .map(|&b| b as u64) .map(|i| (i % modulo, i)) @@ -1551,11 +1545,10 @@ quickcheck! { } quickcheck! { - #[test] fn counts(nums: Vec) -> TestResult { let counts = nums.iter().counts(); for (&item, &count) in counts.iter() { - if count <= 0 { + if count == 0 { return TestResult::failed(); } if count != nums.iter().filter(|&x| x == item).count() { @@ -1602,7 +1595,7 @@ quickcheck! { fn is_fused(mut it: I) -> bool { - while let Some(_) = it.next() {} + for _ in it.by_ref() {} for _ in 0..10{ if it.next().is_some(){ return false; diff --git a/tests/specializations.rs b/tests/specializations.rs index 199cf562a..057e11c9f 100644 --- a/tests/specializations.rs +++ b/tests/specializations.rs @@ -129,7 +129,7 @@ quickcheck! { check_results_specialized!(it, |i| { let mut parameters_from_fold = vec![]; let fold_result = i.fold(vec![], |mut acc, v| { - parameters_from_fold.push((acc.clone(), v.clone())); + parameters_from_fold.push((acc.clone(), v)); acc.push(v); acc }); @@ -139,7 +139,7 @@ quickcheck! { let mut parameters_from_all = vec![]; let first = i.next(); let all_result = i.all(|x| { - parameters_from_all.push(x.clone()); + parameters_from_all.push(x); Some(x)==first }); (parameters_from_all, all_result) diff --git a/tests/test_core.rs b/tests/test_core.rs index a7b7449d3..38b6014e8 100644 --- a/tests/test_core.rs +++ b/tests/test_core.rs @@ -116,7 +116,7 @@ fn chain2() { fn write_to() { let xs = [7, 9, 8]; let mut ys = [0; 5]; - let cnt = ys.iter_mut().set_from(xs.iter().map(|x| *x)); + let cnt = ys.iter_mut().set_from(xs.iter().copied()); assert!(cnt == xs.len()); assert!(ys == [7, 9, 8, 0, 0]); @@ -183,10 +183,7 @@ fn batching() { let pit = xs.iter().cloned().batching(|it| { match it.next() { None => None, - Some(x) => match it.next() { - None => None, - Some(y) => Some((x, y)), - } + Some(x) => it.next().map(|y| (x, y)) } }); it::assert_equal(pit, ys.iter().cloned()); @@ -234,7 +231,7 @@ fn count_clones() { // Check that RepeatN only clones N - 1 times. use core::cell::Cell; - #[derive(PartialEq, Debug)] + #[derive(PartialEq, Eq, Debug)] struct Foo { n: Cell } diff --git a/tests/test_std.rs b/tests/test_std.rs index 4463d912f..f59034234 100644 --- a/tests/test_std.rs +++ b/tests/test_std.rs @@ -1,5 +1,3 @@ -use paste; -use permutohedron; use quickcheck as qc; use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng}; use rand::{seq::SliceRandom, thread_rng}; @@ -123,12 +121,12 @@ fn unique() { #[test] fn intersperse() { let xs = ["a", "", "b", "c"]; - let v: Vec<&str> = xs.iter().map(|x| x.clone()).intersperse(", ").collect(); + let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect(); let text: String = v.concat(); assert_eq!(text, "a, , b, c".to_string()); let ys = [0, 1, 2, 3]; - let mut it = ys[..0].iter().map(|x| *x).intersperse(1); + let mut it = ys[..0].iter().copied().intersperse(1); assert!(it.next() == None); } @@ -474,7 +472,7 @@ impl qc::Arbitrary for Ran // Check that taking the k smallest is the same as // sorting then taking the k first elements -fn k_smallest_sort(i: I, k: u16) -> () +fn k_smallest_sort(i: I, k: u16) where I: Iterator + Clone, I::Item: Ord + Debug, @@ -538,10 +536,10 @@ fn sorted_by_cached_key() { fn test_multipeek() { let nums = vec![1u8,2,3,4,5]; - let mp = multipeek(nums.iter().map(|&x| x)); + let mp = multipeek(nums.iter().copied()); assert_eq!(nums, mp.collect::>()); - let mut mp = multipeek(nums.iter().map(|&x| x)); + let mut mp = multipeek(nums.iter().copied()); assert_eq!(mp.peek(), Some(&1)); assert_eq!(mp.next(), Some(1)); assert_eq!(mp.peek(), Some(&2)); @@ -579,7 +577,7 @@ fn test_multipeek_peeking_next() { use crate::it::PeekingNext; let nums = vec![1u8,2,3,4,5,6,7]; - let mut mp = multipeek(nums.iter().map(|&x| x)); + let mut mp = multipeek(nums.iter().copied()); assert_eq!(mp.peeking_next(|&x| x != 0), Some(1)); assert_eq!(mp.next(), Some(2)); assert_eq!(mp.peek(), Some(&3)); @@ -604,10 +602,10 @@ fn test_multipeek_peeking_next() { fn test_peek_nth() { let nums = vec![1u8,2,3,4,5]; - let iter = peek_nth(nums.iter().map(|&x| x)); + let iter = peek_nth(nums.iter().copied()); assert_eq!(nums, iter.collect::>()); - let mut iter = peek_nth(nums.iter().map(|&x| x)); + let mut iter = peek_nth(nums.iter().copied()); assert_eq!(iter.peek_nth(0), Some(&1)); assert_eq!(iter.peek_nth(0), Some(&1)); @@ -638,7 +636,7 @@ fn test_peek_nth() { fn test_peek_nth_peeking_next() { use it::PeekingNext; let nums = vec![1u8,2,3,4,5,6,7]; - let mut iter = peek_nth(nums.iter().map(|&x| x)); + let mut iter = peek_nth(nums.iter().copied()); assert_eq!(iter.peeking_next(|&x| x != 0), Some(1)); assert_eq!(iter.next(), Some(2)); @@ -694,7 +692,7 @@ fn group_by() { } } - let toupper = |ch: &char| ch.to_uppercase().nth(0).unwrap(); + let toupper = |ch: &char| ch.to_uppercase().next().unwrap(); // try all possible orderings for indices in permutohedron::Heap::new(&mut [0, 1, 2, 3]) { @@ -1091,9 +1089,9 @@ fn format() { let t2 = format!("{:?}", data.iter().format("--")); assert_eq!(t2, ans2); - let dataf = [1.1, 2.71828, -22.]; + let dataf = [1.1, 5.71828, -22.]; let t3 = format!("{:.2e}", dataf.iter().format(", ")); - assert_eq!(t3, "1.10e0, 2.72e0, -2.20e1"); + assert_eq!(t3, "1.10e0, 5.72e0, -2.20e1"); } #[test] @@ -1110,7 +1108,7 @@ fn fold_while() { let vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let sum = vec.into_iter().fold_while(0, |acc, item| { iterations += 1; - let new_sum = acc.clone() + item; + let new_sum = acc + item; if new_sum <= 20 { FoldWhile::Continue(new_sum) } else { @@ -1143,7 +1141,7 @@ fn tree_fold1() { "0 1 x 2 3 x x 4 5 x 6 7 x x x 8 9 x 10 11 x x 12 13 x 14 15 x x x x", ]; for (i, &s) in x.iter().enumerate() { - let expected = if s == "" { None } else { Some(s.to_string()) }; + let expected = if s.is_empty() { None } else { Some(s.to_string()) }; let num_strings = (0..i).map(|x| x.to_string()); let actual = num_strings.tree_fold1(|a, b| format!("{} {} x", a, b)); assert_eq!(actual, expected);