Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.core.simpletypes.temporal;

import junit.framework.*;

public class SimpleTimeTest extends TestCase
{
    public static TestSuite suite()
    {
        return new TestSuite( SimpleTimeTest.class );
    }

    public SimpleTimeTest( String name )
    {
        super( name );
    }

    public static void main( String[] args )
    {
        junit.textui.TestRunner.run( suite() );
    }

    public void test_Contructors_Bad()
    {
        // Bad Strings
        chkCB( "1a" );
        chkCB( "12:a" );
        chkCB( "12:3:a" );
        chkCB( "12:3:4.a" );
        // Missing Parts
        chkCB( "12:" );
        chkCB( "12:2:" );
        chkCB( "12:2:3." );
        // Bad Times
        chkCB( "24" );
        chkCB( "12:-1" );
        chkCB( "12:60" );
        chkCB( "12:60:1" );
        chkCB( "12:34:70" );
        chkCB( "12:1:0.-1" );
        chkCB( "12:1:0.9999" );
    }

    private void chkCB( String pToString )
    {
        try
        {
            SimpleTime.fromString( pToString );
            fail( "Did not fail : fromString( \"" + pToString + "\" )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // Expected
        }
    }

    public void test_rtString()
    {
        chkRT( "1", "01", TimeRes.ToHOUR );
        chkRT( "12:2", "12:02", TimeRes.ToMIN );
        chkRT( "12:2:1", "12:02:01", TimeRes.ToSEC );
        chkRT( "12:12:1.23", "12:12:01.023", TimeRes.ToMSEC );
        chkRT( "12:1:1", "12:01:01", TimeRes.ToSEC );
        chkRT( "12:1:31", "12:01:31", TimeRes.ToSEC );
        chkRT( "12:59:31.467", "12:59:31.467", TimeRes.ToMSEC );
        chkRT( "0:0:0.0", "00:00:00.000", TimeRes.ToMSEC );
        chkRT( "23:59:59.999", "23:59:59.999", TimeRes.ToMSEC );
    }

    private void chkRT( String pToString, String pFromString, TimeRes pTimeResExpected )
    {
        SimpleTime sd = SimpleTime.fromString( pToString );
        assertEquals( pFromString, sd.toString() );
        assertEquals( pTimeResExpected, sd.getTimeRes() );
    }

    public void test_ContructorsAndToString()
            throws Exception
    {
        chk( new SimpleTime( 0 ), "00", 0, 0, 0, 0 );
        chk( new SimpleTime( 12 ), "12", 12, 0, 0, 0 );
        chk( new SimpleTime( 23 ), "23", 23, 0, 0, 0 );

        chk( new SimpleTime( 0, 0 ), "00:00", 0, 0, 0, 0 );
        chk( new SimpleTime( 0, 59 ), "00:59", 0, 59, 0, 0 );
        chk( new SimpleTime( 23, 59 ), "23:59", 23, 59, 0, 0 );
        chk( new SimpleTime( 23, 0 ), "23:00", 23, 0, 0, 0 );

        chk( new SimpleTime( 0, 0, 0 ), "00:00:00", 0, 0, 0, 0 );
        chk( new SimpleTime( 0, 0, 59 ), "00:00:59", 0, 0, 59, 0 );
        chk( new SimpleTime( 0, 59, 0 ), "00:59:00", 0, 59, 0, 0 );
        chk( new SimpleTime( 0, 59, 59 ), "00:59:59", 0, 59, 59, 0 );
        chk( new SimpleTime( 23, 0, 0 ), "23:00:00", 23, 0, 0, 0 );
        chk( new SimpleTime( 23, 0, 59 ), "23:00:59", 23, 0, 59, 0 );
        chk( new SimpleTime( 23, 59, 0 ), "23:59:00", 23, 59, 0, 0 );
        chk( new SimpleTime( 23, 59, 59 ), "23:59:59", 23, 59, 59, 0 );

        chk( new SimpleTime( 0, 0, 0, 0 ), "00:00:00.000", 0, 0, 0, 0 );
        chk( new SimpleTime( 0, 0, 0, 999 ), "00:00:00.999", 0, 0, 0, 999 );
        chk( new SimpleTime( 0, 0, 59, 0 ), "00:00:59.000", 0, 0, 59, 0 );
        chk( new SimpleTime( 0, 0, 59, 999 ), "00:00:59.999", 0, 0, 59, 999 );
        chk( new SimpleTime( 0, 59, 0, 0 ), "00:59:00.000", 0, 59, 0, 0 );
        chk( new SimpleTime( 0, 59, 0, 999 ), "00:59:00.999", 0, 59, 0, 999 );
        chk( new SimpleTime( 0, 59, 59, 0 ), "00:59:59.000", 0, 59, 59, 0 );
        chk( new SimpleTime( 0, 59, 59, 999 ), "00:59:59.999", 0, 59, 59, 999 );
        chk( new SimpleTime( 23, 0, 0, 0 ), "23:00:00.000", 23, 0, 0, 0 );
        chk( new SimpleTime( 23, 0, 0, 999 ), "23:00:00.999", 23, 0, 0, 999 );
        chk( new SimpleTime( 23, 0, 59, 0 ), "23:00:59.000", 23, 0, 59, 0 );
        chk( new SimpleTime( 23, 0, 59, 999 ), "23:00:59.999", 23, 0, 59, 999 );
        chk( new SimpleTime( 23, 59, 0, 0 ), "23:59:00.000", 23, 59, 0, 0 );
        chk( new SimpleTime( 23, 59, 0, 999 ), "23:59:00.999", 23, 59, 0, 999 );
        chk( new SimpleTime( 23, 59, 59, 0 ), "23:59:59.000", 23, 59, 59, 0 );
        chk( new SimpleTime( 23, 59, 59, 999 ), "23:59:59.999", 23, 59, 59, 999 );
    }

    private void chk( SimpleTime pTime, String pToString, int pHour, int pMin, int pSec, int pMilliSec )
    {
        assertEquals( pToString, pTime.toString() );
        assertEquals( "Hour", pHour, pTime.getHour() );
        assertEquals( "Min", pMin, pTime.getMin() );
        assertEquals( "Sec", pSec, pTime.getSec() );
        assertEquals( "MilliSec", pMilliSec, pTime.getMilliSec() );
        SimpleTime st2 = pTime.copy();
        assertEquals( pTime, st2 );
        assertEquals( pToString, st2.toString() );
        assertEquals( "Hour", pHour, st2.getHour() );
        assertEquals( "Min", pMin, st2.getMin() );
        assertEquals( "Sec", pSec, st2.getSec() );
        assertEquals( "MilliSec", pMilliSec, st2.getMilliSec() );
    }

    public void test_copyWithReducedResolution()
    {
        chk_CWRR( "0:0:0.0", TimeRes.ToMSEC, "00:00:00.000" );
        chk_CWRR( "0:0:0.0", TimeRes.ToSEC, "00:00:00" );
        chk_CWRR( "0:0:0.0", TimeRes.ToMIN, "00:00" );
        chk_CWRR( "0:0:0.0", TimeRes.ToHOUR, "00" );
        chk_CWRR( "12:04:30.456", TimeRes.ToMSEC, "12:04:30.456" );
        chk_CWRR( "12:04:30.456", TimeRes.ToSEC, "12:04:30" );
        chk_CWRR( "12:04:30.456", TimeRes.ToMIN, "12:04" );
        chk_CWRR( "12:04:30.456", TimeRes.ToHOUR, "12" );
        chk_CWRR( "04:01:57", TimeRes.ToSEC, "04:01:57" );
        chk_CWRR( "04:01:57", TimeRes.ToMIN, "04:01" );
        chk_CWRR( "04:01:57", TimeRes.ToHOUR, "04" );
        chk_CWRR( "12:02", TimeRes.ToMIN, "12:02" );
        chk_CWRR( "12:02", TimeRes.ToHOUR, "12" );
        chk_CWRR( "12", TimeRes.ToHOUR, "12" );
        chk_CWRR( "12:02:29", TimeRes.ToMSEC );
        chk_CWRR( "12:02", TimeRes.ToSEC );
        chk_CWRR( "12", TimeRes.ToMIN );
    }

    private void chk_CWRR( String pTimeString, TimeRes pSetTo, String pExpectedString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTime sd2 = sd.copyWithReducedResolution( pSetTo );
        assertEquals( pExpectedString, sd2.toString() );
    }

    private void chk_CWRR( String pTimeString, TimeRes pSetTo )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.copyWithReducedResolution( pSetTo );
            fail( "Did Not fail on '" + pTimeString + "': copyWithReducedResolution( " + pSetTo + " )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_timeComponent()
    {
        chk_TC( "00:00:00.000", UtilDateAdaptor.currentWall( 1957, 1, 4, 0, 0, 0, 0 ) );
        chk_TC( "12:02:29.456", UtilDateAdaptor.currentWall( 1957, 1, 4, 12, 2, 29, 456 ) );
        chk_TC( "12:02:29", UtilDateAdaptor.currentWall( 1957, 1, 4, 12, 2, 29 ) );
        chk_TC( "12:02", UtilDateAdaptor.currentWall( 1957, 1, 4, 12, 2 ) );
        chk_TC( "12", UtilDateAdaptor.currentWall( 1957, 1, 4, 12 ) );
    }

    private void chk_TC( String pExpectedString, UtilDateAdaptor pAdaptor )
    {
        SimpleTime sd = SimpleTime.timeComponents( pAdaptor.getTimeRes(), pAdaptor.getWallDate() );
        assertEquals( pExpectedString, sd.toString() );
    }

    public void test_setHour()
    {
        chk_setHour( "04:01:57.123", 7, "07:01:57.123" );
        chk_setHour( "04:01:57", 7, "07:01:57" );
        chk_setHour( "12:04", 4, "04:04" );
        chk_setHour( "12", 4, "04" );
        chk_setHour( "12", -1 );
        chk_setHour( "12", 24 );
    }

    private void chk_setHour( String pTimeString, int pSetTo, String pExpectedString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        sd.setHour( pSetTo );
        assertEquals( pExpectedString, sd.toString() );
    }

    private void chk_setHour( String pTimeString, int pSetTo )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.setHour( pSetTo );
            fail( "Did Not fail on '" + pTimeString + "': setHour( " + pSetTo + " )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_setMin()
    {
        chk_setMin( "04:01", -1 );
        chk_setMin( "04:01", 60 );
        chk_setMin( "04:01:57.123", 12, "04:12:57.123" );
        chk_setMin( "04:01:57", 12, "04:12:57" );
        chk_setMin( "12:04", 1, "12:01" );
        chk_setMin( "20", 4 );
    }

    private void chk_setMin( String pTimeString, int pSetTo, String pExpectedString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        sd.setMin( pSetTo );
        assertEquals( pExpectedString, sd.toString() );
    }

    private void chk_setMin( String pTimeString, int pSetTo )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.setMin( pSetTo );
            fail( "Did Not fail on '" + pTimeString + "': setMin( " + pSetTo + " )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_setSec()
    {
        chk_setSec( "04:01:57", -1 );
        chk_setSec( "04:01:57", 60 );
        chk_setSec( "04:01:57.123", 31, "04:01:31.123" );
        chk_setSec( "12:01:15", 31, "12:01:31" );
        chk_setSec( "07:02", 29 );
        chk_setSec( "02", 30 );
    }

    private void chk_setSec( String pTimeString, int pSetTo, String pExpectedString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        sd.setSec( pSetTo );
        assertEquals( pExpectedString, sd.toString() );
    }

    private void chk_setSec( String pTimeString, int pSetTo )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.setSec( pSetTo );
            fail( "Did Not fail on '" + pTimeString + "': setSec( " + pSetTo + " )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_setMilliSec()
    {
        chk_setMilliSec( "04:01:57.1", -1 );
        chk_setMilliSec( "04:01:57.1", 1000 );
        chk_setMilliSec( "12:01:15.1", 31, "12:01:15.031" );
        chk_setMilliSec( "07:02:28", 29 );
        chk_setMilliSec( "04:02", 30 );
        chk_setMilliSec( "00", 29 );
    }

    private void chk_setMilliSec( String pTimeString, int pSetTo, String pExpectedString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        sd.setMilliSec( pSetTo );
        assertEquals( pExpectedString, sd.toString() );
    }

    private void chk_setMilliSec( String pTimeString, int pSetTo )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.setMilliSec( pSetTo );
            fail( "Did Not fail on '" + pTimeString + "': setMilliSec( " + pSetTo + " )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_addSpan()
    {
        chk_addSpan( "04:01:57.123", "2 3", "07:01:57.123", 2 );
        chk_addSpan( "22:02", "0 10", "08:02", 1 );
    }

    private void chk_addSpan( String pTimeString, String pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTimespan span = SimpleTimespan.fromString( pAdjustBy );
        int zResultDays = sd.add( span );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    public void test_subtractSpan()
    {
        chk_subtractSpan( "07:01:57.123", "2 3", "04:01:57.123", -2 );
        chk_subtractSpan( "08:02", "0 10", "22:02", -1 );
    }

    private void chk_subtractSpan( String pTimeString, String pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTimespan span = SimpleTimespan.fromString( pAdjustBy );
        int zResultDays = sd.subtract( span );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    public void test_addHours()
    {
        chk_addHours( "04:01:57.123", 51, "07:01:57.123", 2 );
        chk_addHours( "12:01:15", -1, "11:01:15", "0 01" );
        chk_addHours( "22:02", 1, "23:02", "0 01" );
        chk_addHours( "22:02", 10, "08:02", 1 );
        chk_addHours( "12", -23, "13", -1 );
    }

    private void chk_addHours( String pTimeString, int pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        int zResultDays = sd.addHours( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    private void chk_addHours( String pTimeString, int pAdjustBy, String pExpectedString, String pDiffString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTime sdOrig = sd.copy();
        assertEquals( sd, sdOrig );
        assertEquals( 0, sd.compareTo( sdOrig ) );
        assertFalse( sd.before( sdOrig ) );
        assertFalse( sd.after( sdOrig ) );
        assertFalse( sdOrig.before( sd ) );
        assertFalse( sdOrig.after( sd ) );
        assertEquals( "0", sd.difference( sdOrig ).toString() );
        int zResultDays = sd.addHours( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( 0, zResultDays );
        assertFalse( sdOrig.equals( sd ) );
        assertEquals( pDiffString, sd.difference( sdOrig ).toString() );
        if ( pAdjustBy > 0 )
        {
            // sdOrig < sd
            assertTrue( 0 > sdOrig.compareTo( sd ) );
            assertTrue( 0 < sd.compareTo( sdOrig ) );
            assertTrue( sdOrig.before( sd ) );
            assertFalse( sdOrig.after( sd ) );
            assertFalse( sd.before( sdOrig ) );
            assertTrue( sd.after( sdOrig ) );
        }
        if ( pAdjustBy < 0 )
        {
            // sdOrig > sd
            assertTrue( 0 < sdOrig.compareTo( sd ) );
            assertTrue( 0 > sd.compareTo( sdOrig ) );
            assertFalse( sdOrig.before( sd ) );
            assertTrue( sdOrig.after( sd ) );
            assertTrue( sd.before( sdOrig ) );
            assertFalse( sd.after( sdOrig ) );
        }
    }

    public void test_addMins()
    {
        chk_addMins( "04:01:57.123", 2, "04:03:57.123", "0 00:02" );
        chk_addMins( "12:01:15", -1, "12:00:15", "0 00:01" );
        chk_addMins( "12:01:15", -1 - (24 * 60), "12:00:15", -1 );
        chk_addMins( "12:02", 12 + (24 * 60), "12:14", 1 );
        chk_addMins( "12:02", 12, "12:14", "0 00:12" );
        chk_addMins( "12" );
    }

    private void chk_addMins( String pTimeString, int pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        int zResultDays = sd.addMins( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    private void chk_addMins( String pTimeString, int pAdjustBy, String pExpectedString, String pDiffString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTime sdOrig = sd.copy();
        assertEquals( sd, sdOrig );
        assertEquals( 0, sd.compareTo( sdOrig ) );
        assertFalse( sd.before( sdOrig ) );
        assertFalse( sd.after( sdOrig ) );
        assertFalse( sdOrig.before( sd ) );
        assertFalse( sdOrig.after( sd ) );
        assertEquals( "0", sd.difference( sdOrig ).toString() );
        int zResultDays = sd.addMins( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( 0, zResultDays );
        assertFalse( sdOrig.equals( sd ) );
        assertEquals( pDiffString, sd.difference( sdOrig ).toString() );
        if ( pAdjustBy > 0 )
        {
            // sdOrig < sd
            assertTrue( 0 > sdOrig.compareTo( sd ) );
            assertTrue( 0 < sd.compareTo( sdOrig ) );
            assertTrue( sdOrig.before( sd ) );
            assertFalse( sdOrig.after( sd ) );
            assertFalse( sd.before( sdOrig ) );
            assertTrue( sd.after( sdOrig ) );
        }
        if ( pAdjustBy < 0 )
        {
            // sdOrig > sd
            assertTrue( 0 < sdOrig.compareTo( sd ) );
            assertTrue( 0 > sd.compareTo( sdOrig ) );
            assertFalse( sdOrig.before( sd ) );
            assertTrue( sdOrig.after( sd ) );
            assertTrue( sd.before( sdOrig ) );
            assertFalse( sd.after( sdOrig ) );
        }
    }

    private void chk_addMins( String pTimeString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.addMins( 1 );
            fail( "Did Not fail on '" + sd + "': addMins( 1 )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_addSecs()
    {
        chk_addSecs( "04:01:57.123", 3, "04:02:00.123", "0 00:00:03" );
        chk_addSecs( "12:01:15", -1, "12:01:14", "0 00:00:01" );
        chk_addSecs( "12:01:15", -1 - (24 * 60 * 60), "12:01:14", -1 );
        chk_addSecs( "12:01:15", 1 + (24 * 60 * 60), "12:01:16", 1 );
        chk_addSecs( "12:02" );
        chk_addSecs( "12" );
    }

    private void chk_addSecs( String pTimeString, int pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        int zResultDays = sd.addSecs( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    private void chk_addSecs( String pTimeString, int pAdjustBy, String pExpectedString, String pDiffString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTime sdOrig = sd.copy();
        assertEquals( sd, sdOrig );
        assertEquals( 0, sd.compareTo( sdOrig ) );
        assertFalse( sd.before( sdOrig ) );
        assertFalse( sd.after( sdOrig ) );
        assertFalse( sdOrig.before( sd ) );
        assertFalse( sdOrig.after( sd ) );
        assertEquals( "0", sd.difference( sdOrig ).toString() );
        int zResultDays = sd.addSecs( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( 0, zResultDays );
        assertFalse( sdOrig.equals( sd ) );
        assertEquals( pDiffString, sd.difference( sdOrig ).toString() );
        if ( pAdjustBy > 0 )
        {
            // sdOrig < sd
            assertTrue( 0 > sdOrig.compareTo( sd ) );
            assertTrue( 0 < sd.compareTo( sdOrig ) );
            assertTrue( sdOrig.before( sd ) );
            assertFalse( sdOrig.after( sd ) );
            assertFalse( sd.before( sdOrig ) );
            assertTrue( sd.after( sdOrig ) );
        }
        if ( pAdjustBy < 0 )
        {
            // sdOrig > sd
            assertTrue( 0 < sdOrig.compareTo( sd ) );
            assertTrue( 0 > sd.compareTo( sdOrig ) );
            assertFalse( sdOrig.before( sd ) );
            assertTrue( sdOrig.after( sd ) );
            assertTrue( sd.before( sdOrig ) );
            assertFalse( sd.after( sdOrig ) );
        }
    }

    private void chk_addSecs( String pTimeString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.addSecs( 1 );
            fail( "Did Not fail on '" + sd + "': addSecs( 1 )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_addMilliSecs()
    {
        chk_addMilliSecs( "04:01:57.123", 3, "04:01:57.126", "0 00:00:00.003" );
        chk_addMilliSecs( "04:01:57.123", -124, "04:01:56.999", "0 00:00:00.124" );
        chk_addMilliSecs( "04:01:57.123", 3 + (24 * 60 * 60 * 1000), "04:01:57.126", 1 );
        chk_addMilliSecs( "04:01:57.123", -3 - (24 * 60 * 60 * 1000), "04:01:57.120", -1 );
        chk_addMilliSecs( "12:01:15" );
        chk_addMilliSecs( "12:02" );
        chk_addMilliSecs( "12" );
    }

    private void chk_addMilliSecs( String pTimeString, int pAdjustBy, String pExpectedString, int pResultDays )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        int zResultDays = sd.addMilliSecs( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( pResultDays, zResultDays );
    }

    private void chk_addMilliSecs( String pTimeString, int pAdjustBy, String pExpectedString, String pDiffString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        SimpleTime sdOrig = sd.copy();
        assertEquals( sd, sdOrig );
        assertEquals( 0, sd.compareTo( sdOrig ) );
        assertFalse( sd.before( sdOrig ) );
        assertFalse( sd.after( sdOrig ) );
        assertFalse( sdOrig.before( sd ) );
        assertFalse( sdOrig.after( sd ) );
        assertEquals( "0", sd.difference( sdOrig ).toString() );
        int zResultDays = sd.addMilliSecs( pAdjustBy );
        assertEquals( pExpectedString, sd.toString() );
        assertEquals( 0, zResultDays );
        assertFalse( sdOrig.equals( sd ) );
        assertEquals( pDiffString, sd.difference( sdOrig ).toString() );
        if ( pAdjustBy > 0 )
        {
            // sdOrig < sd
            assertTrue( 0 > sdOrig.compareTo( sd ) );
            assertTrue( 0 < sd.compareTo( sdOrig ) );
            assertTrue( sdOrig.before( sd ) );
            assertFalse( sdOrig.after( sd ) );
            assertFalse( sd.before( sdOrig ) );
            assertTrue( sd.after( sdOrig ) );
        }
        if ( pAdjustBy < 0 )
        {
            // sdOrig > sd
            assertTrue( 0 < sdOrig.compareTo( sd ) );
            assertTrue( 0 > sd.compareTo( sdOrig ) );
            assertFalse( sdOrig.before( sd ) );
            assertTrue( sdOrig.after( sd ) );
            assertTrue( sd.before( sdOrig ) );
            assertFalse( sd.after( sdOrig ) );
        }
    }

    private void chk_addMilliSecs( String pTimeString )
    {
        SimpleTime sd = SimpleTime.fromString( pTimeString );
        try
        {
            sd.addMilliSecs( 1 );
            fail( "Did Not fail on '" + sd + "': addMilliSecs( 1 )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }

    public void test_after_before_null()
    {
        SimpleTime sd = new SimpleTime( 1 );
        try
        {
            sd.after( null );
            fail( "Did Not fail on '" + sd + "': after( null )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
        try
        {
            sd.before( null );
            fail( "Did Not fail on '" + sd + "': before( null )" );
        }
        catch ( IllegalArgumentException expected )
        {
            // expected
        }
    }
}

Commits for litesoft/trunk/Java/core/Anywhere/tests/org/litesoft/core/simpletypes/temporal/SimpleTimeTest.java

Diff revisions: vs.
Revision Author Commited Message
912 Diff Diff GeorgeS picture GeorgeS Fri 28 Jun, 2013 06:48:05 +0000

Revert to mixed & Working (PEDS & Prioritizer) code!

897 Diff Diff GeorgeS picture GeorgeS Mon 25 Feb, 2013 02:04:34 +0000
869 GeorgeS picture GeorgeS Mon 26 Nov, 2012 01:33:04 +0000