summaryrefslogtreecommitdiffstats
path: root/vendor/itertools/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:11:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:12:43 +0000
commitcf94bdc0742c13e2a0cac864c478b8626b266e1b (patch)
tree044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /vendor/itertools/tests
parentAdding debian version 1.65.0+dfsg1-2. (diff)
downloadrustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz
rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/itertools/tests')
-rw-r--r--vendor/itertools/tests/adaptors_no_collect.rs11
-rw-r--r--vendor/itertools/tests/quick.rs116
-rw-r--r--vendor/itertools/tests/specializations.rs4
-rw-r--r--vendor/itertools/tests/test_core.rs15
-rw-r--r--vendor/itertools/tests/test_std.rs80
-rw-r--r--vendor/itertools/tests/zip.rs8
6 files changed, 164 insertions, 70 deletions
diff --git a/vendor/itertools/tests/adaptors_no_collect.rs b/vendor/itertools/tests/adaptors_no_collect.rs
index a47f906f9..103db23f1 100644
--- a/vendor/itertools/tests/adaptors_no_collect.rs
+++ b/vendor/itertools/tests/adaptors_no_collect.rs
@@ -11,12 +11,11 @@ impl Iterator for PanickingCounter {
fn next(&mut self) -> Option<Self::Item> {
self.curr += 1;
- if self.curr == self.max {
- panic!(
- "Input iterator reached maximum of {} suggesting collection by adaptor",
- self.max
- );
- }
+ assert_ne!(
+ self.curr, self.max,
+ "Input iterator reached maximum of {} suggesting collection by adaptor",
+ self.max
+ );
Some(())
}
diff --git a/vendor/itertools/tests/quick.rs b/vendor/itertools/tests/quick.rs
index 7e222a641..0adcf1ad7 100644
--- a/vendor/itertools/tests/quick.rs
+++ b/vendor/itertools/tests/quick.rs
@@ -258,12 +258,13 @@ where
let mut it = get_it();
for _ in 0..(counts.len() - 1) {
- if let None = it.next() {
+ #[allow(clippy::manual_assert)]
+ 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 +439,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,15 +499,13 @@ quickcheck! {
exact_size(it)
}
- fn equal_merge(a: Vec<i16>, b: Vec<i16>) -> bool {
- let mut sa = a.clone();
- let mut sb = b.clone();
- sa.sort();
- sb.sort();
- let mut merged = sa.clone();
- merged.extend(sb.iter().cloned());
+ fn equal_merge(mut a: Vec<i16>, mut b: Vec<i16>) -> bool {
+ a.sort();
+ b.sort();
+ let mut merged = a.clone();
+ merged.extend(b.iter().cloned());
merged.sort();
- itertools::equal(&merged, sa.iter().merge(&sb))
+ itertools::equal(&merged, a.iter().merge(&b))
}
fn size_merge(a: Iter<u16>, b: Iter<u16>) -> bool {
correct_size_hint(a.merge(b))
@@ -517,7 +516,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)))
}
@@ -526,19 +525,16 @@ 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 a: Vec<i16>, mut b: Vec<i16>, mut c: 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();
- let mut merged = sa.clone();
- merged.extend(sb.iter().cloned());
- merged.extend(sc.iter().cloned());
+ a.sort();
+ b.sort();
+ c.sort();
+ let mut merged = a.clone();
+ merged.extend(b.iter().cloned());
+ merged.extend(c.iter().cloned());
merged.sort();
- itertools::equal(merged.into_iter(), kmerge(vec![sa, sb, sc]))
+ itertools::equal(merged.into_iter(), kmerge(vec![a, b, c]))
}
// Any number of input iterators
@@ -610,7 +606,7 @@ 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),
@@ -618,7 +614,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 +717,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 +939,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))
}
}
@@ -1286,7 +1281,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);
@@ -1551,10 +1546,10 @@ quickcheck! {
}
quickcheck! {
- #[test]
fn counts(nums: Vec<isize>) -> TestResult {
let counts = nums.iter().counts();
for (&item, &count) in counts.iter() {
+ #[allow(clippy::absurd_extreme_comparisons)]
if count <= 0 {
return TestResult::failed();
}
@@ -1602,7 +1597,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;
@@ -1693,3 +1688,62 @@ quickcheck! {
}
}
+quickcheck! {
+ fn min_set_contains_min(a: Vec<(usize, char)>) -> bool {
+ let result_set = a.iter().min_set();
+ if let Some(result_element) = a.iter().min() {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+
+ fn min_set_by_contains_min(a: Vec<(usize, char)>) -> bool {
+ let compare = |x: &&(usize, char), y: &&(usize, char)| x.1.cmp(&y.1);
+ let result_set = a.iter().min_set_by(compare);
+ if let Some(result_element) = a.iter().min_by(compare) {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+
+ fn min_set_by_key_contains_min(a: Vec<(usize, char)>) -> bool {
+ let key = |x: &&(usize, char)| x.1;
+ let result_set = a.iter().min_set_by_key(&key);
+ if let Some(result_element) = a.iter().min_by_key(&key) {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+
+ fn max_set_contains_max(a: Vec<(usize, char)>) -> bool {
+ let result_set = a.iter().max_set();
+ if let Some(result_element) = a.iter().max() {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+
+ fn max_set_by_contains_max(a: Vec<(usize, char)>) -> bool {
+ let compare = |x: &&(usize, char), y: &&(usize, char)| x.1.cmp(&y.1);
+ let result_set = a.iter().max_set_by(compare);
+ if let Some(result_element) = a.iter().max_by(compare) {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+
+ fn max_set_by_key_contains_max(a: Vec<(usize, char)>) -> bool {
+ let key = |x: &&(usize, char)| x.1;
+ let result_set = a.iter().max_set_by_key(&key);
+ if let Some(result_element) = a.iter().max_by_key(&key) {
+ result_set.contains(&result_element)
+ } else {
+ result_set.is_empty()
+ }
+ }
+}
diff --git a/vendor/itertools/tests/specializations.rs b/vendor/itertools/tests/specializations.rs
index 199cf562a..057e11c9f 100644
--- a/vendor/itertools/tests/specializations.rs
+++ b/vendor/itertools/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/vendor/itertools/tests/test_core.rs b/vendor/itertools/tests/test_core.rs
index a7b7449d3..df94eb665 100644
--- a/vendor/itertools/tests/test_core.rs
+++ b/vendor/itertools/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]);
@@ -180,15 +180,10 @@ fn batching() {
let ys = [(0, 1), (2, 1)];
// An iterator that gathers elements up in pairs
- let pit = xs.iter().cloned().batching(|it| {
- match it.next() {
- None => None,
- Some(x) => match it.next() {
- None => None,
- Some(y) => Some((x, y)),
- }
- }
- });
+ let pit = xs
+ .iter()
+ .cloned()
+ .batching(|it| it.next().and_then(|x| it.next().map(|y| (x, y))));
it::assert_equal(pit, ys.iter().cloned());
}
diff --git a/vendor/itertools/tests/test_std.rs b/vendor/itertools/tests/test_std.rs
index 2049d1597..f59034234 100644
--- a/vendor/itertools/tests/test_std.rs
+++ b/vendor/itertools/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<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,
@@ -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));
@@ -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::<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));
@@ -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]) {
@@ -993,6 +991,54 @@ fn diff_shorter() {
}
#[test]
+fn extrema_set() {
+ use std::cmp::Ordering;
+
+ // A peculiar type: Equality compares both tuple items, but ordering only the
+ // first item. Used to distinguish equal elements.
+ #[derive(Clone, Debug, PartialEq, Eq)]
+ struct Val(u32, u32);
+
+ impl PartialOrd<Val> for Val {
+ fn partial_cmp(&self, other: &Val) -> Option<Ordering> {
+ self.0.partial_cmp(&other.0)
+ }
+ }
+
+ impl Ord for Val {
+ fn cmp(&self, other: &Val) -> Ordering {
+ self.0.cmp(&other.0)
+ }
+ }
+
+ assert_eq!(None::<u32>.iter().min_set(), Vec::<&u32>::new());
+ assert_eq!(None::<u32>.iter().max_set(), Vec::<&u32>::new());
+
+ assert_eq!(Some(1u32).iter().min_set(), vec![&1]);
+ assert_eq!(Some(1u32).iter().max_set(), vec![&1]);
+
+ let data = vec![Val(0, 1), Val(2, 0), Val(0, 2), Val(1, 0), Val(2, 1)];
+
+ let min_set = data.iter().min_set();
+ assert_eq!(min_set, vec![&Val(0, 1), &Val(0, 2)]);
+
+ let min_set_by_key = data.iter().min_set_by_key(|v| v.1);
+ assert_eq!(min_set_by_key, vec![&Val(2, 0), &Val(1, 0)]);
+
+ let min_set_by = data.iter().min_set_by(|x, y| x.1.cmp(&y.1));
+ assert_eq!(min_set_by, vec![&Val(2, 0), &Val(1, 0)]);
+
+ let max_set = data.iter().max_set();
+ assert_eq!(max_set, vec![&Val(2, 0), &Val(2, 1)]);
+
+ let max_set_by_key = data.iter().max_set_by_key(|v| v.1);
+ assert_eq!(max_set_by_key, vec![&Val(0, 2)]);
+
+ let max_set_by = data.iter().max_set_by(|x, y| x.1.cmp(&y.1));
+ assert_eq!(max_set_by, vec![&Val(0, 2)]);
+}
+
+#[test]
fn minmax() {
use std::cmp::Ordering;
use crate::it::MinMaxResult;
@@ -1043,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]
@@ -1062,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 {
@@ -1095,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);
@@ -1119,4 +1165,4 @@ fn multiunzip() {
let (): () = [(), (), ()].iter().cloned().multiunzip();
let t: (Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>, Vec<_>) = [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)].iter().cloned().multiunzip();
assert_eq!(t, (vec![0], vec![1], vec![2], vec![3], vec![4], vec![5], vec![6], vec![7], vec![8], vec![9], vec![10], vec![11]));
-} \ No newline at end of file
+}
diff --git a/vendor/itertools/tests/zip.rs b/vendor/itertools/tests/zip.rs
index 5801b4232..75157d34f 100644
--- a/vendor/itertools/tests/zip.rs
+++ b/vendor/itertools/tests/zip.rs
@@ -29,8 +29,8 @@ fn test_zip_longest_size_hint() {
fn test_double_ended_zip_longest() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
- let a = xs.iter().map(|&x| x);
- let b = ys.iter().map(|&x| x);
+ let a = xs.iter().copied();
+ let b = ys.iter().copied();
let mut it = a.zip_longest(b);
assert_eq!(it.next(), Some(Both(1, 1)));
assert_eq!(it.next(), Some(Both(2, 2)));
@@ -45,8 +45,8 @@ fn test_double_ended_zip_longest() {
fn test_double_ended_zip() {
let xs = [1, 2, 3, 4, 5, 6];
let ys = [1, 2, 3, 7];
- let a = xs.iter().map(|&x| x);
- let b = ys.iter().map(|&x| x);
+ let a = xs.iter().copied();
+ let b = ys.iter().copied();
let mut it = multizip((a, b));
assert_eq!(it.next_back(), Some((4, 7)));
assert_eq!(it.next_back(), Some((3, 3)));