mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
* [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
24 lines
778 B
Swift
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()
|