Skip to content

Commit d105ffc

Browse files
Refactor complex number tests (#268)
1 parent d185377 commit d105ffc

File tree

1 file changed

+49
-60
lines changed

1 file changed

+49
-60
lines changed

src/Math-Tests-Complex/PMComplexTest.class.st

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,32 @@ PMComplexTest >> testAbsSecure [
3333
self assert: (c absSecure closeTo: 72 sqrt)
3434
]
3535

36-
{ #category : #tests }
37-
PMComplexTest >> testAdaptToCollectionAndSend [
38-
"self run: #testAbsSecure"
36+
{ #category : #'testing - arithmetic' }
37+
PMComplexTest >> testAddingComplexNumbersToAnArrayOfIntegers [
38+
| c arrayOfIntegers expected |
39+
c := 6 - 6 i.
40+
arrayOfIntegers := #(0 1 2 3 4 5).
41+
42+
expected := { 6 - 6 i . 7 - 6 i . 8 - 6 i . 9 - 6 i . 10 - 6 i . 11 - 6 i }.
43+
self assert: (arrayOfIntegers + c) equals: expected.
44+
]
3945

40-
"using equalsTo since absSecure returns a slightly different Float"
46+
{ #category : #'testing - arithmetic' }
47+
PMComplexTest >> testAddingFractionsAndComplexNumbers [
48+
self assert: 1 + 2 i + (2 / 3) equals: 5 / 3 + 2 i.
49+
self assert: 2 / 3 + (1 + 2 i) equals: 5 / 3 + 2 i
50+
]
4151

42-
| c arr |
43-
c := 6 - 6 i.
44-
arr := #(0 1 2 3 4 5).
45-
self assert: (arr + c at: 1) equals: c.
46-
self assert: (arr * c at: 2) equals: c
52+
{ #category : #'testing - arithmetic' }
53+
PMComplexTest >> testAddingIntegersAndComplexNumbers [
54+
self assert: 1 + 2 i + 1 equals: 2 + 2 i.
55+
self assert: 1 + (1 + 2 i) equals: 2 + 2 i.
56+
]
57+
58+
{ #category : #'testing - arithmetic' }
59+
PMComplexTest >> testAddingRealNumbersAndComplexNumbers [
60+
self assert: 1 + 2 i + 1.0 equals: 2.0 + 2 i.
61+
self assert: 1.0 + (1 + 2 i) equals: 2.0 + 2 i.
4762
]
4863

4964
{ #category : #'testing - arithmetic' }
@@ -57,8 +72,6 @@ PMComplexTest >> testAddingToAPolynomial [
5772

5873
{ #category : #'testing - arithmetic' }
5974
PMComplexTest >> testAddingTwoComplexNumbers [
60-
"self run: #testAdding"
61-
6275
| c |
6376
c := 5 - 6 i + (-5 + 8 i). "Complex with Complex"
6477
self assert: c equals: 0 + 2 i
@@ -170,10 +183,6 @@ PMComplexTest >> testArgumentOfAComplexNumber [
170183

171184
{ #category : #'testing - polar coordinates' }
172185
PMComplexTest >> testArgumentOfAPositivePureImaginaryNumber [
173-
"self run: #testArg"
174-
175-
"self debug: #testArg"
176-
177186
| c |
178187
c := 0 + 5 i.
179188
self assert: c arg equals: Float pi / 2
@@ -238,20 +247,6 @@ PMComplexTest >> testComplexNumberAndIntegerAreUnequalEvenIfRealPartIsEqualToInt
238247
self deny: 1 + 3 i equals: 1.
239248
]
240249

241-
{ #category : #tests }
242-
PMComplexTest >> testConversion [
243-
"self run: #testConversion"
244-
245-
"self debug: #testConversion"
246-
247-
self assert: 1 + 2 i + 1 equals: 2 + 2 i.
248-
self assert: 1 + (1 + 2 i) equals: 2 + 2 i.
249-
self assert: 1 + 2 i + 1.0 equals: 2.0 + 2 i.
250-
self assert: 1.0 + (1 + 2 i) equals: 2.0 + 2 i.
251-
self assert: 1 + 2 i + (2 / 3) equals: 5 / 3 + 2 i.
252-
self assert: 2 / 3 + (1 + 2 i) equals: 5 / 3 + 2 i
253-
]
254-
255250
{ #category : #'testing - mathematical functions' }
256251
PMComplexTest >> testCos [
257252
| c c2 |
@@ -299,10 +294,8 @@ PMComplexTest >> testCosh2MinusSinh2 [
299294
self assert: ((c cosh squared - c sinh squared) imaginary closeTo: 0.0)]]
300295
]
301296

302-
{ #category : #tests }
297+
{ #category : #'testing - expressing complex numbers' }
303298
PMComplexTest >> testCreation [
304-
"self run: #testCreation"
305-
306299
| c |
307300
c := 5 i.
308301
self assert: c real equals: 0.
@@ -323,9 +316,6 @@ PMComplexTest >> testCreation [
323316

324317
{ #category : #'testing - arithmetic' }
325318
PMComplexTest >> testDividingALargeComplexNumbersByItself [
326-
"self run: #testDivision1"
327-
"self debug: #testDivision1"
328-
329319
| c1 c2 quotient |
330320
c1 := 2.0e252 + 3.0e70 i.
331321
c2 := c1.
@@ -412,37 +402,37 @@ PMComplexTest >> testHash [
412402
self assert: aComplex copy hash equals: aComplex hash
413403
]
414404

415-
{ #category : #tests }
405+
{ #category : #'testing - type checking' }
416406
PMComplexTest >> testIsComplexNumberOnComplex [
417407

418408
self assert: (3 + 2i) isComplexNumber
419409
]
420410

421-
{ #category : #tests }
411+
{ #category : #'testing - type checking' }
422412
PMComplexTest >> testIsComplexNumberOnNaN [
423413

424414
self deny: Character space isComplexNumber
425415
]
426416

427-
{ #category : #tests }
417+
{ #category : #'testing - type checking' }
428418
PMComplexTest >> testIsComplexNumberOnReal [
429419

430420
self deny: 5 isComplexNumber
431421
]
432422

433-
{ #category : #tests }
423+
{ #category : #'testing - type checking' }
434424
PMComplexTest >> testIsRealNumberOnComplex [
435425

436426
self deny: (3 + 2i) isRealNumber
437427
]
438428

439-
{ #category : #tests }
429+
{ #category : #'testing - type checking' }
440430
PMComplexTest >> testIsRealNumberOnNaN [
441431

442432
self deny: Character space isRealNumber
443433
]
444434

445-
{ #category : #tests }
435+
{ #category : #'testing - type checking' }
446436
PMComplexTest >> testIsRealNumberOnReal [
447437

448438
self assert: 0.5 isRealNumber
@@ -466,6 +456,16 @@ PMComplexTest >> testMultiplyByI [
466456
self assert: c * 1 i equals: c i
467457
]
468458

459+
{ #category : #'testing - arithmetic' }
460+
PMComplexTest >> testMultiplyingAnArrayOfIntegersByAComplexNumber [
461+
| c arrayOfIntegers expected |
462+
c := 6 - 6 i.
463+
arrayOfIntegers := #(0 1 2 3 4 5).
464+
465+
expected := { 0 + 0 i . 6 - 6 i . 12 - 12 i . 18 - 18 i . 24 - 24 i . 30 - 30 i }.
466+
self assert: (arrayOfIntegers * c) equals: expected .
467+
]
468+
469469
{ #category : #'testing - arithmetic' }
470470
PMComplexTest >> testMultiplyingArraysOfComplexNumbers [
471471
| complexNumbersMultiplied complexNumbers expected |
@@ -490,16 +490,12 @@ PMComplexTest >> testMultiplyingByPolynomials [
490490

491491
{ #category : #'testing - arithmetic' }
492492
PMComplexTest >> testNegated [
493-
"self run: #testNegated"
494-
495-
"self debug: #testNegated"
496-
497493
| c |
498494
c := 2 + 5 i.
499495
self assert: c negated equals: -2 - 5 i
500496
]
501497

502-
{ #category : #tests }
498+
{ #category : #'testing - expressing complex numbers' }
503499
PMComplexTest >> testNew [
504500
| c |
505501
c := PMComplex new.
@@ -532,7 +528,7 @@ PMComplexTest >> testNumberAsComplex [
532528
self assert: minusOne sqrt equals: 1 i
533529
]
534530

535-
{ #category : #tests }
531+
{ #category : #'testing - expressing complex numbers' }
536532
PMComplexTest >> testOne [
537533
| one |
538534
one := PMComplex one.
@@ -761,9 +757,6 @@ PMComplexTest >> testSquareRootOfVerySmallRealAndVeryLargeImaginary [
761757

762758
{ #category : #'testing - mathematical functions' }
763759
PMComplexTest >> testSquareRootOfZeroIsZero [
764-
"comment stating purpose of instance-side method"
765-
"scope: class-variables & instance-variables"
766-
767760
| squareRoot expected |
768761
squareRoot := PMComplex zero sqrt .
769762

@@ -773,10 +766,6 @@ PMComplexTest >> testSquareRootOfZeroIsZero [
773766

774767
{ #category : #'testing - mathematical functions' }
775768
PMComplexTest >> testSquared [
776-
"self run: #testSquared"
777-
778-
"self debug: #testSquared"
779-
780769
| c c2 |
781770
c := 6 - 6 i.
782771
c2 := c squared.
@@ -844,11 +833,6 @@ PMComplexTest >> testWeCanWriteComplexNumbersWhoseRealAndImaginaryPartsAreFracti
844833
self assert: (z imaginary) equals: (Fraction numerator: 4 denominator: 5).
845834
]
846835

847-
{ #category : #'testing - arithmetic' }
848-
PMComplexTest >> testWeCannotTheTakeReciprocalOfZeroComplexNumbers [
849-
self should: [ PMComplex zero reciprocal ] raise: ZeroDivide.
850-
]
851-
852836
{ #category : #'testing - expressing complex numbers' }
853837
PMComplexTest >> testWeCannotWriteFractionsOfComplexNumbersWithDenominatorNormalized [
854838

@@ -872,7 +856,7 @@ PMComplexTest >> testWeCannotWriteFractionsWhoseNumeratorAndDenominatorAreComple
872856
self should: [ Fraction numerator: numerator denominator: denominator ] raise: Exception .
873857
]
874858

875-
{ #category : #tests }
859+
{ #category : #'testing - expressing complex numbers' }
876860
PMComplexTest >> testZero [
877861
| z |
878862
z := PMComplex zero.
@@ -887,3 +871,8 @@ PMComplexTest >> testZeroComplexNumberIsEqualToIntegerZero [
887871
self assert: 0 i equals: 0.
888872
self assert: 0 equals: 0 i.
889873
]
874+
875+
{ #category : #'testing - arithmetic' }
876+
PMComplexTest >> testZeroComplexNumbersDoNotHaveAReciprocal [
877+
self should: [ PMComplex zero reciprocal ] raise: ZeroDivide.
878+
]

0 commit comments

Comments
 (0)