#QUALITY by cg
class: RegressionTests::TimeDurationTest
added:
#test_01_Addition
#test_02_Subtraction
#test_03_Multiplication
#test_04_Division
#test_05_Division
removed:
#test_01_Arithmetic
#test_02_Arithmetic
comment/format in: #test_03_Arithmetic
--- a/RegressionTests__TimeDurationTest.st Thu May 10 13:02:58 2018 +0200
+++ b/RegressionTests__TimeDurationTest.st Thu May 10 14:25:34 2018 +0200
@@ -77,7 +77,7 @@
"
!
-test_01_Arithmetic
+test_01_Addition
|t1 t2 sum|
t1 := TimeDuration fromSeconds:1.
@@ -108,11 +108,11 @@
"
- self new test_01_Arithmetic
+ self new test_01_Addition
"
!
-test_02_Arithmetic
+test_02_Subtraction
|t1 t2 sum|
t1 := TimeDuration fromSeconds:1.
@@ -143,7 +143,135 @@
"
- self new test_01_Arithmetic
+ self new test_01_Subtraction
+ "
+!
+
+test_03_Multiplication
+ |t rslt|
+
+ t := TimeDuration fromSeconds:1.
+ rslt := t * 5.
+ self assert:(rslt asMilliseconds == 5000).
+ self assert:(rslt asPicoseconds = 5000000000000).
+
+ rslt := 5 * t.
+ self assert:(rslt asMilliseconds == 5000).
+ self assert:(rslt asPicoseconds = 5000000000000).
+
+
+ t := TimeDuration fromSeconds:1.1.
+ rslt := t * 2.
+ self assert:(rslt asMilliseconds == 2200).
+ self assert:(rslt asPicoseconds = 2200000000000).
+
+ rslt := 2 * t.
+ self assert:(rslt asMilliseconds == 2200).
+ self assert:(rslt asPicoseconds = 2200000000000).
+
+
+ t := TimeDuration fromNanoseconds:100.
+ rslt := t * 4.5.
+ self assert:(rslt asNanoseconds = 450).
+ self assert:(rslt asPicoseconds = 450000).
+
+ rslt := 4.5 * t.
+ self assert:(rslt asNanoseconds = 450).
+ self assert:(rslt asPicoseconds = 450000).
+
+
+ t := TimeDuration fromMilliseconds:100.
+ t := t + 50 nanoseconds.
+
+ rslt := t * 5.
+ self assert:(rslt asNanoseconds = 500000250).
+
+ rslt := 5 * t.
+ self assert:(rslt asNanoseconds = 500000250).
+
+
+ "
+ self new test_03_Multiplication
+ "
+!
+
+test_04_Division
+ |t rslt|
+
+ t := TimeDuration fromSeconds:1.
+ rslt := t / 5.
+ self assert:(rslt asMilliseconds == 200).
+ self assert:(rslt asPicoseconds = 200000000000).
+
+
+ t := TimeDuration fromSeconds:2.2.
+ rslt := t / 2.
+ self assert:(rslt asMilliseconds == 1100).
+ self assert:(rslt asPicoseconds = 1100000000000).
+
+
+ t := TimeDuration fromNanoseconds:450.
+ rslt := t / 4.5.
+ self assert:(rslt asNanoseconds = 100).
+ self assert:(rslt asPicoseconds = 100000).
+
+
+ t := TimeDuration fromMilliseconds:100.
+ t := t + 50 nanoseconds.
+
+ rslt := t / 5.
+ self assert:(rslt asNanoseconds = 20000010).
+
+
+ "
+ self new test_04_Division
+ "
+!
+
+test_05_Division
+ "dividing two timeDurations gives a numeric quotient"
+
+ |t1 t2 rslt|
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromSeconds:2.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 0.5).
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromMilliseconds:1.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 1000).
+
+ t1 := TimeDuration fromMilliseconds:1.
+ t2 := TimeDuration fromMicroseconds:1.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 1000).
+
+ t1 := TimeDuration fromMicroseconds:1.
+ t2 := TimeDuration fromNanoseconds:1.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 1000).
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromNanoseconds:1.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 1000000000).
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromNanoseconds:50.
+ rslt := t1 / t2.
+ self assert:(rslt isNumber).
+ self assert:(rslt = 20000000).
+
+
+ "
+ self new test_05_Division
"
!