Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style: corrected some style errors #324

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions src/Math-Complex/PMComplexNumber.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ PMComplexNumber >> divideFastAndSecureBy: anObject [
newReal := r * real + imaginary / d.
r * imaginary - real / d ].

^ PMComplexNumber real: newReal imaginary: newImaginary ].
^ self class real: newReal imaginary: newImaginary ].
^ anObject adaptToComplex: self andSend: #/
]

Expand All @@ -507,7 +507,7 @@ PMComplexNumber >> divideSecureBy: anObject [

newReal := ars*brs + (ais*bis) /s.
newImaginary := ais*brs - (ars*bis)/s.
^ PMComplexNumber real: newReal imaginary: newImaginary].
^ self class real: newReal imaginary: newImaginary].
^ anObject adaptToComplex: self andSend: #/
]

Expand Down
71 changes: 64 additions & 7 deletions src/Math-Tests-Complex/PMComplexNumberTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -630,20 +630,59 @@ PMComplexNumberTest >> testQuotientsOfComplexNumbersCannotBeWritten [
{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedTo [

| c c3 |
c := 5 - 6 i.
c3 := (c raisedTo: 0.2) raisedTo: 5.
self assert: c3 real closeTo: c real.
self assert: c3 imaginary closeTo: c imaginary
| expected squareRootOfZSquared z |
z := 5 - 6 i.
squareRootOfZSquared := (z raisedTo: 1 / 2) raisedTo: 2.
expected := 5 - 6 i.
self assert: squareRootOfZSquared closeTo: expected
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedToFractionalIndex [

| z expected |
z := 1 / 2 + (3 sqrt / 2) i.
"Here, we appeal to de Moivre's theorem to compute the expected answer"
expected := 3 sqrt / 2 + (1 / 2) i.
self assert: (z raisedTo: 1 / 2) closeTo: expected
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedToInteger [

| c c3 |
c := 5 - 6 i.
c3 := c * c * c.
self assert: c3 equals: (c raisedToInteger: 3).
self assert: c3 reciprocal equals: (c raisedToInteger: -3)
self assert: (c raisedToInteger: -3) equals: c3 reciprocal
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedToNegativeInteger [

| z expected |
z := 3 sqrt / 2 + (1 / 2) i.
"Here, we appeal to de Moivre's theorem to compute the expected answer"
expected := 0 - 1 i.
self assert: (z raisedTo: -3) closeTo: expected
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedToPositiveNumber [
| z expected |
z := (3 sqrt / 2) + (1/2) i.
"Here, we appeal to de Moivre's theorem to compute the expected answer"
expected := 0 + 1 i.
self assert: (z raisedTo: 3) closeTo: expected.
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testRaisedToZero [

| z expected |
z := 3 sqrt / 2 + (1 / 2) i.
"Here, we appeal to de Moivre's theorem to compute the expected answer"
expected := 1 .
self assert: (z raisedTo: 0) equals: expected
]

{ #category : #tests }
Expand Down Expand Up @@ -926,3 +965,21 @@ PMComplexNumberTest >> testZeroComplexNumberIsEqualToIntegerZero [
PMComplexNumberTest >> testZeroComplexNumbersDoNotHaveAReciprocal [
self should: [ PMComplexNumber zero reciprocal ] raise: ZeroDivide
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testZeroRaisedToNegativePowerRaisesAZeroDivisionError [

| z expected |
z := PMComplexNumber zero.
expected := 0 + 1 i.
self should: [ z raisedTo: -3 ] raise: ZeroDivide
]

{ #category : #'testing - mathematical functions' }
PMComplexNumberTest >> testZeroRaisedToPowerOfZero [

| z expected |
z := PMComplexNumber zero.
expected := PMComplexNumber one.
self assert: (z raisedTo: 0) equals: expected
]
Loading