more coverage
authorClaus Gittinger <cg@exept.de>
Mon, 03 May 2010 18:09:17 +0200
changeset 566 229e35dc2657
parent 565 4fcc34472bd1
child 567 e245ebd95922
more coverage
RegressionTests__ComplexTest.st
--- a/RegressionTests__ComplexTest.st	Tue Apr 27 10:47:55 2010 +0200
+++ b/RegressionTests__ComplexTest.st	Mon May 03 18:09:17 2010 +0200
@@ -10,6 +10,15 @@
 !
 
 
+!ComplexTest class methodsFor:'accessing'!
+
+testedClasses
+    "for the browser and for coverage analysis:
+     return a collection of classNames, which are tested by this testCase"
+
+    ^ #( Complex )
+! !
+
 !ComplexTest methodsFor:'tests'!
 
 testAbs
@@ -35,7 +44,12 @@
     self should: [ (c1 + c2) = (Complex real: 4 imaginary: 6) ].
 
     c3 := (5 - 6 i) + (-5 + 8 i).     "Complex with Complex"
-    self assert: (c3 =  (0 + 2 i)).
+    self assert: (c3 = (0 + 2 i)).
+
+    self assert: (c1 + 1)   = (2 + 2 i).
+    self assert: (c1 + 1.0) = (2 + 2 i).
+    self assert: (1 + c1) = (2 + 2 i).
+    self assert: (1.0 + c1) = (2 + 2 i).
 
     "
      self run: #testAddition
@@ -43,6 +57,95 @@
     "
 !
 
+testAngle
+    | c |
+
+    c := (1 + 1 i).
+    self assert: (c angle radiansToDegrees rounded = 45).
+    self assert: (c asPoint x = 1).
+    self assert: (c asPoint y = 1).
+
+    c := (-1 + 1 i).
+    self assert: (c angle radiansToDegrees rounded = 135).
+    self assert: (c asPoint x = -1).
+    self assert: (c asPoint y = 1).
+
+    c := (-1 - 1 i).
+    self assert: (c angle radiansToDegrees rounded = -135).
+    self assert: (c asPoint x = -1).
+    self assert: (c asPoint y = -1).
+
+    "
+     self new testAngle
+
+     self run: #testAngle
+     self debug: #testAngle
+    "
+!
+
+testCompare
+    | c1 c2 |
+
+    c1 := Complex real: 1 imaginary: 2.
+    c2 := Complex real: 3 imaginary: 4.
+
+    self assert: ( c1 ~= c2 ).
+    self assert: ( c1 = c2 ) not.
+
+    self should: [ c1 < c2 ] raise: Exception.
+    self should: [ c1 <= c2 ] raise: Exception.
+    self should: [ c1 >= c2 ] raise: Exception.
+    self should: [ c1 > c2 ] raise: Exception.
+
+    c1 := Complex fromReal: 1.
+
+    self assert: ( c1 = 1 ).
+    self assert: ( c1 = 1.0 ).
+    self assert: ( c1 ~= 2 ).
+    self assert: ( c1 ~= 2.0 ).
+
+    self assert: ( 1 = c1 ).
+    self assert: ( 1.0 = c1 ).
+    self assert: ( 2 ~= c1 ).
+    self assert: ( 2.0 ~= c1 ).
+!
+
+testConjugated
+    | c |
+
+    c := (2 + 5 i) .
+    self assert: c conjugated  = (2 - 5i).
+
+    "
+     self run: #testConjugated
+     self new testConjugated
+    "
+!
+
+testConversion
+    | c |
+
+    c := Complex fromReal:1.
+    self assert: (c asComplex = c).
+    self assert: (c asFloat = 1).
+    self assert: (c asInteger = 1).
+    self assert: (c asPoint = (1@0) ).
+
+    c := (1 + 1 i).
+    self assert: (c asComplex = c).
+    self should:[ c asFloat ] raise:Exception.
+    self should:[ c asInteger ] raise:Exception.
+    self assert: (c isComplex ).
+    self assert: (c asPoint = (1@1) ).
+
+    "
+     self new testConversion
+
+     self run: #testConversion
+     self debug: #testConversion
+    "
+!
+
 testCreation
     | c |
 
@@ -182,17 +285,19 @@
 !
 
 testMultiplication
-	| c1 c2 |
+    | c1 c2 |
 
-	self shouldnt: [ c1 := Complex real: 1 imaginary: 2 ] raise: Exception.
-	self shouldnt: [ c2 := Complex real: 3 imaginary: 4 ] raise: Exception.
+    self shouldnt: [ c1 := Complex real: 1 imaginary: 2 ] raise: Exception.
+    self shouldnt: [ c2 := Complex real: 3 imaginary: 4 ] raise: Exception.
 
-	self should: [ (c1 * c2) = (Complex real: -5 imaginary: 10) ].
-	self should: [ (c1 * Complex zero) = Complex zero ].
+    self should: [ (c1 * c2) = (Complex real: -5 imaginary: 10) ].
+    self should: [ (c1 * Complex zero) = Complex zero ].
 
-	self should: [ c1 * 5 = (Complex real: 5 imaginary: 10) ].
-	self should: [ c1 * 1.1 = (Complex real: 1.1 imaginary: 2.2) ].
-	self should: [ c1 * (2/3) = (Complex real: 2/3 imaginary: 4/3) ].
+    self should: [ c1 * 5 = (Complex real: 5 imaginary: 10) ].
+    self should: [ c1 * 1.1 = (Complex real: 1.1 imaginary: 2.2) ].
+    self should: [ c1 * (2/3) = (Complex real: 2/3 imaginary: 4/3) ].
+
+    self assert:( 1.0 * c1 = c1 ).
 !
 
 testNegated
@@ -280,12 +385,16 @@
 !
 
 testSubtraction
-	| c1 c2 |
+    | c1 c2 |
+
+    self shouldnt: [ c1 := Complex real: 1 imaginary: 2 ] raise: Exception.
+    self shouldnt: [ c2 := Complex real: 3 imaginary: 4 ] raise: Exception.
 
-	self shouldnt: [ c1 := Complex real: 1 imaginary: 2 ] raise: Exception.
-	self shouldnt: [ c2 := Complex real: 3 imaginary: 4 ] raise: Exception.
+    self should: [ (c1 - c2) = (Complex real: -2 imaginary: -2) ].
 
-	self should: [ (c1 - c2) = (Complex real: -2 imaginary: -2) ].
+    self assert: ( (c1 - 1.0) = (Complex real: 0 imaginary: 2) ).
+    self assert: ( (1.0 - c1) = (Complex real: 0 imaginary: -2) ).
+    self assert: ( (1.0 - (Complex fromReal:1.0)) = 0 ).
 !
 
 xxtestSecureDivision1
@@ -318,4 +427,8 @@
 
 version
     ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
 ! !