Skip to content

Commit 6e0deea

Browse files
The square root of a pure imaginary number is a complex number with positive
real and imaginary parts.
1 parent 6371bfa commit 6e0deea

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,21 @@ PMComplexTest >> testSquareRootOfPositiveRealNumberIsAComplexNumberWithOnlyAReal
638638
self assert: squareRoot equals: expected
639639
]
640640

641+
{ #category : #tests }
642+
PMComplexTest >> testSquareRootOfPureImaginaryNumberIsAComplexNumberWithRealAndImaginaryParts [
643+
644+
"e.g. square root of 4 i = root(2) + i root(2)"
645+
646+
| squareRoot expected pureImaginaryNumber |
647+
pureImaginaryNumber := PMComplex real: 0 imaginary: 4.
648+
649+
squareRoot := pureImaginaryNumber sqrt.
650+
651+
expected := 2 sqrt + 2 sqrt i.
652+
self assert: squareRoot real closeTo: expected real.
653+
self assert: squareRoot imaginary closeTo: expected imaginary
654+
]
655+
641656
{ #category : #tests }
642657
PMComplexTest >> testSquareRootOfZeroIsZero [
643658
"comment stating purpose of instance-side method"

0 commit comments

Comments
 (0)