From af69a6694df67a70c85e0487951b41c2d8899504 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 11 Jan 2024 18:56:14 +0000 Subject: [PATCH 01/23] test: added a test for positive integer. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index efddcf78..fc6c0071 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -646,6 +646,14 @@ PMComplexNumberTest >> testRaisedToInteger [ self assert: c3 reciprocal equals: (c raisedToInteger: -3) ] +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testRaisedToPositiveInteger [ + | z zCubed | + z := (3 sqrt / 2) + (1 / 2) i. + zCubed := (z raisedTo: 3) . + self assert: zCubed closeTo: (0 + 1 i). +] + { #category : #tests } PMComplexNumberTest >> testRandom [ | random c r | From ccd3076e4fda6939b636d8e52534abae9e4b745a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 11 Jan 2024 22:51:21 +0000 Subject: [PATCH 02/23] test: added some missing tests. --- .../PMComplexNumberTest.class.st | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index fc6c0071..45b1b80b 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -637,6 +637,15 @@ PMComplexNumberTest >> testRaisedTo [ self assert: c3 imaginary closeTo: c imaginary ] +{ #category : #tests } +PMComplexNumberTest >> testRaisedToFractionalPower [ + + | z expected | + z := 0 + 1 i. + expected := 3 sqrt / 2 + (1 / 2) i. + self assert: (z raisedTo: 1 / 3) closeTo: expected +] + { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToInteger [ | c c3 | @@ -646,6 +655,13 @@ PMComplexNumberTest >> testRaisedToInteger [ self assert: c3 reciprocal equals: (c raisedToInteger: -3) ] +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testRaisedToNegativeInteger [ + | z | + z := (3 sqrt / 2) + (1 / 2) i. + self assert: (z raisedTo: -3) closeTo: (0 - 1 i). +] + { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToPositiveInteger [ | z zCubed | From 7abf5847269a3d746fa60950c557230da56f3c63 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 11 Jan 2024 22:52:28 +0000 Subject: [PATCH 03/23] refactor: corrected the category. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 45b1b80b..4874e0fb 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -637,7 +637,7 @@ PMComplexNumberTest >> testRaisedTo [ self assert: c3 imaginary closeTo: c imaginary ] -{ #category : #tests } +{ #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToFractionalPower [ | z expected | From d64a1bdad1f7cc2e8af60a2453f7b0211ff256a9 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 19:58:56 +0000 Subject: [PATCH 04/23] test: changed the test data to cos(pi/3) + i sin(pi/3). --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 4874e0fb..e36ef500 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -658,8 +658,8 @@ PMComplexNumberTest >> testRaisedToInteger [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToNegativeInteger [ | z | - z := (3 sqrt / 2) + (1 / 2) i. - self assert: (z raisedTo: -3) closeTo: (0 - 1 i). + z := (1 / 2) + (3 sqrt / 2) i. + self assert: (z raisedTo: -3) closeTo: (-1 + 0 i). ] { #category : #'testing - mathematical functions' } From f96485e40a7f7f36a3ea93153bcfacad1d000745 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 20:03:37 +0000 Subject: [PATCH 05/23] comment: added documentation that shows how to get the answer using De Moivre's theorem. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index e36ef500..91072da2 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -657,6 +657,11 @@ PMComplexNumberTest >> testRaisedToInteger [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToNegativeInteger [ + " + Suppose z = cos(pi / 3) + i sin(pi / 3). By De Moivre's theorem, z**-3 is + z ** 3 = cos(-3 pi / 3) + i sin(-3 pi / 3) = cos(-pi) + sin(pi) = cos(pi) - i sin(pi) + z ** 3 = 0 - i + " | z | z := (1 / 2) + (3 sqrt / 2) i. self assert: (z raisedTo: -3) closeTo: (-1 + 0 i). @@ -665,6 +670,10 @@ PMComplexNumberTest >> testRaisedToNegativeInteger [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToPositiveInteger [ | z zCubed | + " + Suppose z = cos(pi / 6) + i sin(pi / 6). By De Moivre's theorem, z**3 is + z ** 3 = cos(3 pi / 6) + i sin(3 pi / 6) = cos(pi / 2) + sin(pi / 2) = 0 + i + " z := (3 sqrt / 2) + (1 / 2) i. zCubed := (z raisedTo: 3) . self assert: zCubed closeTo: (0 + 1 i). From f4d8a3c9ad5832f2b4f6cd0b49f573ec07f7016a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 20:06:19 +0000 Subject: [PATCH 06/23] test: added another missing test. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 91072da2..23346620 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -253,6 +253,14 @@ PMComplexNumberTest >> testComplexNumberAndIntegerAreUnequalEvenIfRealPartIsEqua self deny: 1 + 3 i equals: 1 ] +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testComplexNumberZeroRaisedToThePowerOfZero [ + + | zeroRaisedToZero | + zeroRaisedToZero := (PMComplexNumber zero) raisedTo: 0. + self assert: zeroRaisedToZero equals: PMComplexNumber one. +] + { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCos [ From a04e5120a073e6e42e229ebab60429f2ea7511c4 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 20:07:37 +0000 Subject: [PATCH 07/23] refactor: made the test name shorter and hopefully more concise. --- .../PMComplexNumberTest.class.st | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 23346620..b89de39e 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -253,14 +253,6 @@ PMComplexNumberTest >> testComplexNumberAndIntegerAreUnequalEvenIfRealPartIsEqua self deny: 1 + 3 i equals: 1 ] -{ #category : #'testing - mathematical functions' } -PMComplexNumberTest >> testComplexNumberZeroRaisedToThePowerOfZero [ - - | zeroRaisedToZero | - zeroRaisedToZero := (PMComplexNumber zero) raisedTo: 0. - self assert: zeroRaisedToZero equals: PMComplexNumber one. -] - { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testCos [ @@ -967,3 +959,11 @@ PMComplexNumberTest >> testZeroComplexNumberIsEqualToIntegerZero [ PMComplexNumberTest >> testZeroComplexNumbersDoNotHaveAReciprocal [ self should: [ PMComplexNumber zero reciprocal ] raise: ZeroDivide ] + +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testZeroRaisedToThePowerOfZero [ + + | zeroRaisedToZero | + zeroRaisedToZero := (PMComplexNumber zero) raisedTo: 0. + self assert: zeroRaisedToZero equals: PMComplexNumber one. +] From eca5b1ddd0c8fd8720693240ce149b218cf8d55c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 20:10:41 +0000 Subject: [PATCH 08/23] fix: corrected the documentation. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index b89de39e..c8c3849e 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -660,7 +660,7 @@ PMComplexNumberTest >> testRaisedToNegativeInteger [ " Suppose z = cos(pi / 3) + i sin(pi / 3). By De Moivre's theorem, z**-3 is z ** 3 = cos(-3 pi / 3) + i sin(-3 pi / 3) = cos(-pi) + sin(pi) = cos(pi) - i sin(pi) - z ** 3 = 0 - i + z ** 3 = -1 + 0 i " | z | z := (1 / 2) + (3 sqrt / 2) i. From abf6a612deebccff8e52312497eecb3f9322240c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 22:30:17 +0000 Subject: [PATCH 09/23] test: demonstrated that sending raiseToInteger: with floating point number raises an Error. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index c8c3849e..3b7c9200 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -655,6 +655,13 @@ PMComplexNumberTest >> testRaisedToInteger [ self assert: c3 reciprocal equals: (c raisedToInteger: -3) ] +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testRaisedToIntegerWithFloats [ + |z| + z := 5 - 9 i. + self should: [ z raisedToInteger: 3.0 ] raise: ArithmeticError . +] + { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testRaisedToNegativeInteger [ " From 45b4d3c40b4b06eab2c4a1b09a02fe413a597d2b Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 22:50:47 +0000 Subject: [PATCH 10/23] refactor: clarified the name of a method. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 3b7c9200..ad4e389a 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -656,7 +656,7 @@ PMComplexNumberTest >> testRaisedToInteger [ ] { #category : #'testing - mathematical functions' } -PMComplexNumberTest >> testRaisedToIntegerWithFloats [ +PMComplexNumberTest >> testRaisedToIntegerWithNonIntegersRaisesAnError [ |z| z := 5 - 9 i. self should: [ z raisedToInteger: 3.0 ] raise: ArithmeticError . From 1a0b3ca83c31ad9707dec0f6e78557aa972b4ba4 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 22:54:31 +0000 Subject: [PATCH 11/23] refactor: ComplexNumber is a Whole Value and we can assert equality. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index ad4e389a..788bbd4d 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -880,8 +880,7 @@ PMComplexNumberTest >> testSquared [ | c c2 | c := 6 - 6 i. c2 := c squared. - self assert: c2 imaginary equals: -72. - self assert: c2 real equals: 0 + self assert: c2 equals: (0 - 72 i) ] { #category : #'testing - arithmetic' } From fdae0618ce0dabc76ef06b50abb082bd8a8d135e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 15 Jan 2024 22:55:12 +0000 Subject: [PATCH 12/23] refactor: Inline Variable as it is not paying its rent. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 788bbd4d..8c3a039c 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -877,10 +877,10 @@ PMComplexNumberTest >> testSquareRootOfZeroIsZero [ { #category : #'testing - mathematical functions' } PMComplexNumberTest >> testSquared [ - | c c2 | + + | c | c := 6 - 6 i. - c2 := c squared. - self assert: c2 equals: (0 - 72 i) + self assert: c squared equals: 0 - 72 i ] { #category : #'testing - arithmetic' } From ede673de95b0adcd4ce9e07d9a7e39951177418a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Tue, 16 Jan 2024 20:08:13 +0000 Subject: [PATCH 13/23] test: simplified the test a little. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 8c3a039c..d3766878 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -17,7 +17,7 @@ PMComplexNumberTest >> testAbs [ "self debug: #testAbs" | c | - c := 6 i: -6. + c := 6 - 6 i. self assert: c abs equals: 72 sqrt ] From baaa8a3261916afc3ea6ed6e610a900556112dcf Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Tue, 16 Jan 2024 21:30:31 +0000 Subject: [PATCH 14/23] refactor: extracted computations to local variables. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index d3766878..787117e2 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -206,7 +206,11 @@ PMComplexNumberTest >> testArgumentOfPureNegativeImaginaryNumber [ { #category : #'testing - bugs' } PMComplexNumberTest >> testBug1 [ - self assert: (0.5 * (2 + 0 i) ln) exp equals: (0.5 * 2 ln) exp + | logOfRootTwo logRootTwo | + logOfRootTwo := (0.5 * (2 + 0 i) ln). + self assert: logOfRootTwo exp closeTo: 2 sqrt + 0.0 i. + logRootTwo := (0.5 * 2 ln). + self assert: logOfRootTwo exp equals: logRootTwo exp ] { #category : #'testing - close to' } From ec1974362c1169adac69a3188a77cbae9ec7fe4c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Tue, 16 Jan 2024 21:34:48 +0000 Subject: [PATCH 15/23] refactor: extracted writing complex numbers in polar coordinates to their own tests. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 787117e2..75247b5b 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -323,9 +323,6 @@ PMComplexNumberTest >> testCreation [ c := PMComplexNumber real: 10 imaginary: 5. self assert: c real equals: 10. self assert: c imaginary equals: 5. - c := PMComplexNumber abs: 5 arg: Float pi / 2. - self assert: c real rounded equals: 0. - self assert: c imaginary equals: 5 ] { #category : #'testing - arithmetic' } @@ -940,6 +937,15 @@ PMComplexNumberTest >> testTwoComplexNumbersWithDifferentRealPartsAreNotEqual [ self deny: z equals: w ] +{ #category : #'testing - expressing complex numbers' } +PMComplexNumberTest >> testWritingComplexNumbersInRadialCoordinates [ + | c | + + c := PMComplexNumber abs: 5 arg: Float pi / 2. + self assert: c real rounded equals: 0. + self assert: c imaginary equals: 5 +] + { #category : #'testing - expressing complex numbers' } PMComplexNumberTest >> testWritingComplexNumbersWhoseRealAndImaginaryPartsAreFractions [ | z | From 2e882c92ccac17f755be1c00a80ed34da77550da Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Tue, 16 Jan 2024 21:35:59 +0000 Subject: [PATCH 16/23] refactor: corrected the name of the test. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 75247b5b..2d8daf5e 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -938,7 +938,7 @@ PMComplexNumberTest >> testTwoComplexNumbersWithDifferentRealPartsAreNotEqual [ ] { #category : #'testing - expressing complex numbers' } -PMComplexNumberTest >> testWritingComplexNumbersInRadialCoordinates [ +PMComplexNumberTest >> testWritingComplexNumbersInPolarCoordinates [ | c | c := PMComplexNumber abs: 5 arg: Float pi / 2. From 94e6d49a0df402839412d78bfd3ecb1b8969b48b Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Tue, 16 Jan 2024 21:54:56 +0000 Subject: [PATCH 17/23] refactor: renamed the test to make it clear we are writing complex numbers in cartesian coordinates. --- .../PMComplexNumberTest.class.st | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 2d8daf5e..f9835ef7 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -308,23 +308,6 @@ PMComplexNumberTest >> testCosh2MinusSinh2 [ self assert: (c cosh squared - c sinh squared) imaginary closeTo: 0.0 ] ] ] -{ #category : #'testing - expressing complex numbers' } -PMComplexNumberTest >> testCreation [ - | c | - c := 5 i. - self assert: c real equals: 0. - self assert: c imaginary equals: 5. - c := 6 + 7 i. - self assert: c real equals: 6. - self assert: c imaginary equals: 7. - c := 5.6 - 8 i. - self assert: c real equals: 5.6. - self assert: c imaginary equals: -8. - c := PMComplexNumber real: 10 imaginary: 5. - self assert: c real equals: 10. - self assert: c imaginary equals: 5. -] - { #category : #'testing - arithmetic' } PMComplexNumberTest >> testDividingALargeComplexNumbersByItself [ | c1 c2 quotient | @@ -937,6 +920,23 @@ PMComplexNumberTest >> testTwoComplexNumbersWithDifferentRealPartsAreNotEqual [ self deny: z equals: w ] +{ #category : #'testing - expressing complex numbers' } +PMComplexNumberTest >> testWritingComplexNumbersInCartesianCoordinates [ + | c | + c := 5 i. + self assert: c real equals: 0. + self assert: c imaginary equals: 5. + c := 6 + 7 i. + self assert: c real equals: 6. + self assert: c imaginary equals: 7. + c := 5.6 - 8 i. + self assert: c real equals: 5.6. + self assert: c imaginary equals: -8. + c := PMComplexNumber real: 10 imaginary: 5. + self assert: c real equals: 10. + self assert: c imaginary equals: 5. +] + { #category : #'testing - expressing complex numbers' } PMComplexNumberTest >> testWritingComplexNumbersInPolarCoordinates [ | c | From 4ad4f60d2c8a6e3b6e555b3b95e2fae816829adf Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:19:38 +0000 Subject: [PATCH 18/23] refactor: clarified the names of some message arguments. --- src/Math-Complex/PMComplexNumber.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Complex/PMComplexNumber.class.st b/src/Math-Complex/PMComplexNumber.class.st index 4033f660..48178a12 100644 --- a/src/Math-Complex/PMComplexNumber.class.st +++ b/src/Math-Complex/PMComplexNumber.class.st @@ -672,10 +672,10 @@ PMComplexNumber >> real [ ] { #category : #private } -PMComplexNumber >> real: aNumber1 imaginary: aNumber2 [ +PMComplexNumber >> real: realPart imaginary: imaginaryPart [ "Private - initialize the real and imaginary parts of a Complex" - real := aNumber1. - imaginary := aNumber2 + real := realPart. + imaginary := imaginaryPart ] { #category : #arithmetic } From bca0a1ffff2765e12f5db0052af78377002565ed Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:21:53 +0000 Subject: [PATCH 19/23] Removed the comment, as the code is self-explanatory. --- src/Math-Complex/PMComplexNumber.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Complex/PMComplexNumber.class.st b/src/Math-Complex/PMComplexNumber.class.st index 48178a12..b4b67c81 100644 --- a/src/Math-Complex/PMComplexNumber.class.st +++ b/src/Math-Complex/PMComplexNumber.class.st @@ -624,7 +624,7 @@ PMComplexNumber >> productWithVector: aVector [ PMComplexNumber >> raisedTo: aNumber [ "Answer the receiver raised to aNumber." - aNumber isInteger ifTrue: [ "Do the special case of integer power" ^ self raisedToInteger: aNumber ]. + aNumber isInteger ifTrue: [ ^ self raisedToInteger: aNumber ]. 0 = aNumber ifTrue: [ ^ self class one ]. "Special case of exponent=0" 1 = aNumber ifTrue: [ ^ self ]. "Special case of exponent=1" From 91af93fcbc6568a9d2c174c56fa35c98dff687af Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:23:06 +0000 Subject: [PATCH 20/23] refactor: Rename Variable where we clarify the name of a variable. --- src/Math-Complex/PMComplexNumber.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math-Complex/PMComplexNumber.class.st b/src/Math-Complex/PMComplexNumber.class.st index b4b67c81..488da9cd 100644 --- a/src/Math-Complex/PMComplexNumber.class.st +++ b/src/Math-Complex/PMComplexNumber.class.st @@ -621,18 +621,18 @@ PMComplexNumber >> productWithVector: aVector [ ] { #category : #'mathematical functions' } -PMComplexNumber >> raisedTo: aNumber [ +PMComplexNumber >> raisedTo: index [ "Answer the receiver raised to aNumber." - aNumber isInteger ifTrue: [ ^ self raisedToInteger: aNumber ]. + index isInteger ifTrue: [ ^ self raisedToInteger: index ]. - 0 = aNumber ifTrue: [ ^ self class one ]. "Special case of exponent=0" - 1 = aNumber ifTrue: [ ^ self ]. "Special case of exponent=1" + 0 = index ifTrue: [ ^ self class one ]. "Special case of exponent=0" + 1 = index ifTrue: [ ^ self ]. "Special case of exponent=1" 0 = self ifTrue: [ "Special case of self = 0" - ^ aNumber < 0 + ^ index < 0 ifTrue: [ (ZeroDivide dividend: self) signal ] ifFalse: [ self ] ]. - ^ (aNumber * self ln) exp "Otherwise use logarithms" + ^ (index * self ln) exp "Otherwise use logarithms" ] { #category : #'mathematical functions' } From 9aaedf02229ea41fd75559f993dc9df662790cab Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:23:59 +0000 Subject: [PATCH 21/23] chore: corrected the name of the comment. --- src/Math-Complex/PMComplexNumber.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Complex/PMComplexNumber.class.st b/src/Math-Complex/PMComplexNumber.class.st index 488da9cd..84a95d98 100644 --- a/src/Math-Complex/PMComplexNumber.class.st +++ b/src/Math-Complex/PMComplexNumber.class.st @@ -622,7 +622,7 @@ PMComplexNumber >> productWithVector: aVector [ { #category : #'mathematical functions' } PMComplexNumber >> raisedTo: index [ - "Answer the receiver raised to aNumber." + "Answer the receiver raised to the power of an index." index isInteger ifTrue: [ ^ self raisedToInteger: index ]. From a9a955eb8f700ebeab0523640cf48d37a0200c49 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:27:36 +0000 Subject: [PATCH 22/23] refactor/test: removed a comment, and added a missing test. --- src/Math-Complex/PMComplexNumber.class.st | 6 +++--- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Math-Complex/PMComplexNumber.class.st b/src/Math-Complex/PMComplexNumber.class.st index 84a95d98..057d347c 100644 --- a/src/Math-Complex/PMComplexNumber.class.st +++ b/src/Math-Complex/PMComplexNumber.class.st @@ -626,9 +626,9 @@ PMComplexNumber >> raisedTo: index [ index isInteger ifTrue: [ ^ self raisedToInteger: index ]. - 0 = index ifTrue: [ ^ self class one ]. "Special case of exponent=0" - 1 = index ifTrue: [ ^ self ]. "Special case of exponent=1" - 0 = self ifTrue: [ "Special case of self = 0" + 0 = index ifTrue: [ ^ self class one ]. + 1 = index ifTrue: [ ^ self ]. + 0 = self ifTrue: [ ^ index < 0 ifTrue: [ (ZeroDivide dividend: self) signal ] ifFalse: [ self ] ]. diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index f9835ef7..341c50c1 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -670,6 +670,13 @@ PMComplexNumberTest >> testRaisedToPositiveInteger [ self assert: zCubed closeTo: (0 + 1 i). ] +{ #category : #'testing - mathematical functions' } +PMComplexNumberTest >> testRaisingZeroToThePowerOfNegativeIndex [ + | zero | + zero := PMComplexNumber zero. + self should: [ zero raisedTo: -4 ] raise: ZeroDivide +] + { #category : #tests } PMComplexNumberTest >> testRandom [ | random c r | From b04f7c9ecbbafc50800f54f329f9523c1952d44a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 17 Jan 2024 08:34:08 +0000 Subject: [PATCH 23/23] test: added another missing test. --- src/Math-Tests-Complex/PMComplexNumberTest.class.st | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Math-Tests-Complex/PMComplexNumberTest.class.st b/src/Math-Tests-Complex/PMComplexNumberTest.class.st index 341c50c1..e60fcc62 100644 --- a/src/Math-Tests-Complex/PMComplexNumberTest.class.st +++ b/src/Math-Tests-Complex/PMComplexNumberTest.class.st @@ -990,3 +990,13 @@ PMComplexNumberTest >> testZeroRaisedToThePowerOfZero [ zeroRaisedToZero := (PMComplexNumber zero) raisedTo: 0. self assert: zeroRaisedToZero equals: PMComplexNumber one. ] + +{ #category : #tests } +PMComplexNumberTest >> testZeroToThePowerOfZero [ + "comment stating purpose of instance-side method" + "scope: class-variables & instance-variables" + + | zero | + zero := PMComplexNumber zero. + self assert: (zero raisedTo: 0) equals: PMComplexNumber one. +]