@@ -974,59 +974,6 @@ class TestData : TestDataSuper {
974
974
expectTrue ( d. classForKeyedArchiver == expected)
975
975
}
976
976
977
- func test_Hashing( ) {
978
- func bridgedData( _ bytes: [ UInt8 ] ) -> Data {
979
- return bytes. withUnsafeBytes { buffer in
980
- NSData ( bytes: buffer. baseAddress, length: buffer. count) as Data
981
- }
982
- }
983
-
984
- let simpleTests : [ [ Data ] ] = [
985
- [
986
- Data ( ) ,
987
- bridgedData ( [ ] ) ,
988
- ] ,
989
- [
990
- Data ( [ 1 ] ) ,
991
- bridgedData ( [ 1 ] ) ,
992
- ] ,
993
- [
994
- Data ( [ 1 , 2 ] ) ,
995
- bridgedData ( [ 1 , 2 ] ) ,
996
- ] ,
997
- [
998
- Data ( [ 1 , 2 , 3 ] ) ,
999
- Data ( [ 1 , 2 , 3 ] ) ,
1000
- bridgedData ( [ 1 , 2 , 3 ] ) ,
1001
- bridgedData ( [ 1 , 2 , 3 ] ) ,
1002
- ] ,
1003
- [
1004
- Data ( [ 2 , 1 , 3 ] ) ,
1005
- bridgedData ( [ 2 , 1 , 3 ] ) ,
1006
- ] ,
1007
- ]
1008
- checkHashableGroups ( simpleTests)
1009
-
1010
- // To ensure strong hashing, all bytes must be fed into the hasher.
1011
- let longTest : [ Data ] = [
1012
- Data ( [ 1 ] ) + Data( UInt8 . min ... UInt8 . max) ,
1013
- Data ( [ 2 ] ) + Data( UInt8 . min ... UInt8 . max) ,
1014
- Data ( UInt8 . min ... UInt8 . max) + Data( [ 1 ] ) ,
1015
- Data ( UInt8 . min ... UInt8 . max) + Data( [ 2 ] ) ,
1016
- Data ( UInt8 . min ..< 128 ) + Data( [ 1 ] ) + Data( 128 ... UInt8 . max) ,
1017
- Data ( UInt8 . min ..< 128 ) + Data( [ 2 ] ) + Data( 128 ... UInt8 . max) ,
1018
- ]
1019
- checkHashable ( longTest, equalityOracle: { $0 == $1 } )
1020
-
1021
- let concatenationTest : [ [ Data ] ] = [
1022
- [ Data ( [ 1 , 2 , 3 ] ) , Data ( ) ] ,
1023
- [ Data ( [ 1 , 2 ] ) , Data ( [ 3 ] ) ] ,
1024
- [ Data ( [ 1 ] ) , Data ( [ 2 , 3 ] ) ] ,
1025
- [ Data ( ) , Data ( [ 1 , 2 , 3 ] ) ] ,
1026
- ]
1027
- checkHashable ( concatenationTest, equalityOracle: { $0 == $1 } )
1028
- }
1029
-
1030
977
func test_AnyHashableContainingData( ) {
1031
978
let values : [ Data ] = [
1032
979
Data ( base64Encoded: " AAAA " ) !,
@@ -3761,14 +3708,13 @@ class TestData : TestDataSuper {
3761
3708
let base2 = Data ( bytes: [ 0 , 0xFF , 0xFF , 0 ] )
3762
3709
let base3 = Data ( bytes: [ 0xFF , 0xFF , 0xFF , 0 ] )
3763
3710
let sliceEmulation = Data ( bytes: [ 0xFF , 0xFF ] )
3711
+ expectEqual ( base1. hashValue, base2. hashValue)
3764
3712
let slice1 = base1 [ base1. startIndex. advanced ( by: 1 ) ..< base1. endIndex. advanced ( by: - 1 ) ]
3765
3713
let slice2 = base2 [ base2. startIndex. advanced ( by: 1 ) ..< base2. endIndex. advanced ( by: - 1 ) ]
3766
3714
let slice3 = base3 [ base3. startIndex. advanced ( by: 1 ) ..< base3. endIndex. advanced ( by: - 1 ) ]
3767
- checkHashableGroups ( [
3768
- [ base1, base2] ,
3769
- [ base3] ,
3770
- [ sliceEmulation, slice1, slice2, slice3] ,
3771
- ] )
3715
+ expectEqual ( slice1. hashValue, sliceEmulation. hashValue)
3716
+ expectEqual ( slice1. hashValue, slice2. hashValue)
3717
+ expectEqual ( slice2. hashValue, slice3. hashValue)
3772
3718
}
3773
3719
3774
3720
func test_slice_resize_growth( ) {
@@ -3779,10 +3725,16 @@ class TestData : TestDataSuper {
3779
3725
3780
3726
func test_hashEmptyData( ) {
3781
3727
let d1 = Data ( )
3728
+ let h1 = d1. hashValue
3729
+
3782
3730
let d2 = NSData ( ) as Data
3731
+ let h2 = d2. hashValue
3732
+ expectEqual ( h1, h2)
3733
+
3783
3734
let data = Data ( bytes: [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] )
3784
3735
let d3 = data [ 4 ..< 4 ]
3785
- checkHashableGroups ( [ [ d1, d2, d3] ] )
3736
+ let h3 = d3. hashValue
3737
+ expectEqual ( h1, h3)
3786
3738
}
3787
3739
3788
3740
func test_validateMutation_slice_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
@@ -3895,7 +3847,6 @@ DataTests.test("test_basicMutableDataMutation") { TestData().test_basicMutableDa
3895
3847
DataTests . test ( " test_passing " ) { TestData ( ) . test_passing ( ) }
3896
3848
DataTests . test ( " test_bufferSizeCalculation " ) { TestData ( ) . test_bufferSizeCalculation ( ) }
3897
3849
DataTests . test ( " test_classForCoder " ) { TestData ( ) . test_classForCoder ( ) }
3898
- DataTests . test ( " test_Hashing " ) { TestData ( ) . test_Hashing ( ) }
3899
3850
DataTests . test ( " test_AnyHashableContainingData " ) { TestData ( ) . test_AnyHashableContainingData ( ) }
3900
3851
DataTests . test ( " test_AnyHashableCreatedFromNSData " ) { TestData ( ) . test_AnyHashableCreatedFromNSData ( ) }
3901
3852
DataTests . test ( " test_noCopyBehavior " ) { TestData ( ) . test_noCopyBehavior ( ) }
0 commit comments