@@ -10,6 +10,9 @@ import StdlibUnittest
10
10
var ObjectiveCTests = TestSuite ( " ObjectiveC " )
11
11
12
12
class NSObjectWithCustomHashable : NSObject {
13
+ var _value : Int
14
+ var _hashValue : Int
15
+
13
16
init ( value: Int , hashValue: Int ) {
14
17
self . _value = value
15
18
self . _hashValue = hashValue
@@ -20,24 +23,22 @@ class NSObjectWithCustomHashable : NSObject {
20
23
return self . _value == other_. _value
21
24
}
22
25
23
- override var hashValue : Int {
26
+ override var hash : Int {
24
27
return _hashValue
25
28
}
26
-
27
- var _value : Int
28
- var _hashValue : Int
29
29
}
30
30
31
31
ObjectiveCTests . test ( " NSObject/Hashable " ) {
32
- let instances : [ ( order: Int , object: NSObject ) ] = [
33
- ( 10 , NSObjectWithCustomHashable ( value: 10 , hashValue: 100 ) ) ,
34
- ( 10 , NSObjectWithCustomHashable ( value: 10 , hashValue: 100 ) ) ,
35
- ( 20 , NSObjectWithCustomHashable ( value: 20 , hashValue: 100 ) ) ,
36
- ( 30 , NSObjectWithCustomHashable ( value: 30 , hashValue: 300 ) ) ,
32
+ let instances : [ ( order: Int , hashOrder : Int , object: NSObject ) ] = [
33
+ ( 10 , 1 , NSObjectWithCustomHashable ( value: 10 , hashValue: 100 ) ) ,
34
+ ( 10 , 1 , NSObjectWithCustomHashable ( value: 10 , hashValue: 100 ) ) ,
35
+ ( 20 , 1 , NSObjectWithCustomHashable ( value: 20 , hashValue: 100 ) ) ,
36
+ ( 30 , 2 , NSObjectWithCustomHashable ( value: 30 , hashValue: 300 ) ) ,
37
37
]
38
38
checkHashable (
39
39
instances. map { $0. object } ,
40
- equalityOracle: { instances [ $0] . order == instances [ $1] . order } )
40
+ equalityOracle: { instances [ $0] . order == instances [ $1] . order } ,
41
+ hashEqualityOracle: { instances [ $0] . hashOrder == instances [ $1] . hashOrder } )
41
42
}
42
43
43
44
runAllTests ( )
0 commit comments