Skip to content

Commit 39a3a1f

Browse files
committed
Eliminate boilerplate from stdlib tests
1 parent 30509f1 commit 39a3a1f

File tree

5 files changed

+17
-61
lines changed

5 files changed

+17
-61
lines changed

Diff for: test/Interpreter/SDK/CoreGraphics_CGFloat.swift

+5-30
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,12 @@ CGFloatTestSuite.test("initOtherTypesFromCGFloat") {
5454
}
5555

5656
CGFloatTestSuite.test("comparisons") {
57-
let x = 3.14
58-
let y = 3.14
59-
let z = 2.71
60-
61-
expectTrue(x == y)
62-
expectFalse(x != y)
63-
checkHashable(true, x, y)
64-
65-
expectFalse(x == z)
66-
expectTrue(x != z)
67-
checkHashable(false, x, z)
68-
69-
expectFalse(x < z)
70-
expectFalse(x <= z)
71-
expectTrue(x >= z)
72-
expectTrue(x > z)
73-
checkComparable(.gt, x, z)
74-
75-
expectTrue(z < x)
76-
expectTrue(z <= x)
77-
expectFalse(z >= x)
78-
expectFalse(z > x)
79-
checkComparable(.lt, z, x)
80-
81-
expectFalse(x < y)
82-
expectTrue(x <= y)
83-
expectTrue(x >= y)
84-
expectFalse(x > y)
85-
checkComparable(.eq, x, y)
86-
}
57+
let instances: [CGFloat] = [ 2.71, 3.14 ]
58+
59+
checkHashable(instances, equalityOracle: { $0 == $1 })
8760

61+
checkComparable(instances, oracle: { $0 <=> $1 })
62+
}
8863

8964
CGFloatTestSuite.test("arithmetic") {
9065
let x: CGFloat = 0.25

Diff for: test/stdlib/Character.swift

+1-7
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,7 @@ CharacterTests.test("Hashable") {
154154
continuingScalars.map { String($0) },
155155
testCharacters
156156
] {
157-
for i in characters.indices {
158-
for j in characters.indices {
159-
var ci = Character(characters[i])
160-
var cj = Character(characters[j])
161-
checkHashable(i == j, ci, cj, "i=\(i), j=\(j)")
162-
}
163-
}
157+
checkHashable(characters, equalityOracle: { $0 == $1 })
164158
}
165159
}
166160

Diff for: test/stdlib/UnsafePointer.swift.gyb

+1-7
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,7 @@ ${SelfName}TestSuite.test("Hashable") {
141141
${SelfType}(bitPattern: 0x12345678)!,
142142
${SelfType}(bitPattern: 0x87654321 as UInt)!,
143143
]
144-
for i in ptrs.indices {
145-
for j in ptrs.indices {
146-
var pi = ptrs[i]
147-
var pj = ptrs[j]
148-
checkHashable(i == j, pi, pj, "i=\(i), j=\(j)")
149-
}
150-
}
144+
checkHashable(ptrs, equalityOracle: { $0 == $1 })
151145
}
152146

153147
${SelfName}TestSuite.test("toInteger") {

Diff for: validation-test/stdlib/ObjectiveC.swift

+8-14
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,15 @@ class NSObjectWithCustomHashable : NSObject {
2929
}
3030

3131
ObjectiveCTests.test("NSObject/Hashable") {
32-
let objects = [
33-
NSObjectWithCustomHashable(value: 10, hashValue: 100),
34-
NSObjectWithCustomHashable(value: 10, hashValue: 100),
35-
NSObjectWithCustomHashable(value: 20, hashValue: 100),
36-
NSObjectWithCustomHashable(value: 30, hashValue: 300),
32+
let instances: [(order: Int, object: NSObject)] = [
33+
(10, NSObjectWithCustomHashable(value: 10, hashValue: 100)),
34+
(10, NSObjectWithCustomHashable(value: 10, hashValue: 100)),
35+
(20, NSObjectWithCustomHashable(value: 20, hashValue: 100)),
36+
(30, NSObjectWithCustomHashable(value: 30, hashValue: 300)),
3737
]
38-
for (i, object1) in objects.enumerated() {
39-
for (j, object2) in objects.enumerated() {
40-
checkHashable(
41-
object1._value == object2._value,
42-
object1,
43-
object2,
44-
"i=\(i), j=\(j)")
45-
}
46-
}
38+
checkHashable(
39+
instances.map { $0.object },
40+
equalityOracle: { instances[$0].order == instances[$1].order })
4741
}
4842

4943
runAllTests()

Diff for: validation-test/stdlib/Set.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -3727,14 +3727,13 @@ SetTestSuite.test("misc") {
37273727
SetTestSuite.test("Hashable") {
37283728
let s1 = Set([1010])
37293729
let s2 = Set([2020])
3730-
checkHashable(s1 == s2, s1, s2)
3730+
checkHashable([s1, s2], equalityOracle: { $0 == $1 })
37313731

37323732
// Explicit types help the type checker quite a bit.
37333733
let ss1 = Set([Set([1010] as [Int]), Set([2020] as [Int]), Set([3030] as [Int])])
37343734
let ss11 = Set([Set([2020] as [Int]), Set([3030] as [Int]), Set([2020] as [Int])])
37353735
let ss2 = Set([Set([9090] as [Int])])
3736-
checkHashable(ss1 == ss11, ss1, ss11)
3737-
checkHashable(ss1 == ss2, ss1, ss2)
3736+
checkHashable([ss1, ss11, ss2], equalityOracle: { $0 == $1 })
37383737
}
37393738

37403739
SetTestSuite.test("Operator.Precedence") {

0 commit comments

Comments
 (0)