@@ -23,7 +23,7 @@ use rand::{seq::SliceRandom, thread_rng};
23
23
use std:: collections:: HashMap ;
24
24
use std:: hash:: BuildHasher ;
25
25
use std:: hash:: RandomState ;
26
- use std:: iter:: FromIterator ;
26
+ use std:: iter:: empty ;
27
27
use std:: { cmp:: min, fmt:: Debug , marker:: PhantomData } ;
28
28
29
29
// A Hasher which forwards it's calls to RandomState to make sure different hashers
@@ -99,17 +99,10 @@ fn duplicates_by() {
99
99
ys_rev. iter ( ) ,
100
100
xs. iter ( ) . duplicates_by ( |x| x[ ..2 ] . to_string ( ) ) . rev ( ) ,
101
101
) ;
102
- }
103
102
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 ( ) ;
113
106
}
114
107
115
108
#[ test]
@@ -137,16 +130,10 @@ fn duplicates() {
137
130
) ;
138
131
let ys_rev = vec ! [ 2 , 1 ] ;
139
132
assert_eq ! ( ys_rev, xs. iter( ) . duplicates( ) . rev( ) . cloned( ) . collect_vec( ) ) ;
140
- }
141
133
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 ( ) ;
150
137
}
151
138
152
139
#[ test]
@@ -163,17 +150,8 @@ fn unique_by() {
163
150
ys_rev. iter ( ) ,
164
151
xs. iter ( ) . unique_by ( |x| x[ ..2 ] . to_string ( ) ) . rev ( ) ,
165
152
) ;
166
- }
167
153
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 ( ) ) ;
177
155
}
178
156
179
157
#[ test]
@@ -191,13 +169,8 @@ fn unique() {
191
169
it:: assert_equal ( ys. iter ( ) , xs. iter ( ) . rev ( ) . unique ( ) . rev ( ) ) ;
192
170
let ys_rev = [ 1 , 0 ] ;
193
171
it:: assert_equal ( ys_rev. iter ( ) , xs. iter ( ) . unique ( ) . rev ( ) ) ;
194
- }
195
172
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 ( ) ) ;
201
174
}
202
175
203
176
#[ test]
@@ -363,11 +336,8 @@ fn all_unique() {
363
336
assert ! ( "ABCDEFGH" . chars( ) . all_unique( ) ) ;
364
337
assert ! ( !"ABCDEFGA" . chars( ) . all_unique( ) ) ;
365
338
assert ! ( :: std:: iter:: empty:: <usize >( ) . all_unique( ) ) ;
366
- }
367
339
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 ( ) ) ;
371
341
}
372
342
373
343
#[ test]
@@ -1637,73 +1607,37 @@ fn multiunzip() {
1637
1607
1638
1608
#[ test]
1639
1609
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 ( ) ) ;
1648
1612
}
1649
1613
1650
1614
#[ test]
1651
1615
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 ( ) ) ;
1661
1618
}
1662
1619
1663
1620
#[ test]
1664
1621
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 ( ) ;
1673
1625
}
1674
1626
1675
1627
#[ test]
1676
1628
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 ( ) ;
1689
1632
}
1690
1633
1691
1634
#[ test]
1692
1635
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 ( ) ) ;
1699
1637
}
1700
1638
1701
1639
#[ test]
1702
1640
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 ( ) ) ;
1709
1643
}
0 commit comments