Skip to content

Commit 37bc565

Browse files
committed
Remove duplicate test cases from test_std.rs
New calls to the *_with_hasher methods are added to make sure they are callable with non-default hashers and provide the correct types.
1 parent 5b84145 commit 37bc565

File tree

1 file changed

+23
-89
lines changed

1 file changed

+23
-89
lines changed

tests/test_std.rs

Lines changed: 23 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rand::{seq::SliceRandom, thread_rng};
2323
use std::collections::HashMap;
2424
use std::hash::BuildHasher;
2525
use std::hash::RandomState;
26-
use std::iter::FromIterator;
26+
use std::iter::empty;
2727
use std::{cmp::min, fmt::Debug, marker::PhantomData};
2828

2929
// A Hasher which forwards it's calls to RandomState to make sure different hashers
@@ -99,17 +99,10 @@ fn duplicates_by() {
9999
ys_rev.iter(),
100100
xs.iter().duplicates_by(|x| x[..2].to_string()).rev(),
101101
);
102-
}
103102

104-
#[test]
105-
fn duplicates_by_with_hasher() {
106-
let xs = ["aaa", "bbbbb", "aa", "ccc", "bbbb", "aaaaa", "cccc"];
107-
let ys = ["aa", "bbbb", "cccc"];
108-
it::assert_equal(
109-
ys.iter(),
110-
xs.iter()
111-
.duplicates_by_with_hasher(|x| x[..2].to_string(), TestHasher::new()),
112-
);
103+
let _ = empty::<u8>()
104+
.duplicates_by_with_hasher(|x| *x, TestHasher::new())
105+
.next();
113106
}
114107

115108
#[test]
@@ -137,16 +130,10 @@ fn duplicates() {
137130
);
138131
let ys_rev = vec![2, 1];
139132
assert_eq!(ys_rev, xs.iter().duplicates().rev().cloned().collect_vec());
140-
}
141133

142-
#[test]
143-
fn duplicates_with_hasher() {
144-
let xs = [0, 1, 2, 3, 2, 1, 3];
145-
let ys = [2, 1, 3];
146-
it::assert_equal(
147-
xs.iter().duplicates_with_hasher(TestHasher::new()),
148-
ys.iter(),
149-
);
134+
let _ = empty::<u8>()
135+
.duplicates_with_hasher(TestHasher::new())
136+
.next();
150137
}
151138

152139
#[test]
@@ -163,17 +150,8 @@ fn unique_by() {
163150
ys_rev.iter(),
164151
xs.iter().unique_by(|x| x[..2].to_string()).rev(),
165152
);
166-
}
167153

168-
#[test]
169-
fn unique_by_with_hasher() {
170-
let xs = ["aaa", "bbbbb", "aa", "ccc", "bbbb", "aaaaa", "cccc"];
171-
let ys = ["aaa", "bbbbb", "ccc"];
172-
it::assert_equal(
173-
ys.iter(),
174-
xs.iter()
175-
.unique_by_with_hasher(|x| x[..2].to_string(), TestHasher::new()),
176-
);
154+
let _ = empty::<u8>().unique_by_with_hasher(|x| *x, TestHasher::new());
177155
}
178156

179157
#[test]
@@ -191,13 +169,8 @@ fn unique() {
191169
it::assert_equal(ys.iter(), xs.iter().rev().unique().rev());
192170
let ys_rev = [1, 0];
193171
it::assert_equal(ys_rev.iter(), xs.iter().unique().rev());
194-
}
195172

196-
#[test]
197-
fn unique_with_hasher() {
198-
let xs = [0, 1, 2, 3, 2, 1, 3];
199-
let ys = [0, 1, 2, 3];
200-
it::assert_equal(ys.iter(), xs.iter().unique_with_hasher(TestHasher::new()));
173+
let _ = empty::<u8>().unique_with_hasher(TestHasher::new());
201174
}
202175

203176
#[test]
@@ -363,11 +336,8 @@ fn all_unique() {
363336
assert!("ABCDEFGH".chars().all_unique());
364337
assert!(!"ABCDEFGA".chars().all_unique());
365338
assert!(::std::iter::empty::<usize>().all_unique());
366-
}
367339

368-
#[test]
369-
fn all_unique_with_hasher() {
370-
assert!("ABCDEFGH".chars().all_unique_with_hasher(TestHasher::new()));
340+
let _ = empty::<u8>().all_unique_with_hasher(TestHasher::new());
371341
}
372342

