mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-23 04:14:22 +00:00
* Rename types to include a Sequence or Collection suffix, and clean up some guides * Various refactors * Replace `validateIndexTraversals` test method with `IndexValidator` type * Add LazySequenceProtocol to StridingSequence, StridingCollection * Update the Numerics dependency to 1.0 * Set `IndexedCollection.Indices` to `Base.Indices` * Remove deprecations * Update the changelog/README for the 1.0.0 release * Fix compiler error on Linux * Rename `WindowsCollection` to `WindowsOfCountCollection`
46 lines
1.3 KiB
Swift
46 lines
1.3 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Algorithms open source project
|
|
//
|
|
// Copyright (c) 2021 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 CompactedTests: XCTestCase {
|
|
|
|
let tests: [[Int?]] =
|
|
[nil, nil, nil, 0, 1, 2]
|
|
.uniquePermutations(ofCount: 0...)
|
|
.map(Array.init)
|
|
|
|
func testCompactedCompacted() {
|
|
for collection in self.tests {
|
|
let seq = AnySequence(collection)
|
|
XCTAssertEqualSequences(
|
|
seq.compactMap({ $0 }), seq.compacted())
|
|
XCTAssertEqualSequences(
|
|
collection.compactMap({ $0 }), collection.compacted())
|
|
}
|
|
}
|
|
|
|
func testCompactedBidirectionalCollection() {
|
|
for array in self.tests {
|
|
XCTAssertEqualSequences(array.compactMap({ $0 }).reversed(),
|
|
array.compacted().reversed())
|
|
}
|
|
}
|
|
|
|
func testCollectionTraversals() {
|
|
let validator = IndexValidator<CompactedCollection<[Int?], Int>>()
|
|
for array in self.tests {
|
|
validator.validate(array.compacted())
|
|
}
|
|
}
|
|
}
|