From 973218da0a757bb6ce95411d6123fc96c6947212 Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 17:19:26 -0500 Subject: [PATCH 1/7] Check SortedSet's BidirectionalCollection conformance SortedSet conforms to BidirectionalCollection but was never run through checkBidirectionalCollection. The counts sit on either side of the sizes where a debug-build tree gains a level, and each is checked both bulk-built and built by insertion, since the two give differently shaped trees. Co-Authored-By: Claude Opus 5.5 --- .../SortedSet/SortedSet Tests.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift index 83553e3e..d4a89dbe 100644 --- a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift +++ b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift @@ -64,6 +64,15 @@ class SortedSetTests: CollectionTestCase { } } + func test_BidirectionalCollection() { + withEvery("count", in: [0, 1, 5, 6, 17, 18, 29, 30]) { count in + checkBidirectionalCollection( + SortedSet(sortedElements: 0 ..< count), expectedContents: 0 ..< count) + checkBidirectionalCollection( + SortedSet(0 ..< count), expectedContents: 0 ..< count) + } + } + func test_firstIndexOf_lastIndexOf() { withEvery("count", in: 0 ..< 20) { count in let contents = Array(0 ..< count) From fac3148fe7865ded9e6130550a2186e7847b84d7 Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 17:19:34 -0500 Subject: [PATCH 2/7] Check SortedSet's Equatable and Hashable conformances SortedSet conforms to Hashable but was never run through checkHashable. Multi-level sets are built both in bulk and by insertion, so equal sets with different tree layouts must compare and hash equal. The last two classes match the evens in count and endpoints and differ only past the first leaf. Co-Authored-By: Claude Opus 5.5 --- .../SortedSet/SortedSet Tests.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift index d4a89dbe..b45b8408 100644 --- a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift +++ b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift @@ -262,6 +262,22 @@ class SortedSetTests: CollectionTestCase { } } + func test_Equatable_Hashable() { + let evens = stride(from: 0, to: 42, by: 2) + let classes: [[SortedSet]] = [ + [[]], + [[0]], + [[1]], + [SortedSet(sortedElements: 0 ..< 20), SortedSet(0 ..< 20)], + [SortedSet(sortedElements: 0 ..< 21), SortedSet(0 ..< 21)], + [SortedSet(sortedElements: 1 ..< 21), SortedSet(1 ..< 21)], + [SortedSet(evens)], + [SortedSet(evens.map { $0 == 20 ? 21 : $0 })], + [SortedSet(evens.map { $0 == 38 ? 39 : $0 })], + ] + checkHashable(equivalenceClasses: classes) + } + func test_Encodable() throws { let s1: SortedSet = [] let v1: MinimalEncoder.Value = .array([]) From e4c7f6e3d85b4f40efa8e4a013fa172caaca1e8e Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 23:13:08 -0500 Subject: [PATCH 3/7] Check SortedSet.SubSequence's Equatable and Hashable conformances SortedSet.SubSequence has its own copy of SortedSet's == and hash(into:), and neither was tested. Equal slices are taken from bulk-built and inserted sets, so they start at different leaf offsets; the last two classes match the evens slice in count and endpoints and differ only past the first leaf. Co-Authored-By: Claude Opus 5.5 --- .../SortedSet/SortedSet Tests.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift index b45b8408..beea2acf 100644 --- a/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift +++ b/Tests/SortedCollectionsTests/SortedSet/SortedSet Tests.swift @@ -278,6 +278,22 @@ class SortedSetTests: CollectionTestCase { checkHashable(equivalenceClasses: classes) } + func test_subSequence_Equatable_Hashable() { + let evens = stride(from: 0, to: 80, by: 2) + let classes: [[SortedSet.SubSequence]] = [ + [SortedSet()[0 ..< 10], SortedSet(0 ..< 40)[50 ..< 60]], + [ + SortedSet(sortedElements: 0 ..< 40)[10 ..< 30], + SortedSet(0 ..< 40)[10 ..< 30], + SortedSet(10 ..< 30)[...], + ], + [SortedSet(evens)[20 ..< 60]], + [SortedSet(evens.map { $0 == 40 ? 41 : $0 })[20 ..< 60]], + [SortedSet(evens.map { $0 == 56 ? 57 : $0 })[20 ..< 60]], + ] + checkHashable(equivalenceClasses: classes) + } + func test_Encodable() throws { let s1: SortedSet = [] let v1: MinimalEncoder.Value = .array([]) From a7f70f3c9fb8852f467c028feba580526cdb69ce Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 22:42:13 -0500 Subject: [PATCH 4/7] Check SortedDictionary's Equatable and Hashable conformances SortedDictionary conforms to Hashable but was never run through checkHashable. The multi-level dictionary is built both in bulk and by insertion, so equal dictionaries with different tree layouts must compare and hash equal; the last two classes differ from it in one key or one value past the first leaf. Co-Authored-By: Claude Opus 5.5 --- .../SortedDictionary Tests.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index fc25dddd..fef94ce8 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -285,6 +285,25 @@ final class SortedDictionaryTests: CollectionTestCase { } } + func test_Equatable_Hashable() { + let evens = stride(from: 0, to: 42, by: 2).map { ($0, $0 / 2) } + let keyChanged = evens.map { key, value in (key == 20 ? 21 : key, value) } + let valueChanged = evens.map { key, value in (key, key == 20 ? -1 : value) } + let classes: [[SortedDictionary]] = [ + [[:]], + [[0: 0]], + [[0: 1]], + [[1: 0]], + [ + SortedDictionary(sortedKeysWithValues: evens), + SortedDictionary(keysWithValues: evens), + ], + [SortedDictionary(sortedKeysWithValues: keyChanged)], + [SortedDictionary(sortedKeysWithValues: valueChanged)], + ] + checkHashable(equivalenceClasses: classes) + } + func test_keys_Equatable() { let left: SortedDictionary = [ 1: "one", From a091324030d6c04e49f94e5a3aaaf2807ea3f36c Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 22:42:41 -0500 Subject: [PATCH 5/7] Check SortedDictionary.Keys's Hashable conformance test_keys_Equatable only ran checkEquatable over single-leaf dictionaries. Run checkHashable instead, and add a multi-level class built in bulk and by insertion with different values, plus one that differs in a single key past the first leaf. Co-Authored-By: Claude Opus 5.5 --- .../SortedDictionary/SortedDictionary Tests.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index fef94ce8..97fe9cbd 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -304,7 +304,7 @@ final class SortedDictionaryTests: CollectionTestCase { checkHashable(equivalenceClasses: classes) } - func test_keys_Equatable() { + func test_keys_Equatable_Hashable() { let left: SortedDictionary = [ 1: "one", 2: "two", @@ -325,10 +325,18 @@ final class SortedDictionaryTests: CollectionTestCase { expectEqual(left.keys, rightEqual.keys) expectNotEqual(left.keys, rightUnequal.keys) - checkEquatable(equivalenceClasses: [ + let evens = stride(from: 0, to: 42, by: 2).map { ($0, "\($0)") } + let keyChanged = evens.map { key, value in (key == 20 ? 21 : key, value) } + + checkHashable(equivalenceClasses: [ [SortedDictionary().keys, SortedDictionary().keys], [left.keys, rightEqual.keys], [rightUnequal.keys], + [ + SortedDictionary(sortedKeysWithValues: evens).keys, + SortedDictionary(keysWithValues: evens.map { key, _ in (key, "") }).keys, + ], + [SortedDictionary(sortedKeysWithValues: keyChanged).keys], ]) } From 7237739c6b0211917dee075361f83c6ee601ef72 Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 22:43:21 -0500 Subject: [PATCH 6/7] Check SortedDictionary.Values's Hashable conformance test_values_Equatable only ran checkEquatable over single-leaf dictionaries. Run checkHashable instead, and add a multi-level class built in bulk and by insertion with different keys but the same values, plus one that differs in a single value past the first leaf. Co-Authored-By: Claude Opus 5.5 --- .../SortedDictionary/SortedDictionary Tests.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index 97fe9cbd..4a84b2ee 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -340,7 +340,7 @@ final class SortedDictionaryTests: CollectionTestCase { ]) } - func test_values_Equatable() { + func test_values_Equatable_Hashable() { let left: SortedDictionary = [ 1: "one", 2: "two", @@ -361,10 +361,18 @@ final class SortedDictionaryTests: CollectionTestCase { expectEqual(left.values, rightEqual.values) expectNotEqual(left.values, rightUnequal.values) - checkEquatable(equivalenceClasses: [ + let evens = stride(from: 0, to: 42, by: 2).map { ($0, "\($0)") } + let valueChanged = evens.map { key, value in (key, key == 20 ? "" : value) } + + checkHashable(equivalenceClasses: [ [SortedDictionary().values, SortedDictionary().values], [left.values, rightEqual.values], [rightUnequal.values], + [ + SortedDictionary(sortedKeysWithValues: evens).values, + SortedDictionary(keysWithValues: evens.map { key, value in (key + 1, value) }).values, + ], + [SortedDictionary(sortedKeysWithValues: valueChanged).values], ]) } From 92a1f6184e5eae37e59b299890007b3a3a64cf7a Mon Sep 17 00:00:00 2001 From: Joseph Cursio Date: Sat, 26 Sep 2026 23:13:08 -0500 Subject: [PATCH 7/7] Check SortedDictionary.SubSequence's Hashable conformance test_subSequence_Equatable only compared three single-leaf slices with expectEqual and expectNotEqual. Also run checkHashable, adding empty slices, equal slices cut from bulk-built and inserted dictionaries, and ones that differ from them only in a value or only in their keys. Co-Authored-By: Claude Opus 5.5 --- .../SortedDictionary Tests.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift index 4a84b2ee..588b0f69 100644 --- a/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift +++ b/Tests/SortedCollectionsTests/SortedDictionary/SortedDictionary Tests.swift @@ -376,7 +376,7 @@ final class SortedDictionaryTests: CollectionTestCase { ]) } - func test_subSequence_Equatable() { + func test_subSequence_Equatable_Hashable() { let left: SortedDictionary = [ 1: "one", 2: "two", @@ -409,6 +409,28 @@ final class SortedDictionaryTests: CollectionTestCase { expectEqual(leftSlice, leftSlice) expectEqual(leftSlice, rightEqualSlice) expectNotEqual(leftSlice, rightUnequalSlice) + + let pairs = (0 ..< 40).map { ($0, "\($0)") } + let bulk = SortedDictionary(sortedKeysWithValues: pairs) + let inserted = SortedDictionary(keysWithValues: pairs) + let valueChanged = SortedDictionary( + sortedKeysWithValues: pairs.map { key, value in (key, key == 20 ? "" : value) }) + let keysShifted = SortedDictionary( + sortedKeysWithValues: pairs.map { key, value in (key + 1, value) }) + + let classes: [[SortedDictionary.SubSequence]] = [ + [left.prefix(0), SortedDictionary()[...]], + [leftSlice, rightEqualSlice], + [rightUnequalSlice], + [ + bulk.dropFirst(10).prefix(20), + inserted.dropFirst(10).prefix(20), + SortedDictionary(sortedKeysWithValues: pairs[10 ..< 30])[...], + ], + [valueChanged.dropFirst(10).prefix(20)], + [keysShifted.dropFirst(10).prefix(20)], + ] + checkHashable(equivalenceClasses: classes) } }