Skip to content

Commit 6aebc1f

Browse files
[CodeReview] Making the corrections
1 parent abe4890 commit 6aebc1f

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

Sources/Algorithms/Compacted.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ extension Collection {
175175
extension CompactedSequence: LazySequenceProtocol
176176
where Base: LazySequenceProtocol {}
177177

178-
extension CompactedCollection: RandomAccessCollection
179-
where Base: RandomAccessCollection {}
180178
extension CompactedCollection: LazySequenceProtocol
181179
where Base: LazySequenceProtocol {}
182180
extension CompactedCollection: LazyCollectionProtocol

Tests/SwiftAlgorithmsTests/CompactedTests.swift

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class CompactedTests: XCTestCase {
3838

3939
func testCollectionTraversals() {
4040
for array in self.tests {
41-
validateIndexTraversals(array)
41+
validateIndexTraversals(array.compacted())
4242
}
4343
}
4444

@@ -55,14 +55,27 @@ final class CompactedTests: XCTestCase {
5555
}
5656

5757
func testCollectionHashableConformances() {
58-
for array in self.tests {
59-
let seq = array.eraseToAnyHashableSequence()
60-
XCTAssertEqualHashValue(
61-
seq.compacted(), seq.compactMap({ $0 }).compacted()
62-
)
63-
XCTAssertEqualHashValue(
64-
array.compacted(), array.compactMap({ $0 }).compacted()
65-
)
58+
for array1 in self.tests {
59+
for array2 in self.tests {
60+
// For non-equal Collections and Sequences that produce the same
61+
// compacted, the compacted wrapper should produce the same hash.
62+
// e.g. [1, 2, 3, nil, nil, 4].compacted() should produce the
63+
// same hash as [1, nil, 2, nil, 3, 4].compacted()
64+
guard !array1.elementsEqual(array2) &&
65+
array1.compacted() == array2.compacted() else {
66+
continue
67+
}
68+
69+
let seq = array1.eraseToAnyHashableSequence()
70+
let seq2 = array2.eraseToAnyHashableSequence()
71+
72+
XCTAssertEqualHashValue(
73+
seq.compacted(), seq2.compacted()
74+
)
75+
XCTAssertEqualHashValue(
76+
array1.compacted(), array2.compacted()
77+
)
78+
}
6679
}
6780
}
6881
}

0 commit comments

Comments
 (0)