@@ -17,7 +17,7 @@ PMComplexNumberTest >> testAbs [
17
17
" self debug: #testAbs"
18
18
19
19
| c |
20
- c := 6 i: - 6 .
20
+ c := 6 - 6 i .
21
21
self assert: c abs equals: 72 sqrt
22
22
]
23
23
@@ -206,7 +206,11 @@ PMComplexNumberTest >> testArgumentOfPureNegativeImaginaryNumber [
206
206
207
207
{ #category : #' testing - bugs' }
208
208
PMComplexNumberTest >> testBug1 [
209
- self assert: (0.5 * (2 + 0 i) ln) exp equals: (0.5 * 2 ln) exp
209
+ | logOfRootTwo logRootTwo |
210
+ logOfRootTwo := (0.5 * (2 + 0 i) ln).
211
+ self assert: logOfRootTwo exp closeTo: 2 sqrt + 0.0 i.
212
+ logRootTwo := (0.5 * 2 ln).
213
+ self assert: logOfRootTwo exp equals: logRootTwo exp
210
214
]
211
215
212
216
{ #category : #' testing - close to' }
@@ -304,26 +308,6 @@ PMComplexNumberTest >> testCosh2MinusSinh2 [
304
308
self assert: (c cosh squared - c sinh squared) imaginary closeTo: 0.0 ] ]
305
309
]
306
310
307
- { #category : #' testing - expressing complex numbers' }
308
- PMComplexNumberTest >> testCreation [
309
- | c |
310
- c := 5 i.
311
- self assert: c real equals: 0 .
312
- self assert: c imaginary equals: 5 .
313
- c := 6 + 7 i.
314
- self assert: c real equals: 6 .
315
- self assert: c imaginary equals: 7 .
316
- c := 5.6 - 8 i.
317
- self assert: c real equals: 5.6 .
318
- self assert: c imaginary equals: - 8 .
319
- c := PMComplexNumber real: 10 imaginary: 5 .
320
- self assert: c real equals: 10 .
321
- self assert: c imaginary equals: 5 .
322
- c := PMComplexNumber abs: 5 arg: Float pi / 2 .
323
- self assert: c real rounded equals: 0 .
324
- self assert: c imaginary equals: 5
325
- ]
326
-
327
311
{ #category : #' testing - arithmetic' }
328
312
PMComplexNumberTest >> testDividingALargeComplexNumbersByItself [
329
313
| c1 c2 quotient |
@@ -637,6 +621,15 @@ PMComplexNumberTest >> testRaisedTo [
637
621
self assert: c3 imaginary closeTo: c imaginary
638
622
]
639
623
624
+ { #category : #' testing - mathematical functions' }
625
+ PMComplexNumberTest >> testRaisedToFractionalPower [
626
+
627
+ | z expected |
628
+ z := 0 + 1 i.
629
+ expected := 3 sqrt / 2 + (1 / 2 ) i.
630
+ self assert: (z raisedTo: 1 / 3 ) closeTo: expected
631
+ ]
632
+
640
633
{ #category : #' testing - mathematical functions' }
641
634
PMComplexNumberTest >> testRaisedToInteger [
642
635
| c c3 |
@@ -646,6 +639,44 @@ PMComplexNumberTest >> testRaisedToInteger [
646
639
self assert: c3 reciprocal equals: (c raisedToInteger: - 3 )
647
640
]
648
641
642
+ { #category : #' testing - mathematical functions' }
643
+ PMComplexNumberTest >> testRaisedToIntegerWithNonIntegersRaisesAnError [
644
+ |z |
645
+ z := 5 - 9 i.
646
+ self should: [ z raisedToInteger: 3.0 ] raise: ArithmeticError .
647
+ ]
648
+
649
+ { #category : #' testing - mathematical functions' }
650
+ PMComplexNumberTest >> testRaisedToNegativeInteger [
651
+ "
652
+ Suppose z = cos(pi / 3) + i sin(pi / 3). By De Moivre's theorem, z**-3 is
653
+ z ** 3 = cos(-3 pi / 3) + i sin(-3 pi / 3) = cos(-pi) + sin(pi) = cos(pi) - i sin(pi)
654
+ z ** 3 = -1 + 0 i
655
+ "
656
+ | z |
657
+ z := (1 / 2 ) + (3 sqrt / 2 ) i.
658
+ self assert: (z raisedTo: - 3 ) closeTo: (- 1 + 0 i).
659
+ ]
660
+
661
+ { #category : #' testing - mathematical functions' }
662
+ PMComplexNumberTest >> testRaisedToPositiveInteger [
663
+ | z zCubed |
664
+ "
665
+ Suppose z = cos(pi / 6) + i sin(pi / 6). By De Moivre's theorem, z**3 is
666
+ z ** 3 = cos(3 pi / 6) + i sin(3 pi / 6) = cos(pi / 2) + sin(pi / 2) = 0 + i
667
+ "
668
+ z := (3 sqrt / 2 ) + (1 / 2 ) i.
669
+ zCubed := (z raisedTo: 3 ) .
670
+ self assert: zCubed closeTo: (0 + 1 i).
671
+ ]
672
+
673
+ { #category : #' testing - mathematical functions' }
674
+ PMComplexNumberTest >> testRaisingZeroToThePowerOfNegativeIndex [
675
+ | zero |
676
+ zero := PMComplexNumber zero.
677
+ self should: [ zero raisedTo: - 4 ] raise: ZeroDivide
678
+ ]
679
+
649
680
{ #category : #tests }
650
681
PMComplexNumberTest >> testRandom [
651
682
| random c r |
@@ -837,11 +868,10 @@ PMComplexNumberTest >> testSquareRootOfZeroIsZero [
837
868
838
869
{ #category : #' testing - mathematical functions' }
839
870
PMComplexNumberTest >> testSquared [
840
- | c c2 |
871
+
872
+ | c |
841
873
c := 6 - 6 i.
842
- c2 := c squared.
843
- self assert: c2 imaginary equals: - 72 .
844
- self assert: c2 real equals: 0
874
+ self assert: c squared equals: 0 - 72 i
845
875
]
846
876
847
877
{ #category : #' testing - arithmetic' }
@@ -897,6 +927,32 @@ PMComplexNumberTest >> testTwoComplexNumbersWithDifferentRealPartsAreNotEqual [
897
927
self deny: z equals: w
898
928
]
899
929
930
+ { #category : #' testing - expressing complex numbers' }
931
+ PMComplexNumberTest >> testWritingComplexNumbersInCartesianCoordinates [
932
+ | c |
933
+ c := 5 i.
934
+ self assert: c real equals: 0 .
935
+ self assert: c imaginary equals: 5 .
936
+ c := 6 + 7 i.
937
+ self assert: c real equals: 6 .
938
+ self assert: c imaginary equals: 7 .
939
+ c := 5.6 - 8 i.
940
+ self assert: c real equals: 5.6 .
941
+ self assert: c imaginary equals: - 8 .
942
+ c := PMComplexNumber real: 10 imaginary: 5 .
943
+ self assert: c real equals: 10 .
944
+ self assert: c imaginary equals: 5 .
945
+ ]
946
+
947
+ { #category : #' testing - expressing complex numbers' }
948
+ PMComplexNumberTest >> testWritingComplexNumbersInPolarCoordinates [
949
+ | c |
950
+
951
+ c := PMComplexNumber abs: 5 arg: Float pi / 2 .
952
+ self assert: c real rounded equals: 0 .
953
+ self assert: c imaginary equals: 5
954
+ ]
955
+
900
956
{ #category : #' testing - expressing complex numbers' }
901
957
PMComplexNumberTest >> testWritingComplexNumbersWhoseRealAndImaginaryPartsAreFractions [
902
958
| z |
@@ -926,3 +982,21 @@ PMComplexNumberTest >> testZeroComplexNumberIsEqualToIntegerZero [
926
982
PMComplexNumberTest >> testZeroComplexNumbersDoNotHaveAReciprocal [
927
983
self should: [ PMComplexNumber zero reciprocal ] raise: ZeroDivide
928
984
]
985
+
986
+ { #category : #' testing - mathematical functions' }
987
+ PMComplexNumberTest >> testZeroRaisedToThePowerOfZero [
988
+
989
+ | zeroRaisedToZero |
990
+ zeroRaisedToZero := (PMComplexNumber zero) raisedTo: 0 .
991
+ self assert: zeroRaisedToZero equals: PMComplexNumber one.
992
+ ]
993
+
994
+ { #category : #tests }
995
+ PMComplexNumberTest >> testZeroToThePowerOfZero [
996
+ " comment stating purpose of instance-side method"
997
+ " scope: class-variables & instance-variables"
998
+
999
+ | zero |
1000
+ zero := PMComplexNumber zero.
1001
+ self assert: (zero raisedTo: 0 ) equals: PMComplexNumber one.
1002
+ ]
0 commit comments