Skip to content

Commit

Permalink
apply clippy lints to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hellow554 committed Jun 2, 2022
1 parent 06d62d7 commit 2279f16
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
35 changes: 14 additions & 21 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -498,9 +498,7 @@ quickcheck! {
exact_size(it)
}

fn equal_merge(a: Vec<i16>, b: Vec<i16>) -> bool {
let mut sa = a.clone();
let mut sb = b.clone();
fn equal_merge(mut sa: Vec<i16>, mut sb: Vec<i16>) -> bool {
sa.sort();
sb.sort();
let mut merged = sa.clone();
Expand All @@ -517,7 +515,7 @@ quickcheck! {
exact_size(multizip((a, b, c)))
}
fn size_zip_rc(a: Iter<i16>, b: Iter<i16>) -> bool {
let rc = rciter(a.clone());
let rc = rciter(a);
correct_size_hint(multizip((&rc, &rc, b)))
}

Expand All @@ -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<i16>, b: Vec<i16>, c: Vec<i16>) -> bool {
fn equal_kmerge(mut sa: Vec<i16>, mut sb: Vec<i16>, mut sc: Vec<i16>) -> 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();
Expand Down Expand Up @@ -610,15 +605,15 @@ quickcheck! {
fn size_2_zip_longest(a: Iter<i16>, b: Iter<i16>) -> 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),
_ => None,
}
))
&&
itertools::equal(b.clone(),
itertools::equal(b,
jt.filter_map(|elt| match elt {
EitherOrBoth::Both(_, y) => Some(y),
EitherOrBoth::Right(y) => Some(y),
Expand Down Expand Up @@ -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={}",
Expand Down Expand Up @@ -943,8 +938,7 @@ quickcheck! {
fn fuzz_group_by_lazy_1(it: Iter<u8>) -> 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))
}
}

Expand Down Expand Up @@ -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::<HashMap<_,_>>();
assert_eq!(lookup, group_map_lookup);

Expand All @@ -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))
Expand Down Expand Up @@ -1551,11 +1545,10 @@ quickcheck! {
}

quickcheck! {
#[test]
fn counts(nums: Vec<isize>) -> 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() {
Expand Down Expand Up @@ -1602,7 +1595,7 @@ quickcheck! {

fn is_fused<I: Iterator>(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;
Expand Down
4 changes: 2 additions & 2 deletions tests/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
Expand All @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<usize>
}
Expand Down
30 changes: 14 additions & 16 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -474,7 +472,7 @@ impl<T: Clone + Send, R: Clone + Rng + SeedableRng + Send> 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: I, k: u16) -> ()
fn k_smallest_sort<I>(i: I, k: u16)
where
I: Iterator + Clone,
I::Item: Ord + Debug,
Expand Down Expand Up @@ -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::<Vec<_>>());

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));
Expand Down Expand Up @@ -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));
Expand All @@ -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::<Vec<_>>());

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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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]
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2279f16

Please sign in to comment.