@@ -152,10 +152,17 @@ class SortedArrayTests: XCTestCase {
152152 XCTAssertEqual ( description, " <SortedArray> [ \" a \" , \" b \" , \" c \" ] " )
153153 }
154154
155- func testFilter( ) {
156- let sut = SortedArray ( unsorted: [ " a " , " b " , " c " ] )
157- assertElementsEqual ( sut. filter { $0 != " a " } , [ " b " , " c " ] )
155+ func testFilterReturnsSortedArray( ) {
156+ let source = SortedArray ( unsorted: [ 3 , 2 , 1 ] )
157+ let sut = source. filter { $0 % 2 == 0 }
158+ XCTAssert ( type ( of: sut) == SortedArray< Int> . self )
158159 }
160+
161+ func testFilterMaintainsSortOrder( ) {
162+ let sut = SortedArray ( unsorted: [ " b " , " a " , " c " , " a " , " d " , " A " ] )
163+ assertElementsEqual ( sut. filter { $0 != " a " } , [ " A " , " b " , " c " , " d " ] )
164+ }
165+
159166}
160167
161168extension SortedArrayTests {
@@ -184,7 +191,8 @@ extension SortedArrayTests {
184191 ( " testMax " , testMax) ,
185192 ( " testCustomStringConvertible " , testCustomStringConvertible) ,
186193 ( " testCustomDebugStringConvertible " , testCustomDebugStringConvertible) ,
187- ( " testFilter " , testFilter) ,
194+ ( " testFilterReturnsSortedArray " , testFilterReturnsSortedArray) ,
195+ ( " testFilterMaintainsSortOrder " , testFilterMaintainsSortOrder) ,
188196 ]
189197 }
190198}
0 commit comments