//===----------------------------------------------------------------------===// // // This source file is part of the Swift Algorithms open source project // // Copyright (c) 2020 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // //===----------------------------------------------------------------------===// import XCTest import Algorithms final class PartitionTests: XCTestCase { func testStablePartition() { for l in 0..<13 { let a = Array(0..= k } XCTAssertGreaterThanOrEqual(p, i) XCTAssertLessThanOrEqual(p, j) XCTAssertEqual(p, k) } } } } func testPartitioningIndexWithEmptyInput() { let input: [Int] = [] let a = input.partitioningIndex(where: { _ in return true }) XCTAssertEqual(a, input.startIndex) let b = input.partitioningIndex(where: { _ in return false }) XCTAssertEqual(b, input.endIndex) } func testPartitioningIndexWithOneEmptyPartition() { let input: Range = (0 ..< 10) let a = input.partitioningIndex(where: { $0 > 10 }) XCTAssertEqual(a, input.endIndex) let b = input.partitioningIndex(where: { $0 >= 0 }) XCTAssertEqual(b, input.startIndex) } func testPartitionWithSubrangeBidirectionalCollection() { for length in 10...20 { let a = Array(0..