RegressionTests__TimeDurationTest.st
changeset 1918 208bd3c139d3
parent 1447 2351db93aa5b
child 1919 2a68b01c7f02
equal deleted inserted replaced
1917:46bcef094b5d 1918:208bd3c139d3
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "{ Package: 'stx:goodies/regression' }"
     3 "{ Package: 'stx:goodies/regression' }"
     2 
     4 
     3 "{ NameSpace: RegressionTests }"
     5 "{ NameSpace: RegressionTests }"
     4 
     6 
     5 TestCase subclass:#TimeDurationTest
     7 TestCase subclass:#TimeDurationTest
    10 !
    12 !
    11 
    13 
    12 
    14 
    13 !TimeDurationTest methodsFor:'Testing'!
    15 !TimeDurationTest methodsFor:'Testing'!
    14 
    16 
    15 test_01_PrintingReading
    17 test_00_Reading
       
    18     |t1 t2|
       
    19 
       
    20     t2 := TimeDuration fromString:'1.001s'.
       
    21     self assert:(t2 asMilliseconds == 1001).
       
    22 
       
    23     t1 := TimeDuration fromString:'1001ms'.
       
    24     self assert:(t1 asMilliseconds = 1001).
       
    25 
       
    26     t1 := TimeDuration fromString:'1001ns'.
       
    27     self assert:(t1 asNanoseconds = 1001).
       
    28 
       
    29     t1 := TimeDuration fromString:'1001us'.
       
    30     self assert:(t1 asMicroseconds = 1001).
       
    31 
       
    32     t1 := TimeDuration fromString:'1s 30us'.
       
    33     self assert:(t1 asMicroseconds = 1000030).
       
    34 
       
    35     t1 := TimeDuration fromString:'01:30:33'.
       
    36     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    37     self assert:(t1 asMilliseconds = (((1*3600)+(30*60)+33)*1000)).
       
    38 
       
    39     t1 := TimeDuration fromString:'01:30:33,5'.
       
    40     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    41     self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+500)).
       
    42 
       
    43     t1 := TimeDuration fromString:'01:30:33,05'.
       
    44     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    45     self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+50)).
       
    46 
       
    47     t1 := TimeDuration fromString:'01:30:33,005'.
       
    48     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    49     self assert:(t1 asMilliseconds = ((((1*3600)+(30*60)+33)*1000)+5)).
       
    50 
       
    51     t1 := TimeDuration fromString:'01:30:33,0005'.
       
    52     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    53     self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+500)).
       
    54 
       
    55     t1 := TimeDuration fromString:'01:30:33,00005'.
       
    56     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    57     self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+50)).
       
    58 
       
    59     t1 := TimeDuration fromString:'01:30:33,000005'.
       
    60     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    61     self assert:(t1 asMicroseconds = ((((1*3600)+(30*60)+33)*1000*1000)+5)).
       
    62 
       
    63     t1 := TimeDuration fromString:'01:30:33,0000005'.
       
    64     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    65     self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+500)).
       
    66 
       
    67     t1 := TimeDuration fromString:'01:30:33,00000005'.
       
    68     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    69     self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+50)).
       
    70 
       
    71     t1 := TimeDuration fromString:'01:30:33,000000005'.
       
    72     self assert:(t1 asSeconds = ((1*3600)+(30*60)+33)).
       
    73     self assert:(t1 asNanoseconds = ((((1*3600)+(30*60)+33)*1000*1000*1000)+5)).
       
    74 
       
    75     "
       
    76      self new test_00_Reading
       
    77     "
       
    78 !
       
    79 
       
    80 test_10_PrintingReading
    16      #(
    81      #(
    17 	(0 0 0 0)
    82         "/ hours minutes seconds millis
    18 	(0 0 0 1)
    83         (0 0 0 0)
    19 	(0 0 0 9)
    84         (0 0 0 1)
    20 	(0 0 0 10)
    85         (0 0 0 9)
    21 	(0 0 0 11)
    86         (0 0 0 10)
    22 	(0 0 0 99)
    87         (0 0 0 11)
    23 	(0 0 0 100)
    88         (0 0 0 99)
    24 	(0 0 0 101)
    89         (0 0 0 100)
    25 	(0 0 0 999)
    90         (0 0 0 101)
    26 	(0 0 0 1000)
    91         (0 0 0 999)
    27 	(0 0 0 1001)
    92         (0 0 0 1000)
       
    93         (0 0 0 1001)
    28 
    94 
    29 	(0 33 0 123)
    95         (0 33 0 123)
    30 	(2 0 0 123)
    96         (2 0 0 123)
    31 	(2 33 0 123)
    97         (2 33 0 123)
    32 	(100 33 0 123)
    98         (100 33 0 123)
    33 	(10000 33 0 123)
    99         (10000 33 0 123)
    34 	(1000000 33 0 123)
   100         (1000000 33 0 123)
    35 
   101 
    36 	(2 33 0 0)
   102         (2 33 0 0)
    37 	(2 0 0 0)
   103         (2 0 0 0)
    38 	(24 0 0 0)
   104         (24 0 0 0)
    39 	(0 0 0 123)
   105         (0 0 0 123)
    40     ) do:[:hmsms |
   106     ) do:[:hmsms |
    41 	|h m s ms d1 d2 s1 s2|
   107         |h m s ms d1 d2 s1 s2|
    42 
   108 
    43 	h := hmsms first.
   109         h := hmsms first.
    44 	m := hmsms second.
   110         m := hmsms second.
    45 	s := hmsms third.
   111         s := hmsms third.
    46 	ms := hmsms fourth.
   112         ms := hmsms fourth.
    47 	d1 := TimeDuration hours:h minutes:m seconds:s milliseconds:ms.
   113         "/ generate a duration
    48 	s1 := d1 printString.
   114         d1 := TimeDuration hours:h minutes:m seconds:s milliseconds:ms.
    49 	d2 := TimeDuration readFrom:s1.
   115         "/ print it
    50 	s2 := d2 printString.
   116         s1 := d1 printString.
    51 	self assert:(d1 = d2).
   117         "/ read it back
    52 	self assert:(d1 timeEncoding = d2 timeEncoding).
   118         d2 := TimeDuration readFrom:s1.
    53 	self assert:(s1 = s2).
   119         s2 := d2 printString.
       
   120         "/ same time?
       
   121         self assert:(d1 = d2).
       
   122         self assert:(d1 timeEncoding = d2 timeEncoding).
       
   123         "/ same string?
       
   124         self assert:(s1 = s2).
    54      ].
   125      ].
    55 
   126 
    56 
   127 
    57 "/     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
   128 "/     (TimeDuration hours:0 minutes:0 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
    58 "/     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringFormat:'%h:%m:%s'
   129 "/     (TimeDuration hours:0 minutes:0 seconds:10 milliseconds:123) printStringFormat:'%h:%m:%s'
    61 "/     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
   132 "/     (TimeDuration hours:100 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
    62 "/     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
   133 "/     (TimeDuration hours:10000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
    63 "/     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
   134 "/     (TimeDuration hours:1000000 minutes:33 seconds:0 milliseconds:123) printStringFormat:'%h:%m:%s'
    64 
   135 
    65     "
   136     "
    66      self new test_01_PrintingReading
   137      self new test_10_PrintingReading
    67     "
   138     "
    68 
   139 
    69     "Created: / 18-07-2007 / 14:02:01 / cg"
   140     "Created: / 18-07-2007 / 14:02:01 / cg"
    70 ! !
   141 ! !
    71 
   142