mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
- withEveryDeque/withEveryFullDeque now visit capacity 0. - checkEquatable reports transitivity violations instead of trapping when pairs arrive out of order (non-transitive oracles, maxSamples). - Minimal range-replaceable collections no longer trap in removeLast() and popLast(). - LifetimeTracked's "Double deinit" precondition can now fire. - withEvery, withEveryRange and withSomeArrayLayouts include the failing value in their "Throwing trace". - CustomCountedProducer drops its unused chunkSize parameter, and the two loops that reran identical cases over it are removed. Adds regression tests for the first three. Fixes #810
64 lines
2.1 KiB
Swift
64 lines
2.1 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2022 - 2026 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
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import XCTest
|
|
#if !COLLECTIONS_SINGLE_MODULE
|
|
import _CollectionsTestSupport
|
|
#endif
|
|
|
|
class CombinatoricsTests: CollectionTestCase {
|
|
func testEverySubset_smoke() {
|
|
func collectSubsets(of set: [Int]) -> Set<[Int]> {
|
|
var result: Set<[Int]> = []
|
|
withEverySubset("subset", of: set) { subset in
|
|
let r = result.insert(subset)
|
|
expectTrue(r.inserted)
|
|
}
|
|
return result
|
|
}
|
|
|
|
expectEqual(collectSubsets(of: []), [[]])
|
|
expectEqual(collectSubsets(of: [0]), [[], [0]])
|
|
expectEqual(collectSubsets(of: [0, 1]), [[], [0], [1], [0, 1]])
|
|
expectEqual(
|
|
collectSubsets(of: [0, 1, 2]),
|
|
[[], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2]])
|
|
}
|
|
|
|
func testEveryPermutation_smoke() {
|
|
func collectPermutations(of items: [Int]) -> Set<[Int]> {
|
|
var result: Set<[Int]> = []
|
|
withEveryPermutation("permutation", of: items) { permutation in
|
|
let r = result.insert(permutation)
|
|
expectTrue(r.inserted)
|
|
}
|
|
return result
|
|
}
|
|
|
|
expectEqual(collectPermutations(of: []), [[]])
|
|
expectEqual(collectPermutations(of: [0]), [[0]])
|
|
expectEqual(collectPermutations(of: [0, 1]), [[0, 1], [1, 0]])
|
|
expectEqual(
|
|
collectPermutations(of: [0, 1, 2]),
|
|
[[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]])
|
|
}
|
|
|
|
func testEveryDeque_capacityZero() {
|
|
var layouts: [DequeLayout] = []
|
|
withEveryDeque("layout", ofCapacities: [0]) { layouts.append($0) }
|
|
withEveryFullDeque("layout", ofCapacities: [0]) { layouts.append($0) }
|
|
let empty = DequeLayout(capacity: 0, startSlot: 0, count: 0)
|
|
expectEqual(layouts, [empty, empty])
|
|
}
|
|
}
|