@@ -147,6 +147,36 @@ class TestMeasurement : TestMeasurementSuper {
147147 expectTrue ( fiveKM < sevenThousandM)
148148 expectTrue ( fiveKM <= fiveThousandM)
149149 }
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+ if #available( iOS 8 . 0 , * ) {
167+ let values : [ NSMeasurement ] = [
168+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . meters) ,
169+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . kilometers) ,
170+ NSMeasurement ( doubleValue: 100 , unit: UnitLength . kilometers) ,
171+ ]
172+ let anyHashables = values. map ( AnyHashable . init)
173+ expectEqual ( Measurement . self, type ( of: anyHashables [ 0 ] . base) )
174+ expectEqual ( Measurement . self, type ( of: anyHashables [ 1 ] . base) )
175+ expectEqual ( Measurement . self, type ( of: anyHashables [ 2 ] . base) )
176+ expectNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
177+ expectEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
178+ }
179+ }
150180}
151181
152182#if !FOUNDATION_XCTEST
@@ -159,6 +189,8 @@ if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
159189 MeasurementTests . test ( " testMeasurementFormatter " ) { TestMeasurement ( ) . testMeasurementFormatter ( ) }
160190 MeasurementTests . test ( " testEquality " ) { TestMeasurement ( ) . testEquality ( ) }
161191 MeasurementTests . test ( " testComparison " ) { TestMeasurement ( ) . testComparison ( ) }
192+ MeasurementTests . test ( " test_AnyHashableContainingMeasurement " ) { TestMeasurement ( ) . test_AnyHashableContainingMeasurement ( ) }
193+ MeasurementTests . test ( " test_AnyHashableCreatedFromNSMeasurement " ) { TestMeasurement ( ) . test_AnyHashableCreatedFromNSMeasurement ( ) }
162194 runAllTests ( )
163195}
164196#endif
0 commit comments