File tree 2 files changed +16
-1
lines changed
Tests/SwiftAlgorithmsTests
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ extension MutableCollection {
61
61
by belongsInSecondPartition: ( Element ) throws -> Bool
62
62
) rethrows -> Index {
63
63
try stablePartition (
64
- count: count,
64
+ count: self [ subrange ] . count,
65
65
subrange: subrange,
66
66
by: belongsInSecondPartition)
67
67
}
Original file line number Diff line number Diff line change @@ -61,6 +61,21 @@ final class PartitionTests: XCTestCase {
61
61
}
62
62
}
63
63
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
+
64
79
func testPartitioningIndex( ) {
65
80
for i in 0 ..< 7 {
66
81
for j in i..< 11 {
You can’t perform that action at this time.
0 commit comments