@@ -84,6 +84,13 @@ PMQuaternionTest >> testDividePolynomial [
84
84
self assert: ((poly / q12) coefficients allSatisfy: [ :ea | ea = 1 ])
85
85
]
86
86
87
+ { #category : #running }
88
+ PMQuaternionTest >> testDivision [
89
+ self assert: (0 / q1234) isZero.
90
+ self assert: 1 / q1234 equals: q1234 reciprocal.
91
+ self assert: q1234 / q1234 equals: 1
92
+ ]
93
+
87
94
{ #category : #running }
88
95
PMQuaternionTest >> testEquality [
89
96
self assert: q1234 equals: q1234 copy.
@@ -153,6 +160,103 @@ PMQuaternionTest >> testLog [
153
160
self assert: (qln qk closeTo: qlg10ln qk)
154
161
]
155
162
163
+ { #category : #' testing - arithmetic' }
164
+ PMQuaternionTest >> testMultiplicationByComplexNumberIsNonCommutative [
165
+ | quaternion complexNumber |
166
+ quaternion := 2 + 3 i + 4 j + 5 k.
167
+ complexNumber := 1 - 1 i.
168
+
169
+ self assert: (quaternion * complexNumber) equals: 5 + 1 i - 1 j + 9 k.
170
+ self assert: (complexNumber * quaternion) equals: 5 + 1 i + 9 j + 1 k.
171
+ ]
172
+
173
+ { #category : #' testing - arithmetic' }
174
+ PMQuaternionTest >> testMultiplicationByConjugate [
175
+
176
+ | quaternion |
177
+ quaternion := 1 + 2 i + 3 j + 4 k.
178
+ self assert: quaternion * (quaternion conjugated) equals: 30
179
+ ]
180
+
181
+ { #category : #' testing - arithmetic' }
182
+ PMQuaternionTest >> testMultiplicationByIntegersIsCommutative [
183
+
184
+ | quaternion |
185
+ quaternion := 1 + 2 i + 3 j + 4 k.
186
+
187
+ self assert: quaternion * 5 equals: 5 + 10 i + 15 j + 20 k.
188
+ self assert: 5 * quaternion equals: 5 + 10 i + 15 j + 20 k.
189
+ ]
190
+
191
+ { #category : #' testing - arithmetic' }
192
+ PMQuaternionTest >> testMultiplicationByPolynomialIsCommutative [
193
+
194
+ | poly quaternion |
195
+ poly := PMPolynomial coefficients: #( 1 1 1 ) .
196
+ quaternion := 1 + 2 i + 0 j + 0 k.
197
+ self assert: (poly * quaternion at: 0 ) equals: q12.
198
+ self assert: (quaternion * poly at: 0 ) equals: q12
199
+ ]
200
+
201
+ { #category : #tests }
202
+ PMQuaternionTest >> testMultiplicationByTheBasisElements [
203
+
204
+ | quaternion |
205
+ quaternion := 1 + 2 i + 3 j + 4 k.
206
+
207
+ self assert: quaternion * 1 i equals: (- 2 + 1 i + 4 j - 3 k).
208
+ self assert: quaternion * 1 j equals: (- 3 - 4 i + 1 j + 2 k).
209
+ self assert: quaternion * 1 k equals: (- 4 + 3 i - 2 j + 1 k)
210
+ ]
211
+
212
+ { #category : #' testing - arithmetic' }
213
+ PMQuaternionTest >> testMultiplicationByVectorIsCommutative [
214
+ | vec quaternion |
215
+ vec := PMVector new : 2 .
216
+ vec at: 1 put: 1 .
217
+ vec at: 2 put: 2 .
218
+ quaternion := 1 + 2 i + 3 j + 4 k.
219
+ " This uses productWithVector"
220
+ self assert: (vec * quaternion at: 1 ) equals: (1 + 2 i + 3 j + 4 k).
221
+ self assert: (vec * quaternion at: 2 ) equals: (2 + 4 i + 6 j + 8 k).
222
+
223
+ " This uses adaptToQuaternion:andSend:"
224
+ self assert: (quaternion * vec at: 1 ) equals: 1 + 2 i + 3 j + 4 k.
225
+ self assert: (quaternion * vec at: 2 ) equals: 2 + 4 i + 6 j + 8 k.
226
+ ]
227
+
228
+ { #category : #' testing - arithmetic' }
229
+ PMQuaternionTest >> testMultiplicationByZero [
230
+ | quaternion |
231
+ quaternion := 1 + 2 i + 3 j + 4 k.
232
+
233
+ self assert: quaternion * 0 equals: 0 + 0 i + 0 j + 0 k.
234
+ ]
235
+
236
+ { #category : #' testing - arithmetic' }
237
+ PMQuaternionTest >> testMultiplicationOfBasisElements [
238
+ " https://en.wikipedia.org/wiki/Quaternion#Multiplication_of_basis_elements"
239
+
240
+ self assert: 1 i * 1 i equals: - 1 .
241
+ self assert: 1 j * 1 j equals: - 1 .
242
+ self assert: 1 k * 1 k equals: - 1 .
243
+ self assert: 1 i * 1 j equals: 1 k.
244
+ self assert: 1 j * 1 k equals: 1 i.
245
+ self assert: 1 k * 1 i equals: 1 j.
246
+ self assert: 1 j * 1 i equals: - 1 k.
247
+ self assert: 1 k * 1 j equals: - 1 i.
248
+ self assert: 1 i * 1 k equals: - 1 j.
249
+ self assert: 1 i i equals: - 1 .
250
+ self assert: 1 j j equals: - 1 .
251
+ self assert: 1 k k equals: - 1 .
252
+ self assert: 1 i j equals: 1 k.
253
+ self assert: 1 j k equals: 1 i.
254
+ self assert: 1 k i equals: 1 j.
255
+ self assert: 1 j i equals: - 1 k.
256
+ self assert: 1 k j equals: - 1 i.
257
+ self assert: 1 i k equals: - 1 j.
258
+ ]
259
+
156
260
{ #category : #running }
157
261
PMQuaternionTest >> testNaturalLogOfQuaternion [
158
262
@@ -227,51 +331,6 @@ PMQuaternionTest >> testPrintOn [
227
331
self assert: s equals: ' (1 i: 2 j: 3 k: 4)'
228
332
]
229
333
230
- { #category : #running }
231
- PMQuaternionTest >> testProduct [
232
- self assert: q1234 * 5 equals: (5 i: 10 j: 15 k: 20 ).
233
- self assert: 5 * q1234 equals: (5 i: 10 j: 15 k: 20 ).
234
- self assert: 1 i * 1 i equals: - 1 .
235
- self assert: 1 j * 1 j equals: - 1 .
236
- self assert: 1 k * 1 k equals: - 1 .
237
- self assert: 1 i * 1 j equals: 1 k.
238
- self assert: 1 j * 1 k equals: 1 i.
239
- self assert: 1 k * 1 i equals: 1 j.
240
- self assert: 1 j * 1 i equals: - 1 k.
241
- self assert: 1 k * 1 j equals: - 1 i.
242
- self assert: 1 i * 1 k equals: - 1 j.
243
- self assert: 1 i i equals: - 1 .
244
- self assert: 1 j j equals: - 1 .
245
- self assert: 1 k k equals: - 1 .
246
- self assert: 1 i j equals: 1 k.
247
- self assert: 1 j k equals: 1 i.
248
- self assert: 1 k i equals: 1 j.
249
- self assert: 1 j i equals: - 1 k.
250
- self assert: 1 k j equals: - 1 i.
251
- self assert: 1 i k equals: - 1 j.
252
- self assert: q1234 * 1 i equals: q1234 i.
253
- self assert: q1234 * 1 j equals: q1234 j.
254
- self assert: q1234 * 1 k equals: q1234 k.
255
- self assert: (q1234 * 0 ) isZero.
256
- self assert: (0 / q1234) isZero.
257
- self assert: q1234 * q1234 conjugated equals: q1234 squaredNorm.
258
- self assert: 1 / q1234 equals: q1234 reciprocal.
259
- self assert: q1234 / q1234 equals: 1
260
- ]
261
-
262
- { #category : #running }
263
- PMQuaternionTest >> testProductWithVector [
264
- | vec |
265
- vec := PMVector new : 2 .
266
- vec at: 1 put: 1 .
267
- vec at: 2 put: 2 .
268
- " This uses productWithVector"
269
- self assert: (vec * q1234 at: 2 ) equals: 2 * q1234.
270
-
271
- " This uses adaptToQuaternion:andSend:"
272
- self assert: (q1234 * vec at: 1 ) equals: q1234
273
- ]
274
-
275
334
{ #category : #running }
276
335
PMQuaternionTest >> testRaisedTo [
277
336
| eps |
@@ -363,14 +422,6 @@ PMQuaternionTest >> testTanh [
363
422
self assert: ((1 + 2 i) tanh - (1 + 2 j k) tanh) abs < eps
364
423
]
365
424
366
- { #category : #running }
367
- PMQuaternionTest >> testTimesPolynomial [
368
- | poly |
369
- poly := PMPolynomial coefficients: #(1 1 1) .
370
- self assert: (poly * q12 at: 0 ) equals: q12.
371
- self assert: (q12 * poly at: 0 ) equals: q12
372
- ]
373
-
374
425
{ #category : #running }
375
426
PMQuaternionTest >> testUnreal [
376
427
self assert: q1234 unreal real equals: 0 .
0 commit comments