Skip to content

Commit f1c4af9

Browse files
committed
Add laziness tests
1 parent fc2f02d commit f1c4af9

File tree

7 files changed

+26
-0
lines changed

7 files changed

+26
-0
lines changed

Tests/SwiftAlgorithmsTests/ChainTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,8 @@ final class ChainTests: XCTestCase {
136136
XCTAssertEqual(chain.distance(from: start, to: end), distance)
137137
}
138138
}
139+
140+
func testChainLazy() {
141+
XCTAssertLazy([1, 2, 3].lazy.chained(with: [4, 5, 6]))
142+
}
139143
}

Tests/SwiftAlgorithmsTests/ChunkedTests.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ final class ChunkedTests: XCTestCase {
7171
let lazyChunks = fruits.lazy.chunked(by: { $0.first == $1.first })
7272
validateFruitChunks(lazyChunks)
7373
}
74+
75+
func testChunkedLazy() {
76+
XCTAssertLazy(fruits.lazy.chunked(by: { $0.first == $1.first }))
77+
XCTAssertLazy(fruits.lazy.chunked(on: { $0.first }))
78+
}
7479
}

Tests/SwiftAlgorithmsTests/CombinationsTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ final class CombinationsTests: XCTestCase {
3838
XCTAssertEqualSequences([], "".combinations(ofCount: 5))
3939
XCTAssertEqualSequences([], "ABCD".combinations(ofCount: 5))
4040
}
41+
42+
func testCombinationsLazy() {
43+
XCTAssertLazy("ABC".lazy.combinations(ofCount: 1))
44+
}
4145
}

Tests/SwiftAlgorithmsTests/CycleTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ final class CycleTests: XCTestCase {
3939
let empty2 = Array("Hello".cycled(times: 0))
4040
XCTAssert(empty2.isEmpty)
4141
}
42+
43+
func testCycleLazy() {
44+
XCTAssertLazy((1...4).lazy.cycled())
45+
}
4246
}

Tests/SwiftAlgorithmsTests/IndexedTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ final class IndexedTests: XCTestCase {
2727
let indexOfI = si.last(where: { $0.element == "I" })!.index
2828
XCTAssertEqual("I", s[indexOfI])
2929
}
30+
31+
func testIndexedLazy() {
32+
XCTAssertLazy("ABCD".lazy.indexed())
33+
}
3034
}

Tests/SwiftAlgorithmsTests/PermutationsTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ final class PermutationsTests: XCTestCase {
6969
while numbers.nextPermutation() {}
7070
XCTAssertEqual([1, 2, 3, 4, 5, 6, 7], numbers)
7171
}
72+
73+
func testPermutationsLazy() {
74+
XCTAssertLazy("ABCD".lazy.permutations(ofCount: 2))
75+
}
7276
}

Tests/SwiftAlgorithmsTests/TestUtilities.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ func XCTAssertEqualSequences<S1: Sequence, S2: Sequence>(
6565
try XCTAssert(expression1().elementsEqual(expression2(), by: areEquivalent), message(), file: file, line: line)
6666
}
6767

68+
func XCTAssertLazy<S: LazySequenceProtocol>(_: S) {}

0 commit comments

Comments
 (0)