@@ -10,11 +10,11 @@ var HashingTestSuite = TestSuite("Hashing")
10
10
11
11
func checkHash(
12
12
for value: UInt64 ,
13
- withKey key : ( UInt64 , UInt64 ) ,
13
+ withSeed seed : ( UInt64 , UInt64 ) ,
14
14
expected: UInt64 ,
15
15
file: String = #file, line: UInt = #line
16
16
) {
17
- var hasher = _Hasher ( key : key )
17
+ var hasher = _Hasher ( seed : seed )
18
18
hasher. append ( bits: value)
19
19
let hash = hasher. finalize ( )
20
20
expectEqual (
@@ -24,23 +24,23 @@ func checkHash(
24
24
25
25
HashingTestSuite . test ( " _Hasher/CustomKeys " ) {
26
26
// This assumes _Hasher implements SipHash-1-3.
27
- checkHash ( for: 0 , withKey : ( 0 , 0 ) , expected: 0xbd60acb658c79e45 )
28
- checkHash ( for: 0 , withKey : ( 0 , 1 ) , expected: 0x1ce32b0b44e61175 )
29
- checkHash ( for: 0 , withKey : ( 1 , 0 ) , expected: 0x9c44b7c8df2ca74b )
30
- checkHash ( for: 0 , withKey : ( 1 , 1 ) , expected: 0x9653ca0a3b455506 )
31
- checkHash ( for: 0 , withKey : ( . max, . max) , expected: 0x3ab336a4895e4d36 )
32
-
33
- checkHash ( for: 1 , withKey : ( 0 , 0 ) , expected: 0x1e9f734161d62dd9 )
34
- checkHash ( for: 1 , withKey : ( 0 , 1 ) , expected: 0xb6fcf32d09f76cba )
35
- checkHash ( for: 1 , withKey : ( 1 , 0 ) , expected: 0xacb556b13007504a )
36
- checkHash ( for: 1 , withKey : ( 1 , 1 ) , expected: 0x7defec680db51d24 )
37
- checkHash ( for: 1 , withKey : ( . max, . max) , expected: 0x212798441870ef6b )
38
-
39
- checkHash ( for: . max, withKey : ( 0 , 0 ) , expected: 0x2f205be2fec8e38d )
40
- checkHash ( for: . max, withKey : ( 0 , 1 ) , expected: 0x3ff7fa33381ecf7b )
41
- checkHash ( for: . max, withKey : ( 1 , 0 ) , expected: 0x404afd8eb2c4b22a )
42
- checkHash ( for: . max, withKey : ( 1 , 1 ) , expected: 0x855642d657c1bd46 )
43
- checkHash ( for: . max, withKey : ( . max, . max) , expected: 0x5b16b7a8181980c2 )
27
+ checkHash ( for: 0 , withSeed : ( 0 , 0 ) , expected: 0xbd60acb658c79e45 )
28
+ checkHash ( for: 0 , withSeed : ( 0 , 1 ) , expected: 0x1ce32b0b44e61175 )
29
+ checkHash ( for: 0 , withSeed : ( 1 , 0 ) , expected: 0x9c44b7c8df2ca74b )
30
+ checkHash ( for: 0 , withSeed : ( 1 , 1 ) , expected: 0x9653ca0a3b455506 )
31
+ checkHash ( for: 0 , withSeed : ( . max, . max) , expected: 0x3ab336a4895e4d36 )
32
+
33
+ checkHash ( for: 1 , withSeed : ( 0 , 0 ) , expected: 0x1e9f734161d62dd9 )
34
+ checkHash ( for: 1 , withSeed : ( 0 , 1 ) , expected: 0xb6fcf32d09f76cba )
35
+ checkHash ( for: 1 , withSeed : ( 1 , 0 ) , expected: 0xacb556b13007504a )
36
+ checkHash ( for: 1 , withSeed : ( 1 , 1 ) , expected: 0x7defec680db51d24 )
37
+ checkHash ( for: 1 , withSeed : ( . max, . max) , expected: 0x212798441870ef6b )
38
+
39
+ checkHash ( for: . max, withSeed : ( 0 , 0 ) , expected: 0x2f205be2fec8e38d )
40
+ checkHash ( for: . max, withSeed : ( 0 , 1 ) , expected: 0x3ff7fa33381ecf7b )
41
+ checkHash ( for: . max, withSeed : ( 1 , 0 ) , expected: 0x404afd8eb2c4b22a )
42
+ checkHash ( for: . max, withSeed : ( 1 , 1 ) , expected: 0x855642d657c1bd46 )
43
+ checkHash ( for: . max, withSeed : ( . max, . max) , expected: 0x5b16b7a8181980c2 )
44
44
}
45
45
46
46
HashingTestSuite . test ( " _Hasher/DefaultKey " ) {
@@ -52,22 +52,15 @@ HashingTestSuite.test("_Hasher/DefaultKey") {
52
52
defaultHasher. append ( bits: value)
53
53
expectEqual ( defaultHasher. finalize ( ) , defaultHash)
54
54
55
- var customHasher = _Hasher ( key : _Hasher. _secretKey )
55
+ var customHasher = _Hasher ( seed : _Hasher. _seed )
56
56
customHasher. append ( bits: value)
57
57
expectEqual ( customHasher. finalize ( ) , defaultHash)
58
58
}
59
59
60
- HashingTestSuite . test ( " _Hasher/keyOverride " ) {
61
- let value : UInt64 = 0x0102030405060708
62
- let expected = Int ( truncatingIfNeeded: 0x661dac5d71c78013 as UInt64 )
63
-
64
- let originalKey = _Hasher. _secretKey
65
- _Hasher. _secretKey = ( 1 , 2 )
66
- let hash = _hashValue ( for: value)
67
- _Hasher. _secretKey = originalKey
68
-
69
- expectEqual ( hash, expected)
60
+ HashingTestSuite . test ( " _Hasher/determinism " ) {
61
+ // By defaults, tests are configured to run with deterministic hashing.
62
+ expectTrue ( _Hasher. _isDeterministic)
63
+ expectEqual ( ( 0 , 0 ) , _Hasher. _seed)
70
64
}
71
65
72
66
runAllTests ( )
73
-
0 commit comments