File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Tests/SwiftAlgorithmsTests Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -168,8 +168,8 @@ extension MutableCollection where Self: BidirectionalCollection {
168168//===----------------------------------------------------------------------===//
169169
170170extension Collection {
171- /// Returns the index of the first element in the collection that matches
172- /// the predicate.
171+ /// Returns the start index of the partition of a collection that matches
172+ /// the given predicate.
173173 ///
174174 /// The collection must already be partitioned according to the predicate.
175175 /// That is, there should be an index `i` where for every element in
@@ -179,7 +179,8 @@ extension Collection {
179179 /// - Parameter belongsInSecondPartition: A predicate that partitions the
180180 /// collection.
181181 /// - Returns: The index of the first element in the collection for which
182- /// `predicate` returns `true`.
182+ /// `predicate` returns `true`, or `endIndex` if there are no elements
183+ /// for which `predicate` returns `true`.
183184 ///
184185 /// - Complexity: O(log *n*), where *n* is the length of this collection if
185186 /// the collection conforms to `RandomAccessCollection`, otherwise O(*n*).
Original file line number Diff line number Diff line change @@ -92,6 +92,26 @@ final class PartitionTests: XCTestCase {
9292 }
9393 }
9494
95+ func testPartitioningIndexWithEmptyInput( ) {
96+ let input : [ Int ] = [ ]
97+
98+ let a = input. partitioningIndex ( where: { _ in return true } )
99+ XCTAssertEqual ( a, input. startIndex)
100+
101+ let b = input. partitioningIndex ( where: { _ in return false } )
102+ XCTAssertEqual ( b, input. endIndex)
103+ }
104+
105+ func testPartitioningIndexWithOneEmptyPartition( ) {
106+ let input : Range < Int > = ( 0 ..< 10 )
107+
108+ let a = input. partitioningIndex ( where: { $0 > 10 } )
109+ XCTAssertEqual ( a, input. endIndex)
110+
111+ let b = input. partitioningIndex ( where: { $0 >= 0 } )
112+ XCTAssertEqual ( b, input. startIndex)
113+ }
114+
95115 func testPartitionWithSubrangeBidirectionalCollection( ) {
96116 for length in 10 ... 20 {
97117 let a = Array ( 0 ..< length)
You can’t perform that action at this time.
0 commit comments