373343
#[test]
@@ -1637,73 +1607,37 @@ fn multiunzip() {
16371607

16381608
#[test]
16391609
fn into_group_map_with_hasher() {
1640-
let xs = vec![(0, 10), (2, 12), (3, 13), (0, 20), (3, 33), (2, 42)];
1641-
let lookup: HashMap<i32, Vec<i32>, TestHasher> =
1642-
xs.into_iter().into_group_map_with_hasher(TestHasher::new());
1643-
1644-
assert_eq!(lookup[&0], vec![10, 20]);
1645-
assert_eq!(lookup.get(&1), None);
1646-
assert_eq!(lookup[&2], vec![12, 42]);
1647-
assert_eq!(lookup[&3], vec![13, 33]);
1610+
let _: HashMap<_, _, TestHasher> =
1611+
empty::<(u8, u8)>().into_group_map_with_hasher(TestHasher::new());
16481612
}
16491613

16501614
#[test]
16511615
fn into_group_map_by_with_hasher() {
1652-
let xs = vec![(0, 10), (2, 12), (3, 13), (0, 20), (3, 33), (2, 42)];
1653-
let lookup: HashMap<u32, Vec<(u32, u32)>, TestHasher> = xs
1654-
.into_iter()
1655-
.into_group_map_by_with_hasher(|a| a.0, TestHasher::new());
1656-
1657-
assert_eq!(lookup[&0], vec![(0, 10), (0, 20)]);
1658-
assert_eq!(lookup.get(&1), None);
1659-
assert_eq!(lookup[&2], vec![(2, 12), (2, 42)]);
1660-
assert_eq!(lookup[&3], vec![(3, 13), (3, 33)]);
1616+
let _: HashMap<_, _, TestHasher> =
1617+
empty::<(u8, u8)>().into_group_map_by_with_hasher(|x| *x, TestHasher::new());
16611618
}
16621619

16631620
#[test]
16641621
fn into_grouping_map_with_hasher() {
1665-
let xs = vec![(0, 10), (2, 12), (3, 13), (0, 20), (3, 33), (2, 42)];
1666-
let exp = HashMap::from_iter([(0, vec![10, 20]), (2, vec![12, 42]), (3, vec![13, 33])]);
1667-
assert_eq!(
1668-
xs.into_iter()
1669-
.into_grouping_map_with_hasher(TestHasher::new())
1670-
.collect(),
1671-
exp
1672-
);
1622+
let _: HashMap<_, Vec<_>, TestHasher> = empty::<(u8, u8)>()
1623+
.into_grouping_map_with_hasher(TestHasher::new())
1624+
.collect();
16731625
}
16741626

16751627
#[test]
16761628
fn into_grouping_map_by_with_hasher() {
1677-
let xs = vec![(0, 10), (2, 12), (3, 13), (0, 20), (3, 33), (2, 42)];
1678-
let exp = HashMap::from_iter([
1679-
(0, vec![(0, 10), (0, 20)]),
1680-
(2, vec![(2, 12), (2, 42)]),
1681-
(3, vec![(3, 13), (3, 33)]),
1682-
]);
1683-
assert_eq!(
1684-
xs.into_iter()
1685-
.into_grouping_map_by_with_hasher(|t| { t.0 }, TestHasher::new())
1686-
.collect(),
1687-
exp
1688-
);
1629+
let _: HashMap<_, Vec<_>, TestHasher> = empty::<(u8, u8)>()
1630+
.into_grouping_map_by_with_hasher(|x| *x, TestHasher::new())
1631+
.collect();
16891632
}
16901633

16911634
#[test]
16921635
fn counts_with_hasher() {
1693-
assert_eq!(
1694-
[1, 1, 1, 3, 3, 5]
1695-
.iter()
1696-
.counts_with_hasher(TestHasher::new()),
1697-
HashMap::from_iter([(&1, 3), (&3, 2), (&5, 1)])
1698-
);
1636+
let _: HashMap<_, _, TestHasher> = empty::<u8>().counts_with_hasher(TestHasher::new());
16991637
}
17001638

17011639
#[test]
17021640
fn counts_by_with_hasher() {
1703-
assert_eq!(
1704-
[10, 12, 13, 20, 42, 33, 52, 17]
1705-
.iter()
1706-
.counts_by_with_hasher(|x| x % 10, TestHasher::new()),
1707-
HashMap::from_iter([(0, 2), (2, 3), (3, 2), (7, 1)])
1708-
);
1641+
let _: HashMap<_, _, TestHasher> =
1642+
empty::<u8>().counts_by_with_hasher(|x| x, TestHasher::new());
17091643
}

0 commit comments

Comments
 (0)