'From Squeak3.7beta of ''1 April 2004'' [latest update: #5972] on 17 July 2004 at 6:39:02 pm'!
"Change Set:		ComplexTests
Date:			17 July 2004
Author:			stephane ducasse

Some tests for complex. Marcus is willing to bring in complex numbers and here are a couple of tests I wrote while reading the complex class developed by Matej Kosik.
Pay attention reciprocal raise a ZeroDivide exception and not an Error as before to conform with Number class reciprocal"!


!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:00'!
testAbs
	"self run: #testAbs"
	"self debug: #testAbs"
	
	| c |
	c := (6 - 6 i).
	self assert: c abs  = 72 sqrt.
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 13:59'!
testAdding
	"self run: #testAdding"
	
	| c |
	c := (5 - 6 i) + (-5 + 8 i).     "Complex with Complex"
	self assert: (c =  (0 + 2 i)).! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:02'!
testArg
	"self run: #testArg"
	"self debug: #testArg"
	
	| c |
	c := (0 + 5 i) .
	self assert: c arg  = (Float pi/ 2).
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:13'!
testComplexCollection
	"self run: #testComplexCollection"
	"self debug: #testComplexCollection"
	
	| array array2 |
	array := Array with: 1 + 2i with:  3 + 4i with: 5 + 6i.
	array2 := 2 * array.
	array with:  array2 do: [:one :two | self assert: (2 * one) = two ] ! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:16'!
testConversion
	"self run: #testConversion"
	"self debug: #testConversion"
	
	self assert: ((1 + 2i) + 1) =  (2 + 2 i).
	self assert: (1 + (1 + 2i)) =  (2 + 2 i).
	self assert: ((1 + 2i) + 1.0) =  (2.0 + 2 i).
	self assert: (1.0 + (1 + 2i)) =  (2.0 + 2 i).
	self assert: ((1 + 2i) + (2/3)) = ((5/3) + 2 i ).
	self assert: ((2/3) + (1 + 2i)) = ((5/3) + 2 i )! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 13:59'!
testCreation
	"self run: #testCreation"
	
	| c |
	c := 5 i.
	self assert: (c real = 0).
	self assert: (c imaginary = 5).
	
	c := 6 + 7 i.
	self assert: (c real = 6).
	self assert: ( c imaginary = 7).
	
	c := 5.6 - 8 i.
	self assert: (c real = 5.6).
	self assert: (c imaginary = -8).
	
	c := Complex real: 10 imaginary: 5.
	self assert: (c real = 10).
	self assert: (c imaginary = 5).
	
	c := Complex abs: 5 arg: (Float pi/2).
	self assert: (c real rounded = 0).
	self assert: (c imaginary = 5).
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:10'!
testEquality
	"self run: #testEquality"
	"self debug: #testEquality"
	
	self assert: 0i = 0.
	self assert: (2 - 5i) = ((1 -4 i) + (1 - 1i)).
	self assert: 0i isZero.
	self deny: (1 + 3 i) = 1.
	self deny: (1 + 3 i) = (1 + 2i).! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 13:55'!
testInfiniteInterface
	"self run: #testInfiniteInterface"
	
	| c |
	c := 1 i + 2.
	self deny: c isInfinite.
	self deny: c isNaN.
	self deny: c isInf! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:03'!
testNegated
	"self run: #testNegated"
	"self debug: #testNegated"
	
	| c |
	c := (2 + 5 i) .
	self assert: c negated  = (-2 - 5i).
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:05'!
testReciprocal
	"self run: #testReciprocal"
	"self debug: #testReciprocal"
	
	| c |
	c := (2 + 5 i).
	self assert: c reciprocal  = ((2/29) - (5/29)i).
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 14:07'!
testReciprocalError
	"self run: #testReciprocalError"
	"self debug: #testReciprocalError"
	
	| c |
	c := (0 i).
	self should: [c reciprocal] raise: ZeroDivide
	! !

!ComplexTest methodsFor: 'testing' stamp: 'sd 7/17/2004 13:24'!
testSquared
	"self run: #testSquared"
	"self debug: #testSquared"
	
	| c c2 |
	c := (6 - 6 i).
	c2 := (c squared).
	self assert: c2 imaginary = -72.
	self assert: c2 real = 0.! !

ComplexTest removeSelector: #testModulo!
ComplexTest removeSelector: #testReprocical!
