Skip to content

Commit 0b9603f

Browse files
markuswntrstephentyrone
authored andcommitted
Update transformation hashing and equality tests
1 parent 0c4d402 commit 0b9603f

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

Tests/QuaternionTests/PropertyTests.swift

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,35 @@ final class PropertyTests: XCTestCase {
102102
}
103103
// Validate that all *normal* values hash their absolute components, so
104104
// that rotations in *R³* of `q` and `-q` will hash to same value.
105-
let pis = [
106-
Quaternion<T>(real: .pi, imaginary: .pi, .pi, .pi),
107-
Quaternion<T>(real: .pi, imaginary: -.pi, .pi, .pi),
108-
Quaternion<T>(real: .pi, imaginary: .pi, -.pi, .pi),
109-
Quaternion<T>(real: .pi, imaginary: .pi, .pi, -.pi),
110-
Quaternion<T>(real: .pi, imaginary: -.pi, -.pi, .pi),
111-
Quaternion<T>(real: .pi, imaginary: -.pi, .pi, -.pi),
112-
Quaternion<T>(real: .pi, imaginary: .pi, -.pi, -.pi),
113-
Quaternion<T>(real: .pi, imaginary: -.pi, -.pi, -.pi),
114-
115-
Quaternion<T>(real: -.pi, imaginary: .pi, .pi, .pi),
116-
Quaternion<T>(real: -.pi, imaginary: -.pi, .pi, .pi),
117-
Quaternion<T>(real: -.pi, imaginary: .pi, -.pi, .pi),
118-
Quaternion<T>(real: -.pi, imaginary: .pi, .pi, -.pi),
119-
Quaternion<T>(real: -.pi, imaginary: -.pi, -.pi, .pi),
120-
Quaternion<T>(real: -.pi, imaginary: -.pi, .pi, -.pi),
121-
Quaternion<T>(real: -.pi, imaginary: .pi, -.pi, -.pi),
122-
Quaternion<T>(real: -.pi, imaginary: -.pi, -.pi, -.pi),
105+
let pairs: [(lhs: Quaternion<T>, rhs: Quaternion<T>)] = [
106+
(
107+
Quaternion<T>(real: .pi, imaginary: .pi, .pi, .pi),
108+
Quaternion<T>(real: -.pi, imaginary: .pi, .pi, .pi)
109+
), (
110+
Quaternion<T>(real: .pi, imaginary: -.pi, .pi, .pi),
111+
Quaternion<T>(real: -.pi, imaginary: -.pi, .pi, .pi)
112+
), (
113+
Quaternion<T>(real: .pi, imaginary: .pi, -.pi, .pi),
114+
Quaternion<T>(real: -.pi, imaginary: .pi, -.pi, .pi)
115+
), (
116+
Quaternion<T>(real: .pi, imaginary: .pi, .pi, -.pi),
117+
Quaternion<T>(real: -.pi, imaginary: .pi, .pi, -.pi)
118+
), (
119+
Quaternion<T>(real: .pi, imaginary: -.pi, -.pi, .pi),
120+
Quaternion<T>(real: -.pi, imaginary: -.pi, -.pi, .pi)
121+
), (
122+
Quaternion<T>(real: .pi, imaginary: -.pi, .pi, -.pi),
123+
Quaternion<T>(real: -.pi, imaginary: -.pi, .pi, -.pi)
124+
), (
125+
Quaternion<T>(real: .pi, imaginary: .pi, -.pi, -.pi),
126+
Quaternion<T>(real: -.pi, imaginary: .pi, -.pi, -.pi)
127+
), (
128+
Quaternion<T>(real: .pi, imaginary: -.pi, -.pi, -.pi),
129+
Quaternion<T>(real: -.pi, imaginary: -.pi, -.pi, -.pi)
130+
)
123131
]
124-
for pi in pis[1...] {
125-
XCTAssertEqual(pis[0].hashValue, pi.hashValue)
132+
for pair in pairs {
133+
XCTAssertEqual(pair.lhs.hashValue, pair.rhs.hashValue)
126134
}
127135
}
128136

@@ -131,21 +139,18 @@ final class PropertyTests: XCTestCase {
131139
testEquatableHashable(Float64.self)
132140
}
133141

134-
func testRotationEquals<T: Real & SIMDScalar>(_ type: T.Type) {
142+
func testTransformationEquals<T: Real & SIMDScalar>(_ type: T.Type) {
135143
let rotations: [(lhs: Quaternion<T>, rhs: Quaternion<T>)] = [
136144
(
137145
Quaternion<T>(real: -.pi, imaginary: -.pi, -.pi, -.pi),
138146
Quaternion<T>(real: .pi, imaginary: .pi, .pi, .pi)
139-
),
140-
(
147+
), (
141148
Quaternion<T>(real: .ulpOfOne, imaginary: .ulpOfOne, .ulpOfOne, .ulpOfOne),
142149
Quaternion<T>(real: -.ulpOfOne, imaginary: -.ulpOfOne, -.ulpOfOne, -.ulpOfOne)
143-
),
144-
(
150+
), (
145151
Quaternion<T>(real: .pi, imaginary: -.pi, .pi, -.pi),
146152
Quaternion<T>(real: -.pi, imaginary: .pi, -.pi, .pi)
147-
),
148-
(
153+
), (
149154
Quaternion<T>(real: -.ulpOfOne, imaginary: -.ulpOfOne, .ulpOfOne, .ulpOfOne),
150155
Quaternion<T>(real: .ulpOfOne, imaginary: .ulpOfOne, -.ulpOfOne, -.ulpOfOne)
151156
),
@@ -154,8 +159,7 @@ final class PropertyTests: XCTestCase {
154159
(
155160
Quaternion<T>.zero,
156161
-Quaternion<T>.zero
157-
),
158-
(
162+
), (
159163
-Quaternion<T>.infinity,
160164
Quaternion<T>.infinity
161165
),
@@ -165,9 +169,9 @@ final class PropertyTests: XCTestCase {
165169
}
166170
}
167171

168-
func testRotationEquals() {
169-
testRotationEquals(Float32.self)
170-
testRotationEquals(Float64.self)
172+
func testTransformationEquals() {
173+
testTransformationEquals(Float32.self)
174+
testTransformationEquals(Float64.self)
171175
}
172176

173177
func testCodable<T: Real & SIMDScalar>(_ type: T.Type) throws {

0 commit comments

Comments
 (0)