File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Tests/SwiftAlgorithmsTests Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ extension MutableCollection {
6161 by belongsInSecondPartition: ( Element ) throws -> Bool
6262 ) rethrows -> Index {
6363 try stablePartition (
64- count: count,
64+ count: self [ subrange ] . count,
6565 subrange: subrange,
6666 by: belongsInSecondPartition)
6767 }
Original file line number Diff line number Diff line change @@ -61,6 +61,21 @@ final class PartitionTests: XCTestCase {
6161 }
6262 }
6363
64+ func testStablePartitionWithSubrange( ) {
65+ for length in 10 ... 20 {
66+ let a = Array ( 0 ..< length)
67+ for j in 0 ..< length {
68+ var b = a
69+ let partitionRange = 0 ..< j
70+ let condition = { $0 < j - 1 }
71+ let p = b. stablePartition ( subrange: partitionRange, by: condition)
72+ XCTAssertEqual ( p, partitionRange. count > 0 ? 1 : 0 )
73+ XCTAssertEqualSequences ( b [ partitionRange. lowerBound..< p] , a [ partitionRange] . filter { !condition( $0) } )
74+ XCTAssertEqualSequences ( b [ p..< partitionRange. upperBound] , a [ partitionRange] . filter ( condition) )
75+ }
76+ }
77+ }
78+
6479 func testPartitioningIndex( ) {
6580 for i in 0 ..< 7 {
6681 for j in i..< 11 {
You can’t perform that action at this time.
0 commit comments