[OrderedCollections] Check the remaining Hashable conformances (#792)

* Check OrderedSet.UnorderedView with checkHashable

The equivalence classes hold permutations of the same members, sets
that differ by one member or by count, and sets on both sides of the
hash table threshold, including small sets that carry a hash table or
reserved capacity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check OrderedSet.SubSequence with checkHashable

The equivalence classes hold equal slices taken from different base
sets, at different offsets, and from bases with and without a hash
table, alongside slices that differ in order, members or count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check OrderedDictionary.Values with checkHashable

The equivalence classes hold dictionaries with different keys but the
same value sequence, alongside values that differ in order, contents
or count, including repeated values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Joseph CursioandClaude Opus 5.5 authored and GitHub committed 2026-10-22 11:03:17 -07:00
1 parent 0b51424337
commit a8a70a3495
3 files changed
+53

No files matched your search

@@ -74,6 +74,22 @@ class OrderedDictionaryValueTests: CollectionTestCase {
expectEqual(d.values.debugDescription, "[1, 2]")
}
func test_Equatable_Hashable() {
let samples: [[OrderedDictionary<Int, Int>]] = [
[[:], OrderedDictionary(minimumCapacity: 100, persistent: true)],
[[1: 100], [2: 100], [100: 100]],
[[100: 1], [1: 1]],
[[1: 100, 2: 200], [2: 100, 1: 200], [3: 100, 4: 200]],
[[2: 200, 1: 100], [1: 200, 2: 100]],
[[1: 100, 2: 100], [3: 100, 4: 100]],
[[1: 100, 2: 200, 3: 300], [3: 100, 2: 200, 1: 300]],
[OrderedDictionary(uniqueKeys: 0 ..< 20, values: 100 ..< 120),
OrderedDictionary(uniqueKeys: 20 ..< 40, values: 100 ..< 120)],
[OrderedDictionary(uniqueKeys: 0 ..< 20, values: 101 ..< 121)],
]
checkHashable(equivalenceClasses: samples.map { $0.map { $0.values }})
}
func test_values_RandomAccessCollection() {
withEvery("count", in: 0 ..< 30) { count in
let keys = 0 ..< count
@@ -23,6 +23,23 @@ import _CollectionsTestSupport
// extension OrderedSet.UnorderedView: SetAPIChecker {}
class OrderedSetUnorderedViewTests: CollectionTestCase {
func test_Equatable_Hashable() {
let samples: [[OrderedSet<Int>]] = [
[[], OrderedSet(minimumCapacity: 100, persistent: true)],
[[1], OrderedSet(_scale: 5, bias: 7, contents: [1])],
[[2], [2]],
[[1, 2], [2, 1]],
[[1, 2, 3], [3, 1, 2],
OrderedSet(_scale: 5, bias: 3, contents: [2, 3, 1])],
[[1, 2, 4], [4, 2, 1]],
[OrderedSet(0 ..< 15),
OrderedSet(_scale: 5, bias: 0, contents: (0 ..< 15).reversed())],
[OrderedSet(0 ..< 16), OrderedSet((0 ..< 16).reversed())],
[OrderedSet(1 ..< 17), OrderedSet((1 ..< 17).reversed())],
]
checkHashable(equivalenceClasses: samples.map { $0.map { $0.unordered }})
}
func test_unordered_insert() {
withEvery("count", in: 0 ..< 20) { count in
withEvery("dupes", in: 1 ... 3) { dupes in
@@ -1688,6 +1688,26 @@ class OrderedSetTests: CollectionTestCase {
}
}
func test_subsequence_Equatable_Hashable() {
let a: OrderedSet = [0, 1, 2, 3]
let b: OrderedSet = [1, 2]
let c: OrderedSet = [3, 2, 1, 0]
let d = OrderedSet(0 ..< 20)
let samples: [[OrderedSet<Int>.SubSequence]] = [
[a[0 ..< 0], a[4 ..< 4], b[1 ..< 1], d[10 ..< 10]],
[a[1 ..< 2], b[0 ..< 1], c[2 ..< 3], d[1 ..< 2]],
[a[2 ..< 3], b[1 ..< 2], c[1 ..< 2], d[2 ..< 3]],
[a[1 ..< 3], b[0 ..< 2], d[1 ..< 3]],
[c[1 ..< 3]],
[a[1 ..< 4], d[1 ..< 4]],
[a[0 ..< 4], d[0 ..< 4]],
[c[0 ..< 4]],
[d[0 ..< 20], OrderedSet(0 ..< 20)[0 ..< 20]],
[d[4 ..< 20], OrderedSet(4 ..< 20)[0 ..< 16]],
]
checkHashable(equivalenceClasses: samples)
}
func test_move_empty() {
withOrderedSetLayouts(scales: [0, 5, 6]) { layout in
var set = OrderedSet(layout: layout)