Skip to content

Commit d5e8bdf

Browse files
committed
FlattenSequence/distance(from:to:) untrapping Int.min (v4).
1. I removed some command-like comments. 2. I added a test for Int.min and Int.max distances.
1 parent e06f80a commit d5e8bdf

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

test/stdlib/FlattenDistanceFromTo.swift

+32-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
//
1313
// RUN: %target-run-simple-swift(-parse-as-library)
1414
// REQUIRES: executable_test
15-
// REQUIRES: reflection
16-
// UNSUPPORTED: use_os_stdlib
1715
// END.
1816
//
1917
//===----------------------------------------------------------------------===//
@@ -27,6 +25,7 @@ final class FlattenDistanceFromToTests {
2725
let tests = FlattenDistanceFromToTests()
2826
let suite = TestSuite("FlattenDistanceFromToTests")
2927
suite.test("EachIndexPair", tests.testEachIndexPair)
28+
suite.test("MinMaxOutputs", tests.testMinMaxOutputs)
3029
runAllTests()
3130
}
3231
}
@@ -142,3 +141,34 @@ extension FlattenDistanceFromToTests {
142141
expectEqual(invocations, 2502, "unexpected workload")
143142
}
144143
}
144+
145+
//===----------------------------------------------------------------------===//
146+
// MARK: - Min Max Outputs
147+
//===----------------------------------------------------------------------===//
148+
149+
extension FlattenDistanceFromToTests {
150+
151+
/// Checks some `Int.min` and `Int.max` distances.
152+
///
153+
/// - Note: A distance of `Int.min` requires more than `Int.max` elements.
154+
///
155+
func testMinMaxOutputs() {
156+
for s: FlattenSequence in [
157+
158+
[-1..<Int.max/1],
159+
[00..<Int.max/1, 00..<000000001],
160+
[00..<000000001, 01..<Int.max/1, 00..<000000001],
161+
[00..<000000001, 00..<Int.max/2, 00..<Int.max/2, 00..<000000001]
162+
163+
].map({ $0.joined() }) {
164+
165+
let a = s.startIndex, b = s.endIndex
166+
167+
expectEqual(Int.min, s.distance(from: b, to: s.index(a, offsetBy: 00)))
168+
expectEqual(Int.max, s.distance(from: s.index(a, offsetBy: 01), to: b))
169+
170+
expectEqual(Int.min, s.distance(from: s.index(b, offsetBy: 00), to: a))
171+
expectEqual(Int.max, s.distance(from: a, to: s.index(b, offsetBy: -1)))
172+
}
173+
}
174+
}

0 commit comments

Comments
 (0)