Skip to content

Commit 2279f16

Browse files
committed
apply clippy lints to tests
1 parent 06d62d7 commit 2279f16

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

tests/quick.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ where
258258
let mut it = get_it();
259259

260260
for _ in 0..(counts.len() - 1) {
261-
if let None = it.next() {
261+
if it.next().is_none() {
262262
panic!("Iterator shouldn't be finished, may not be deterministic");
263263
}
264264
}
265265

266-
if let None = it.next() {
266+
if it.next().is_none() {
267267
break 'outer;
268268
}
269269

@@ -438,7 +438,7 @@ quickcheck! {
438438
}
439439
assert_eq!(answer, actual);
440440

441-
assert_eq!(answer.into_iter().last(), a.clone().multi_cartesian_product().last());
441+
assert_eq!(answer.into_iter().last(), a.multi_cartesian_product().last());
442442
}
443443

444444
#[allow(deprecated)]
@@ -498,9 +498,7 @@ quickcheck! {
498498
exact_size(it)
499499
}
500500

501-
fn equal_merge(a: Vec<i16>, b: Vec<i16>) -> bool {
502-
let mut sa = a.clone();
503-
let mut sb = b.clone();
501+
fn equal_merge(mut sa: Vec<i16>, mut sb: Vec<i16>) -> bool {
504502
sa.sort();
505503
sb.sort();
506504
let mut merged = sa.clone();
@@ -517,7 +515,7 @@ quickcheck! {
517515
exact_size(multizip((a, b, c)))
518516
}
519517
fn size_zip_rc(a: Iter<i16>, b: Iter<i16>) -> bool {
520-
let rc = rciter(a.clone());
518+
let rc = rciter(a);
521519
correct_size_hint(multizip((&rc, &rc, b)))
522520
}
523521

@@ -526,11 +524,8 @@ quickcheck! {
526524
correct_size_hint(izip!(filt, b.clone(), c.clone())) &&
527525
exact_size(izip!(a, b, c))
528526
}
529-
fn equal_kmerge(a: Vec<i16>, b: Vec<i16>, c: Vec<i16>) -> bool {
527+
fn equal_kmerge(mut sa: Vec<i16>, mut sb: Vec<i16>, mut sc: Vec<i16>) -> bool {
530528
use itertools::free::kmerge;
531-
let mut sa = a.clone();
532-
let mut sb = b.clone();
533-
let mut sc = c.clone();
534529
sa.sort();
535530
sb.sort();
536531
sc.sort();
@@ -610,15 +605,15 @@ quickcheck! {
610605
fn size_2_zip_longest(a: Iter<i16>, b: Iter<i16>) -> bool {
611606
let it = a.clone().zip_longest(b.clone());
612607
let jt = a.clone().zip_longest(b.clone());
613-
itertools::equal(a.clone(),
608+
itertools::equal(a,
614609
it.filter_map(|elt| match elt {
615610
EitherOrBoth::Both(x, _) => Some(x),
616611
EitherOrBoth::Left(x) => Some(x),
617612
_ => None,
618613
}
619614
))
620615
&&
621-
itertools::equal(b.clone(),
616+
itertools::equal(b,
622617
jt.filter_map(|elt| match elt {
623618
EitherOrBoth::Both(_, y) => Some(y),
624619
EitherOrBoth::Right(y) => Some(y),
@@ -721,7 +716,7 @@ quickcheck! {
721716

722717
assert_eq!(expected_first, curr_perm);
723718

724-
while let Some(next_perm) = perms.next() {
719+
for next_perm in perms {
725720
assert!(
726721
next_perm > curr_perm,
727722
"next perm isn't greater-than current; next_perm={:?} curr_perm={:?} n={}",
@@ -943,8 +938,7 @@ quickcheck! {
943938
fn fuzz_group_by_lazy_1(it: Iter<u8>) -> bool {
944939
let jt = it.clone();
945940
let groups = it.group_by(|k| *k);
946-
let res = itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x));
947-
res
941+
itertools::equal(jt, groups.into_iter().flat_map(|(_, x)| x))
948942
}
949943
}
950944

@@ -1286,7 +1280,7 @@ quickcheck! {
12861280
.map(|i| (i % modulo, i))
12871281
.into_group_map()
12881282
.into_iter()
1289-
.map(|(key, vals)| (key, vals.into_iter().fold(0u64, |acc, val| acc + val)))
1283+
.map(|(key, vals)| (key, vals.into_iter().sum()))
12901284
.collect::<HashMap<_,_>>();
12911285
assert_eq!(lookup, group_map_lookup);
12921286

@@ -1304,7 +1298,7 @@ quickcheck! {
13041298
acc + val
13051299
});
13061300

1307-
// TODO: Swap `fold1` with stdlib's `fold_first` when it's stabilized
1301+
#[allow(deprecated)] //TODO: once msrv hits 1.51. replace `fold1` with `reduce`
13081302
let group_map_lookup = a.iter()
13091303
.map(|&b| b as u64)
13101304
.map(|i| (i % modulo, i))
@@ -1551,11 +1545,10 @@ quickcheck! {
15511545
}
15521546

15531547
quickcheck! {
1554-
#[test]
15551548
fn counts(nums: Vec<isize>) -> TestResult {
15561549
let counts = nums.iter().counts();
15571550
for (&item, &count) in counts.iter() {
1558-
if count <= 0 {
1551+
if count == 0 {
15591552
return TestResult::failed();
15601553
}
15611554
if count != nums.iter().filter(|&x| x == item).count() {
@@ -1602,7 +1595,7 @@ quickcheck! {
16021595

16031596
fn is_fused<I: Iterator>(mut it: I) -> bool
16041597
{
1605-
while let Some(_) = it.next() {}
1598+
for _ in it.by_ref() {}
16061599
for _ in 0..10{
16071600
if it.next().is_some(){
16081601
return false;

tests/specializations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ quickcheck! {
129129
check_results_specialized!(it, |i| {
130130
let mut parameters_from_fold = vec![];
131131
let fold_result = i.fold(vec![], |mut acc, v| {
132-
parameters_from_fold.push((acc.clone(), v.clone()));
132+
parameters_from_fold.push((acc.clone(), v));
133133
acc.push(v);
134134
acc
135135
});
@@ -139,7 +139,7 @@ quickcheck! {
139139
let mut parameters_from_all = vec![];
140140
let first = i.next();
141141
let all_result = i.all(|x| {
142-
parameters_from_all.push(x.clone());
142+
parameters_from_all.push(x);
143143
Some(x)==first
144144
});
145145
(parameters_from_all, all_result)

tests/test_core.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn chain2() {
116116
fn write_to() {
117117
let xs = [7, 9, 8];
118118
let mut ys = [0; 5];
119-
let cnt = ys.iter_mut().set_from(xs.iter().map(|x| *x));
119+
let cnt = ys.iter_mut().set_from(xs.iter().copied());
120120
assert!(cnt == xs.len());
121121
assert!(ys == [7, 9, 8, 0, 0]);
122122

@@ -183,10 +183,7 @@ fn batching() {
183183
let pit = xs.iter().cloned().batching(|it| {
184184
match it.next() {
185185
None => None,
186-
Some(x) => match it.next() {
187-
None => None,
188-
Some(y) => Some((x, y)),
189-
}
186+
Some(x) => it.next().map(|y| (x, y))
190187
}
191188
});
192189
it::assert_equal(pit, ys.iter().cloned());
@@ -234,7 +231,7 @@ fn count_clones() {
234231
// Check that RepeatN only clones N - 1 times.
235232

236233
use core::cell::Cell;
237-
#[derive(PartialEq, Debug)]
234+
#[derive(PartialEq, Eq, Debug)]
238235
struct Foo {
239236
n: Cell<usize>
240237
}

tests/test_std.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use paste;
2-
use permutohedron;
31
use quickcheck as qc;
42
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
53
use rand::{seq::SliceRandom, thread_rng};
@@ -123,12 +121,12 @@ fn unique() {
123121
#[test]
124122
fn intersperse() {
125123
let xs = ["a", "", "b", "c"];
126-
let v: Vec<&str> = xs.iter().map(|x| x.clone()).intersperse(", ").collect();
124+
let v: Vec<&str> = xs.iter().cloned().intersperse(", ").collect();
127125
let text: String = v.concat();
128126
assert_eq!(text, "a, , b, c".to_string());
129127

130128
let ys = [0, 1, 2, 3];
131-
let mut it = ys[..0].iter().map(|x| *x).intersperse(1);
129+
let mut it = ys[..0].iter().copied().intersperse(1);
132130
assert!(it.next() == None);
133131
}
134132

@@ -474,7 +472,7 @@ impl<T: Clone + Send, R: Clone + Rng + SeedableRng + Send> qc::Arbitrary for Ran
474472

475473
// Check that taking the k smallest is the same as
476474
// sorting then taking the k first elements
477-
fn k_smallest_sort<I>(i: I, k: u16) -> ()
475+
fn k_smallest_sort<I>(i: I, k: u16)
478476
where
479477
I: Iterator + Clone,
480478
I::Item: Ord + Debug,
@@ -538,10 +536,10 @@ fn sorted_by_cached_key() {
538536
fn test_multipeek() {
539537
let nums = vec![1u8,2,3,4,5];
540538

541-
let mp = multipeek(nums.iter().map(|&x| x));
539+
let mp = multipeek(nums.iter().copied());
542540
assert_eq!(nums, mp.collect::<Vec<_>>());
543541

544-
let mut mp = multipeek(nums.iter().map(|&x| x));
542+
let mut mp = multipeek(nums.iter().copied());
545543
assert_eq!(mp.peek(), Some(&1));
546544
assert_eq!(mp.next(), Some(1));
547545
assert_eq!(mp.peek(), Some(&2));
@@ -579,7 +577,7 @@ fn test_multipeek_peeking_next() {
579577
use crate::it::PeekingNext;
580578
let nums = vec![1u8,2,3,4,5,6,7];
581579

582-
let mut mp = multipeek(nums.iter().map(|&x| x));
580+
let mut mp = multipeek(nums.iter().copied());
583581
assert_eq!(mp.peeking_next(|&x| x != 0), Some(1));
584582
assert_eq!(mp.next(), Some(2));
585583
assert_eq!(mp.peek(), Some(&3));
@@ -604,10 +602,10 @@ fn test_multipeek_peeking_next() {
604602
fn test_peek_nth() {
605603
let nums = vec![1u8,2,3,4,5];
606604

607-
let iter = peek_nth(nums.iter().map(|&x| x));
605+
let iter = peek_nth(nums.iter().copied());
608606
assert_eq!(nums, iter.collect::<Vec<_>>());
609607

610-
let mut iter = peek_nth(nums.iter().map(|&x| x));
608+
let mut iter = peek_nth(nums.iter().copied());
611609

612610
assert_eq!(iter.peek_nth(0), Some(&1));
613611
assert_eq!(iter.peek_nth(0), Some(&1));
@@ -638,7 +636,7 @@ fn test_peek_nth() {
638636
fn test_peek_nth_peeking_next() {
639637
use it::PeekingNext;
640638
let nums = vec![1u8,2,3,4,5,6,7];
641-
let mut iter = peek_nth(nums.iter().map(|&x| x));
639+
let mut iter = peek_nth(nums.iter().copied());
642640

643641
assert_eq!(iter.peeking_next(|&x| x != 0), Some(1));
644642
assert_eq!(iter.next(), Some(2));
@@ -694,7 +692,7 @@ fn group_by() {
694692
}
695693
}
696694

697-
let toupper = |ch: &char| ch.to_uppercase().nth(0).unwrap();
695+
let toupper = |ch: &char| ch.to_uppercase().next().unwrap();
698696

699697
// try all possible orderings
700698
for indices in permutohedron::Heap::new(&mut [0, 1, 2, 3]) {
@@ -1091,9 +1089,9 @@ fn format() {
10911089
let t2 = format!("{:?}", data.iter().format("--"));
10921090
assert_eq!(t2, ans2);
10931091

1094-
let dataf = [1.1, 2.71828, -22.];
1092+
let dataf = [1.1, 5.71828, -22.];
10951093
let t3 = format!("{:.2e}", dataf.iter().format(", "));
1096-
assert_eq!(t3, "1.10e0, 2.72e0, -2.20e1");
1094+
assert_eq!(t3, "1.10e0, 5.72e0, -2.20e1");
10971095
}
10981096

10991097
#[test]
@@ -1110,7 +1108,7 @@ fn fold_while() {
11101108
let vec = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
11111109
let sum = vec.into_iter().fold_while(0, |acc, item| {
11121110
iterations += 1;
1113-
let new_sum = acc.clone() + item;
1111+
let new_sum = acc + item;
11141112
if new_sum <= 20 {
11151113
FoldWhile::Continue(new_sum)
11161114
} else {
@@ -1143,7 +1141,7 @@ fn tree_fold1() {
11431141
"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",
11441142
];
11451143
for (i, &s) in x.iter().enumerate() {
1146-
let expected = if s == "" { None } else { Some(s.to_string()) };
1144+
let expected = if s.is_empty() { None } else { Some(s.to_string()) };
11471145
let num_strings = (0..i).map(|x| x.to_string());
11481146
let actual = num_strings.tree_fold1(|a, b| format!("{} {} x", a, b));
11491147
assert_eq!(actual, expected);

0 commit comments

Comments
 (0)