|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift Algorithms open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// |
| 10 | +//===----------------------------------------------------------------------===// |
| 11 | + |
| 12 | +import XCTest |
| 13 | +import Algorithms |
| 14 | + |
| 15 | +final class CompactedTests: XCTestCase { |
| 16 | + |
| 17 | + var tests: [[Int?]] = [ |
| 18 | + [], |
| 19 | + [0], |
| 20 | + [nil], |
| 21 | + [0, nil], |
| 22 | + [nil, 0], |
| 23 | + [0, nil, 1, nil, 2, nil], |
| 24 | + [0, 1, 2, nil, nil, nil], |
| 25 | + [nil, nil, nil, 0, 1, 2], |
| 26 | + [nil, nil, nil, nil, nil, nil] |
| 27 | + ] |
| 28 | + |
| 29 | + func testCompactedSequence() { |
| 30 | + for array in self.tests { |
| 31 | + let seq = AnySequence(array) |
| 32 | + XCTAssertEqualSequences(seq.compactMap({ $0 }), seq.compacted()) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + func testCompactedCollection() { |
| 37 | + for array in self.tests { |
| 38 | + XCTAssertEqualSequences(array.compactMap({ $0 }), array.compacted()) |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + func testCompactedBidirectionalCollection() { |
| 43 | + for array in self.tests { |
| 44 | + XCTAssertEqualSequences(array.compactMap({ $0 }).reversed(), array.compacted().reversed()) |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + func testCollectionTraversals() { |
| 49 | + for array in self.tests { |
| 50 | + validateIndexTraversals(array) |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments