Skip to content

Commit 720153a

Browse files
authored
Merge pull request #20710 from lorentey/validate-validation
[test] Extend Set, Dictionary test suite
2 parents 5ade8dd + 5e53e5b commit 720153a

File tree

3 files changed

+860
-96
lines changed

3 files changed

+860
-96
lines changed

test/stdlib/Inputs/DictionaryKeyValueTypes.swift

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ struct TestValueCOWTy {
5454
var _keyCount = _stdlib_AtomicInt(0)
5555
var _keySerial = _stdlib_AtomicInt(0)
5656

57-
// A wrapper class that can help us track allocations and find issues with
58-
// object lifetime.
59-
final class TestKeyTy
60-
: Equatable, Hashable, CustomStringConvertible, ExpressibleByIntegerLiteral
61-
{
57+
class _BaseKeyTy: CustomStringConvertible {
58+
final var value: Int
59+
final var serial: Int
60+
6261
class var objectCount: Int {
6362
get {
6463
return _keyCount.load()
@@ -70,18 +69,8 @@ final class TestKeyTy
7069

7170
init(_ value: Int) {
7271
_keyCount.fetchAndAdd(1)
73-
serial = _keySerial.addAndFetch(1)
72+
self.serial = _keySerial.addAndFetch(1)
7473
self.value = value
75-
self._hashValue = value
76-
}
77-
78-
convenience init(integerLiteral value: Int) {
79-
self.init(value)
80-
}
81-
82-
convenience init(value: Int, hashValue: Int) {
83-
self.init(value)
84-
self._hashValue = hashValue
8574
}
8675

8776
deinit {
@@ -94,18 +83,60 @@ final class TestKeyTy
9483
assert(serial > 0, "dead TestKeyTy")
9584
return value.description
9685
}
86+
}
87+
88+
// A wrapper class that can help us track allocations and find issues with
89+
// object lifetime.
90+
final class TestKeyTy
91+
: _BaseKeyTy, Equatable, Hashable, ExpressibleByIntegerLiteral
92+
{
93+
override init(_ value: Int) {
94+
super.init(value)
95+
}
96+
97+
convenience init(integerLiteral value: Int) {
98+
self.init(value)
99+
}
100+
101+
func hash(into hasher: inout Hasher) {
102+
hasher.combine(value)
103+
}
97104

98105
var hashValue: Int {
99-
return _hashValue
106+
return value
100107
}
101108

102-
var value: Int
103-
var _hashValue: Int
104-
var serial: Int
109+
static func ==(lhs: TestKeyTy, rhs: TestKeyTy) -> Bool {
110+
return lhs.value == rhs.value
111+
}
105112
}
106113

107-
func == (lhs: TestKeyTy, rhs: TestKeyTy) -> Bool {
108-
return lhs.value == rhs.value
114+
// A variant of TestKeyTy with precise control over hashing.
115+
// This is useful for bucket-level tests.
116+
final class RawTestKeyTy: _BaseKeyTy, Equatable, Hashable
117+
{
118+
var _hash: Int
119+
120+
init(value: Int, hashValue: Int) {
121+
self._hash = hashValue
122+
super.init(value)
123+
}
124+
125+
var hashValue: Int {
126+
return _hash
127+
}
128+
129+
func hash(into hasher: inout Hasher) {
130+
hasher.combine(_hash)
131+
}
132+
133+
func _rawHashValue(seed: Int) -> Int {
134+
return _hash
135+
}
136+
137+
static func ==(lhs: RawTestKeyTy, rhs: RawTestKeyTy) -> Bool {
138+
return lhs.value == rhs.value
139+
}
109140
}
110141

111142
var _valueCount = _stdlib_AtomicInt(0)

0 commit comments

Comments
 (0)