@@ -147,6 +147,34 @@ class TestMeasurement : TestMeasurementSuper {
147
147
expectTrue ( fiveKM < sevenThousandM)
148
148
expectTrue ( fiveKM <= fiveThousandM)
149
149
}
150
+
151
+ func test_AnyHashableContainingMeasurement( ) {
152
+ let values : [ Measurement < UnitLength > ] = [
153
+ Measurement ( value: 100 , unit: UnitLength . meters) ,
154
+ Measurement ( value: 100 , unit: UnitLength . kilometers) ,
155
+ Measurement ( value: 100 , unit: UnitLength . kilometers) ,
156
+ ]
157
+ let anyHashables = values. map ( AnyHashable . init)
158
+ expectEqual ( Measurement< UnitLength> . self , type ( of: anyHashables [ 0 ] . base) )
159
+ expectEqual ( Measurement< UnitLength> . self , type ( of: anyHashables [ 1 ] . base) )
160
+ expectEqual ( Measurement< UnitLength> . self , type ( of: anyHashables [ 2 ] . base) )
161
+ expectNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
162
+ expectEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
163
+ }
164
+
165
+ func test_AnyHashableCreatedFromNSMeasurement( ) {
166
+ let values : [ NSMeasurement ] = [
167
+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . meters) ,
168
+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . kilometers) ,
169
+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . kilometers) ,
170
+ ]
171
+ let anyHashables = values. map ( AnyHashable . init)
172
+ expectEqual ( Measurement< Unit> . self , type ( of: anyHashables [ 0 ] . base) )
173
+ expectEqual ( Measurement< Unit> . self , type ( of: anyHashables [ 1 ] . base) )
174
+ expectEqual ( Measurement< Unit> . self , type ( of: anyHashables [ 2 ] . base) )
175
+ expectNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
176
+ expectEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
177
+ }
150
178
}
151
179
152
180
#if !FOUNDATION_XCTEST
@@ -159,6 +187,8 @@ if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
159
187
MeasurementTests . test ( " testMeasurementFormatter " ) { TestMeasurement ( ) . testMeasurementFormatter ( ) }
160
188
MeasurementTests . test ( " testEquality " ) { TestMeasurement ( ) . testEquality ( ) }
161
189
MeasurementTests . test ( " testComparison " ) { TestMeasurement ( ) . testComparison ( ) }
190
+ MeasurementTests . test ( " test_AnyHashableContainingMeasurement " ) { TestMeasurement ( ) . test_AnyHashableContainingMeasurement ( ) }
191
+ MeasurementTests . test ( " test_AnyHashableCreatedFromNSMeasurement " ) { TestMeasurement ( ) . test_AnyHashableCreatedFromNSMeasurement ( ) }
162
192
runAllTests ( )
163
193
}
164
194
#endif
0 commit comments