From d2e82ada53ee7fe6cdd863f1ffb0c28ce7887d2b Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Mon, 19 Sep 2022 17:27:22 -0700 Subject: [PATCH] =?UTF-8?q?[tests]=20checkBidirectionalCollection:=20Don?= =?UTF-8?q?=E2=80=99t=20pointlessly=20repeat=20index(=5F:offsetBy:limitedB?= =?UTF-8?q?y:)=20probe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckBidirectionalCollection.swift | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Sources/_CollectionsTestSupport/ConformanceCheckers/CheckBidirectionalCollection.swift b/Sources/_CollectionsTestSupport/ConformanceCheckers/CheckBidirectionalCollection.swift index 1f752a4e..dffead87 100644 --- a/Sources/_CollectionsTestSupport/ConformanceCheckers/CheckBidirectionalCollection.swift +++ b/Sources/_CollectionsTestSupport/ConformanceCheckers/CheckBidirectionalCollection.swift @@ -148,25 +148,24 @@ public func _checkBidirectionalCollection= limit ? allIndices[j] : nil - expectEqual(actual, expected) - } + } + + // Check `index(_,offsetBy:limitedBy:)` + let limits = + Set([0, allIndices.count - 1, allIndices.count / 2]) + .sorted() + withEvery("limit", in: limits) { limit in + withEvery("i", in: 0 ..< allIndices.count) { i in + let min = -i - (limit <= i ? 2 : 0) + withEvery("delta", in: stride(from: 0, through: min, by: -1)) { delta in + let actual = collection.index( + allIndices[i], + offsetBy: delta, + limitedBy: allIndices[limit]) + let j = i + delta + let expected = i < limit || j >= limit ? allIndices[j] : nil + expectEqual(actual, expected) } } - } }