Files
swift-mirror/validation-test/stdlib/Stride.swift
Xiaodi Wu 4c7059f59a [stdlib][SR-13883] Avoid advancing past representable bounds when striding (#34860)
* [stdlib][SR-13883] Avoid advancing past representable bounds when striding.

* [stdlib] Expand a test and add a comment to ensure correct floating-point stride bounds checking.

* [stdlib][NFC] Clarify a comment in a test.

* [stdlib][NFC] Adjust copyright notices, clarify comments, delete '-swift-version=3' for tests.

* [stdlib] Add implementations for fixed-width integer strides for performance.

* [stdlib] Document `Strideable._step` and modify overflow checking behavior of `Stride*Iterator`.

* [stdlib] Address reviewer comments, postpone documentation changes

* [stdlib][NFC] Update documentation for '_step(after:from:by:)'

* [stdlib][NFC] Use 'nil' instead of an arbitrary value for integer striding '_step' index
2021-03-11 08:18:28 -05:00

24 lines
778 B
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
import StdlibCollectionUnittest
var StrideTestSuite = TestSuite("Stride")
StrideTestSuite.test("to") {
checkSequence(Array(0...4), stride(from: 0, to: 5, by: 1))
checkSequence(Array(1...5).reversed(), stride(from: 5, to: 0, by: -1))
checkSequence(stride(from: 0, to: 127, by: 3).map { Int8($0) },
stride(from: 0, to: 127 as Int8, by: 3))
}
StrideTestSuite.test("through") {
checkSequence(Array(0...5), stride(from: 0, through: 5, by: 1))
checkSequence(Array(0...5).reversed(), stride(from: 5, through: 0, by: -1))
checkSequence(stride(from: 0, through: 127, by: 3).map { Int8($0) },
stride(from: 0, through: 127 as Int8, by: 3))
}
runAllTests()