RegressionTests__QDoubleTests.st
changeset 1606 148c8253d741
child 1607 00dc6d97bc10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RegressionTests__QDoubleTests.st	Tue Jun 13 09:04:15 2017 +0200
@@ -0,0 +1,110 @@
+"{ Package: 'stx:goodies/regression' }"
+
+"{ NameSpace: RegressionTests }"
+
+TestCase subclass:#QDoubleTests
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'tests-regression'
+!
+
+!QDoubleTests class methodsFor:'documentation'!
+
+documentation
+"
+    documentation to be added.
+
+    [author:]
+        cg
+
+    [instance variables:]
+
+    [class variables:]
+
+    [see also:]
+
+"
+! !
+
+!QDoubleTests methodsFor:'tests'!
+
+test_01_instance_creation
+    |d|
+
+    d := QDouble fromFloat:1.0.
+
+    "
+     self run:#test_01_instance_creation
+     self new test_01_instance_creation
+    "
+
+    "Created: / 12-06-2017 / 17:03:46 / cg"
+    "Modified: / 12-06-2017 / 18:41:14 / cg"
+!
+
+test_02_addition
+    |d1 d2 l1 l2 sum_l q1 q2 sum_d sum_q|
+
+    d1 := 1.0.
+    d2 := 1.0e-16.
+    sum_d := d1 + d2.
+    "/ precision is lost with doubles!!
+    self assert:( sum_d - 1.0 = 0.0 ).
+    
+    l1 := 1.0 asLongFloat.
+    l2 := 1.0e-16 asLongFloat.
+    sum_l := l1 + l2.
+    "/ no precision is lost with long doubles!!
+    self assert:( (sum_l - (1.0 asLongFloat)) > 0.0 ).
+
+    q1 := QDouble fromFloat:1.0.
+    q2 := QDouble fromFloat:1.0e-16.
+
+    sum_q := q1 + q2.
+    
+    "
+     self run:#test_02_addition
+     self new test_02_addition
+    "
+
+    "Created: / 12-06-2017 / 17:05:07 / cg"
+    "Modified: / 12-06-2017 / 18:41:25 / cg"
+!
+
+test_03_subtract
+    |d1 d2 l1 l2 diff_l q1 q2 diff_d diff_q|
+
+    d1 := 1.0.
+    d2 := 0.99999.
+    diff_d := d1 - d2.
+    "/ precision is lost with doubles!!
+    
+    l1 := 1.0 asLongFloat.
+    l2 := 0.99999 asLongFloat.
+    diff_l := l1 - l2.
+    "/ no precision is lost with long doubles!!
+
+    q1 := QDouble fromFloat:1.0.
+    q2 := QDouble fromFloat:0.99999.
+
+    diff_q := q1 - q2.
+    
+    "
+     self run:#test_03_subtract
+     self new test_03_subtract
+    "
+
+    "Created: / 12-06-2017 / 23:12:00 / cg"
+! !
+
+!QDoubleTests class methodsFor:'documentation'!
+
+version
+    ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
+! !
+