--- a/RegressionTests__TimeDurationTest.st Thu May 10 02:06:08 2018 +0200
+++ b/RegressionTests__TimeDurationTest.st Thu May 10 12:44:54 2018 +0200
@@ -18,12 +18,23 @@
|t|
t := TimeDuration fromSeconds:1.
+ self assert:(t asSeconds = 1).
self assert:(t asMilliseconds == 1000).
self assert:(t asMicroseconds = 1000000).
self assert:(t asNanoseconds = 1000000000).
self assert:(t asPicoseconds = 1000000000000).
+ t := TimeDuration fromSeconds:1.5.
+ self assert:(t asSeconds = 1).
+ self assert:(t asTruncatedSeconds == 1).
+ self assert:(t asExactSeconds = 1.5).
+ self assert:(t asMilliseconds == 1500).
+ self assert:(t asMicroseconds = 1500000).
+ self assert:(t asNanoseconds = 1500000000).
+ self assert:(t asPicoseconds = 1500000000000).
+
t := TimeDuration fromMilliseconds:345.
+ self assert:(t asSeconds = 0).
self assert:(t asExactSeconds = 0.345).
self assert:(t asTruncatedSeconds = 0).
self assert:(t asMilliseconds == 345).
@@ -34,6 +45,7 @@
t := TimeDuration fromMicroseconds:345.
self assert:(t asExactSeconds = 0.000345).
self assert:(t asTruncatedSeconds = 0).
+ self assert:(t asExactMilliseconds = 0.345).
self assert:(t asTruncatedMilliseconds == 0).
self assert:(t asMicroseconds = 345).
self assert:(t asNanoseconds = 345000).
@@ -43,15 +55,20 @@
self assert:(t asExactSeconds = 0.000000345).
self assert:(t asTruncatedSeconds = 0).
self assert:(t asTruncatedMilliseconds == 0).
+ self assert:(t asExactMilliseconds = 0.000345).
self assert:(t asTruncatedMicroseconds = 0).
+ self assert:(t asExactMicroseconds = 0.345).
self assert:(t asNanoseconds = 345).
self assert:(t asPicoseconds = 345000).
t := TimeDuration fromPicoseconds:345.
self assert:(t asExactSeconds = 0.000000000345).
self assert:(t asTruncatedSeconds = 0).
+ self assert:(t asExactMilliseconds = 0.000000345).
self assert:(t asTruncatedMilliseconds == 0).
+ self assert:(t asExactMicroseconds = 0.000345).
self assert:(t asTruncatedMicroseconds = 0).
+ self assert:(t asExactNanoseconds = 0.345).
self assert:(t asTruncatedNanoseconds = 0).
self assert:(t asPicoseconds = 345).
@@ -60,7 +77,35 @@
"
!
-test_00_Reading
+test_01_Arithmetic
+ |t1 t2 sum|
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromMilliseconds:1.
+ sum := t1 + t2.
+
+ self assert:(sum asMilliseconds == 1001).
+ self assert:(sum asMicroseconds = 1001000).
+ self assert:(sum asNanoseconds = 1001000000).
+ self assert:(sum asPicoseconds = 1001000000000).
+
+
+ t1 := TimeDuration fromSeconds:1.
+ t2 := TimeDuration fromMicroseconds:1.
+ sum := t1 + t2.
+
+ self assert:(sum asMilliseconds == 1000).
+ self assert:(sum asMicroseconds = 1000001).
+ self assert:(sum asNanoseconds = 1000001000).
+ self assert:(sum asPicoseconds = 1000001000000).
+
+
+ "
+ self new test_01_Arithmetic
+ "
+!
+
+test_05_Reading
|t1 t2|
t2 := TimeDuration fromString:'1.001s'.
@@ -81,10 +126,26 @@
t1 := TimeDuration fromString:'1s 30us'.
self assert:(t1 asMicroseconds = 1000030).
+ t1 := TimeDuration fromString:'0.1s'.
+ self assert:(t1 asMilliseconds = 100).
+ t1 := TimeDuration fromString:'0.1ms'.
+ self assert:(t1 asMicroseconds = 100).
+ t1 := TimeDuration fromString:'0.1us'.
+ self assert:(t1 asNanoseconds = 100).
+ t1 := TimeDuration fromString:'0.1ns'.
+ self assert:(t1 asPicoseconds = 100).
+
+ t1 := TimeDuration fromString:'0,1ns'.
+ self assert:(t1 asPicoseconds = 100).
+
t1 := TimeDuration fromString:'01:30:33'.
self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
self assert:(t1 asMilliseconds = (((1*3600)+(30*60)+33)*1000)).
+ t1 := TimeDuration fromString:'01:30:33.5'.
+ self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
+ self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+500)).
+
t1 := TimeDuration fromString:'01:30:33,5'.
self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+500)).
@@ -121,71 +182,18 @@
self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+5)).
- "
- self new test_00_Reading
- "
-!
-
-test_05_Reading
- |t1 t2|
-
- t2 := TimeDuration fromString:'1.001s'.
- self assert:(t2 asMilliseconds == 1001).
-
- t1 := TimeDuration fromString:'1001ms'.
- self assert:(t1 asMilliseconds = 1001).
+ t1 := TimeDuration fromString:'0.000000005'.
+ self assert:(t1 asNanoseconds = 5).
- t1 := TimeDuration fromString:'1001ns'.
- self assert:(t1 asNanoseconds = 1001).
-
- t1 := TimeDuration fromString:'1001us'.
- self assert:(t1 asMicroseconds = 1001).
-
- t1 := TimeDuration fromString:'1001ps'.
- self assert:(t1 asPicoseconds = 1001).
-
- t1 := TimeDuration fromString:'1s 30us'.
- self assert:(t1 asMicroseconds = 1000030).
-
- t1 := TimeDuration fromString:'01:30:33'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMilliseconds = (((1*3600)+(30*60)+33)*1000)).
+ t1 := TimeDuration fromString:'0.000000005s'.
+ self assert:(t1 asNanoseconds = 5).
- t1 := TimeDuration fromString:'01:30:33,5'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+500)).
-
- t1 := TimeDuration fromString:'01:30:33,05'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+50)).
-
- t1 := TimeDuration fromString:'01:30:33,005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+5)).
-
- t1 := TimeDuration fromString:'01:30:33,0005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+500)).
+ t1 := TimeDuration fromString:'1d 5h'.
+ self assert:(t1 asTruncatedHours = 29).
- t1 := TimeDuration fromString:'01:30:33,00005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+50)).
-
- t1 := TimeDuration fromString:'01:30:33,000005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+5)).
-
- t1 := TimeDuration fromString:'01:30:33,0000005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+500)).
-
- t1 := TimeDuration fromString:'01:30:33,00000005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+50)).
-
- t1 := TimeDuration fromString:'01:30:33,000000005'.
- self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
- self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+5)).
+ t1 := TimeDuration fromString:'1d 5h 30m'.
+ self assert:(t1 asTruncatedHours = 29).
+ self assert:(t1 asExactHours = 29.5).
"
self new test_05_Reading