diff --git a/Sources/Algorithms/Partition.swift b/Sources/Algorithms/Partition.swift index 0454c5d..0bccb3a 100644 --- a/Sources/Algorithms/Partition.swift +++ b/Sources/Algorithms/Partition.swift @@ -61,7 +61,7 @@ extension MutableCollection { by belongsInSecondPartition: (Element) throws-> Bool ) rethrows -> Index { try stablePartition( - count: count, + count: self[subrange].count, subrange: subrange, by: belongsInSecondPartition) } diff --git a/Tests/SwiftAlgorithmsTests/PartitionTests.swift b/Tests/SwiftAlgorithmsTests/PartitionTests.swift index a65bcc3..ad8ba8e 100644 --- a/Tests/SwiftAlgorithmsTests/PartitionTests.swift +++ b/Tests/SwiftAlgorithmsTests/PartitionTests.swift @@ -61,6 +61,21 @@ final class PartitionTests: XCTestCase { } } + func testStablePartitionWithSubrange() { + for length in 10...20 { + let a = Array(0.. 0 ? 1 : 0) + XCTAssertEqualSequences(b[partitionRange.lowerBound..