Skip to content

Commit 2650afb

Browse files
authored
[stdlib] add simple tests for past-the-end behavior of stride iterators (#3362)
1 parent eb7bd30 commit 2650afb

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/1_stdlib/Strideable.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,33 @@ StrideTestSuite.test("ErrorAccumulation") {
204204
expectEqual(10, b.count)
205205
}
206206

207+
func strideIteratorTest<
208+
Stride : Sequence
209+
>(_ stride: Stride, nonNilResults: Int) {
210+
var i = stride.makeIterator()
211+
for _ in 0..<nonNilResults {
212+
expectNotEmpty(i.next())
213+
}
214+
for _ in 0..<10 {
215+
expectEmpty(i.next())
216+
}
217+
}
218+
219+
StrideTestSuite.test("StrideThroughIterator/past end") {
220+
strideIteratorTest(stride(from: 0, through: 3, by: 1), nonNilResults: 4)
221+
}
222+
223+
StrideTestSuite.test("StrideThroughIterator/past end/backward") {
224+
strideIteratorTest(stride(from: 3, through: 0, by: -1), nonNilResults: 4)
225+
}
226+
227+
StrideTestSuite.test("StrideToIterator/past end") {
228+
strideIteratorTest(stride(from: 0, to: 3, by: 1), nonNilResults: 3)
229+
}
230+
231+
StrideTestSuite.test("StrideToIterator/past end/backward") {
232+
strideIteratorTest(stride(from: 3, to: 0, by: -1), nonNilResults: 3)
233+
}
234+
207235
runAllTests()
208236

0 commit comments

Comments
 (0)