1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Francois Chouinard - Initial API and implementation
11 * Francois Chouinard - Adjusted for new Event Model
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.event
;
16 import junit
.framework
.TestCase
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfTimestamp
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestampFormat
;
23 * Test suite for the TmfTimestamp class.
25 @SuppressWarnings("nls")
26 public class TmfTimestampTest
extends TestCase
{
28 // ------------------------------------------------------------------------
30 // ------------------------------------------------------------------------
32 private final ITmfTimestamp ts0
= new TmfTimestamp();
33 private final ITmfTimestamp ts1
= new TmfTimestamp(12345, 0);
34 private final ITmfTimestamp ts2
= new TmfTimestamp(12345, -1);
35 private final ITmfTimestamp ts3
= new TmfTimestamp(12345, 2, 5);
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
42 * @param name the test name
44 public TmfTimestampTest(final String name
) {
49 protected void setUp() throws Exception
{
54 protected void tearDown() throws Exception
{
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
65 public void testDefaultConstructor() {
66 assertEquals("getValue", 0, ts0
.getValue());
67 assertEquals("getscale", 0, ts0
.getScale());
68 assertEquals("getPrecision", 0, ts0
.getPrecision());
74 public void testValueConstructor() {
75 assertEquals("getValue", 12345, ts1
.getValue());
76 assertEquals("getscale", 0, ts1
.getScale());
77 assertEquals("getPrecision", 0, ts1
.getPrecision());
83 public void testValueScaleConstructor() {
84 assertEquals("getValue", 12345, ts2
.getValue());
85 assertEquals("getscale", -1, ts2
.getScale());
86 assertEquals("getPrecision", 0, ts2
.getPrecision());
92 public void testFullConstructor() {
93 assertEquals("getValue", 12345, ts3
.getValue());
94 assertEquals("getscale", 2, ts3
.getScale());
95 assertEquals("getPrecision", 5, ts3
.getPrecision());
101 public void testCopyConstructor() {
102 final ITmfTimestamp ts
= new TmfTimestamp(12345, 2, 5);
103 final ITmfTimestamp copy
= new TmfTimestamp(ts
);
105 assertEquals("getValue", ts
.getValue(), copy
.getValue());
106 assertEquals("getscale", ts
.getScale(), copy
.getScale());
107 assertEquals("getPrecision", ts
.getPrecision(), copy
.getPrecision());
109 assertEquals("getValue", 12345, copy
.getValue());
110 assertEquals("getscale", 2, copy
.getScale());
111 assertEquals("getPrecision", 5, copy
.getPrecision());
117 public void testCopyNullConstructor() {
119 new TmfTimestamp(null);
120 fail("TmfTimestamp: null argument");
121 } catch (final IllegalArgumentException e
) {
128 public void testCopyConstructorBigBang() {
129 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_BANG
);
130 assertEquals("getValue", TmfTimestamp
.BIG_BANG
.getValue(), ts
.getValue());
131 assertEquals("getscale", TmfTimestamp
.BIG_BANG
.getScale(), ts
.getScale());
132 assertEquals("getPrecision", TmfTimestamp
.BIG_BANG
.getPrecision(), ts
.getPrecision());
138 public void testCopyConstructorBigCrunch() {
139 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_CRUNCH
);
140 assertEquals("getValue", TmfTimestamp
.BIG_CRUNCH
.getValue(), ts
.getValue());
141 assertEquals("getscale", TmfTimestamp
.BIG_CRUNCH
.getScale(), ts
.getScale());
142 assertEquals("getPrecision", TmfTimestamp
.BIG_CRUNCH
.getPrecision(), ts
.getPrecision());
148 public void testCopyConstructorZero() {
149 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.ZERO
);
150 assertEquals("getValue", TmfTimestamp
.ZERO
.getValue(), ts
.getValue());
151 assertEquals("getscale", TmfTimestamp
.ZERO
.getScale(), ts
.getScale());
152 assertEquals("getPrecision", TmfTimestamp
.ZERO
.getPrecision(), ts
.getPrecision());
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
159 private static class MyTimestamp
extends TmfTimestamp
{
162 public boolean equals(final Object other
) {
163 return super.equals(other
);
167 public MyTimestamp
clone() {
168 return (MyTimestamp
) super.clone();
175 public void testClone() {
176 final ITmfTimestamp clone
= ts0
.clone();
178 assertTrue("clone", ts0
.clone().equals(ts0
));
179 assertTrue("clone", clone
.clone().equals(clone
));
181 assertEquals("clone", clone
, ts0
);
182 assertEquals("clone", ts0
, clone
);
188 public void testClone2() {
189 final MyTimestamp timestamp
= new MyTimestamp();
190 final MyTimestamp clone
= timestamp
.clone();
192 assertTrue("clone", timestamp
.clone().equals(timestamp
));
193 assertTrue("clone", clone
.clone().equals(clone
));
195 assertEquals("clone", clone
, timestamp
);
196 assertEquals("clone", timestamp
, clone
);
199 // ------------------------------------------------------------------------
201 // ------------------------------------------------------------------------
206 public void testHashCode() {
207 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
208 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
209 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
211 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
212 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
213 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
215 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
218 // ------------------------------------------------------------------------
220 // ------------------------------------------------------------------------
225 public void testEqualsReflexivity() {
226 assertTrue("equals", ts0
.equals(ts0
));
227 assertTrue("equals", ts1
.equals(ts1
));
229 assertTrue("equals", !ts0
.equals(ts1
));
230 assertTrue("equals", !ts1
.equals(ts0
));
236 public void testEqualsSymmetry() {
237 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
238 assertTrue("equals", ts0
.equals(ts0copy
));
239 assertTrue("equals", ts0copy
.equals(ts0
));
241 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
242 assertTrue("equals", ts1
.equals(ts1copy
));
243 assertTrue("equals", ts1copy
.equals(ts1
));
245 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
246 assertTrue("equals", ts2
.equals(ts2copy
));
247 assertTrue("equals", ts2copy
.equals(ts2
));
253 public void testEqualsTransivity() {
254 final ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
255 final ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
256 assertTrue("equals", ts0
.equals(ts0copy1
));
257 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
258 assertTrue("equals", ts0
.equals(ts0copy2
));
260 final ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
261 final ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
262 assertTrue("equals", ts1
.equals(ts1copy1
));
263 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
264 assertTrue("equals", ts1
.equals(ts1copy2
));
266 final ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
267 final ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
268 assertTrue("equals", ts2
.equals(ts2copy1
));
269 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
270 assertTrue("equals", ts2
.equals(ts2copy2
));
276 public void testEqualsNull() {
277 assertTrue("equals", !ts0
.equals(null));
278 assertTrue("equals", !ts1
.equals(null));
284 public void testEqualsNonTimestamp() {
285 assertFalse("equals", ts0
.equals(ts0
.toString()));
288 // ------------------------------------------------------------------------
290 // ------------------------------------------------------------------------
295 public void testToStringDefault() {
296 assertEquals("toString", "00:00:00.000_000_000", ts0
.toString());
297 assertEquals("toString", "03:25:45.000_000_000", ts1
.toString());
298 assertEquals("toString", "00:20:34.500_000_000", ts2
.toString());
299 assertEquals("toString", "06:55:00.000_000_000", ts3
.toString());
305 public void testToStringInterval() {
306 assertEquals("toString", "000.000_000_000", ts0
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
307 assertEquals("toString", "12345.000_000_000", ts1
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
308 assertEquals("toString", "1234.500_000_000", ts2
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
309 assertEquals("toString", "1234500.000_000_000", ts3
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
312 // ------------------------------------------------------------------------
314 // ------------------------------------------------------------------------
319 public void testNormalizeOffset() {
320 ITmfTimestamp ts
= ts0
.normalize(0, 0);
321 assertEquals("getValue", 0, ts
.getValue());
322 assertEquals("getscale", 0, ts
.getScale());
323 assertEquals("getPrecision", 0, ts
.getPrecision());
325 ts
= ts0
.normalize(12345, 0);
326 assertEquals("getValue", 12345, ts
.getValue());
327 assertEquals("getscale", 0, ts
.getScale());
328 assertEquals("getPrecision", 0, ts
.getPrecision());
330 ts
= ts0
.normalize(10, 0);
331 assertEquals("getValue", 10, ts
.getValue());
332 assertEquals("getscale", 0, ts
.getScale());
333 assertEquals("getPrecision", 0, ts
.getPrecision());
335 ts
= ts0
.normalize(-10, 0);
336 assertEquals("getValue", -10, ts
.getValue());
337 assertEquals("getscale", 0, ts
.getScale());
338 assertEquals("getPrecision", 0, ts
.getPrecision());
344 public void testNormalizeOffsetLowerLimits() {
345 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5, 0);
347 ITmfTimestamp ts
= ref
.normalize(-4, 0);
348 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
349 assertEquals("getscale", 0, ts
.getScale());
350 assertEquals("getPrecision", 0, ts
.getPrecision());
352 ts
= ref
.normalize(-5, 0);
353 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
354 assertEquals("getscale", 0, ts
.getScale());
355 assertEquals("getPrecision", 0, ts
.getPrecision());
357 ts
= ref
.normalize(-6, 0);
358 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
359 assertEquals("getscale", 0, ts
.getScale());
360 assertEquals("getPrecision", 0, ts
.getPrecision());
366 public void testNormalizeOffsetUpperLimits() {
367 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5, 0);
369 ITmfTimestamp ts
= ref
.normalize(4, 0);
370 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
371 assertEquals("getscale", 0, ts
.getScale());
372 assertEquals("getPrecision", 0, ts
.getPrecision());
374 ts
= ref
.normalize(5, 0);
375 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
376 assertEquals("getscale", 0, ts
.getScale());
377 assertEquals("getPrecision", 0, ts
.getPrecision());
379 ts
= ref
.normalize(6, 0);
380 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
381 assertEquals("getscale", 0, ts
.getScale());
382 assertEquals("getPrecision", 0, ts
.getPrecision());
388 public void testNormalizeScale() {
389 ITmfTimestamp ts
= ts0
.normalize(0, 10);
390 assertEquals("getValue", 0, ts
.getValue());
391 assertEquals("getscale", 10, ts
.getScale());
392 assertEquals("getPrecision", 0, ts
.getPrecision());
394 ts
= ts0
.normalize(0, -10);
395 assertEquals("getValue", 0, ts
.getValue());
396 assertEquals("getscale", -10, ts
.getScale());
397 assertEquals("getPrecision", 0, ts
.getPrecision());
403 public void testNormalizedScaleLimits() {
404 final int MAX_SCALE_DIFF
= 19;
408 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
409 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
410 } catch (final ArithmeticException e
) {
411 fail("normalize: scale error");
416 ts1
.normalize(0, +MAX_SCALE_DIFF
);
417 fail("normalize: scale error");
418 ts1
.normalize(0, -MAX_SCALE_DIFF
);
419 fail("normalize: scale error");
420 } catch (final ArithmeticException e
) {
425 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
426 fail("normalize: scale error");
427 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
428 fail("normalize: scale error");
429 } catch (final ArithmeticException e
) {
436 public void testNormalizeOffsetAndScaleTrivial() {
437 final ITmfTimestamp ts
= ts0
.normalize(0, 0);
438 assertEquals("getValue", 0, ts
.getValue());
439 assertEquals("getscale", 0, ts
.getScale());
440 assertEquals("getPrecision", 0, ts
.getPrecision());
446 public void testNormalizeOffsetAndScale() {
447 final int SCALE
= 12;
449 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
450 assertEquals("getValue", 0, ts
.getValue());
451 assertEquals("getscale", SCALE
, ts
.getScale());
452 assertEquals("getPrecision", 0, ts
.getPrecision());
454 ts
= ts0
.normalize(12345, SCALE
);
455 assertEquals("getValue", 12345, ts
.getValue());
456 assertEquals("getscale", SCALE
, ts
.getScale());
457 assertEquals("getPrecision", 0, ts
.getPrecision());
459 ts
= ts0
.normalize(10, SCALE
);
460 assertEquals("getValue", 10, ts
.getValue());
461 assertEquals("getscale", SCALE
, ts
.getScale());
462 assertEquals("getPrecision", 0, ts
.getPrecision());
464 ts
= ts0
.normalize(-10, SCALE
);
465 assertEquals("getValue", -10, ts
.getValue());
466 assertEquals("getscale", SCALE
, ts
.getScale());
467 assertEquals("getPrecision", 0, ts
.getPrecision());
473 public void testNormalizeOffsetAndScale2() {
475 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
476 assertEquals("getValue", 123, ts
.getValue());
477 assertEquals("getscale", SCALE
, ts
.getScale());
478 assertEquals("getPrecision", 0, ts
.getPrecision());
480 ts
= ts1
.normalize(12345, SCALE
);
481 assertEquals("getValue", 12468, ts
.getValue());
482 assertEquals("getscale", SCALE
, ts
.getScale());
483 assertEquals("getPrecision", 0, ts
.getPrecision());
486 ts
= ts1
.normalize(0, SCALE
);
487 assertEquals("getValue", 1234500, ts
.getValue());
488 assertEquals("getscale", SCALE
, ts
.getScale());
489 assertEquals("getPrecision", 0, ts
.getPrecision());
491 ts
= ts1
.normalize(67, SCALE
);
492 assertEquals("getValue", 1234567, ts
.getValue());
493 assertEquals("getscale", SCALE
, ts
.getScale());
494 assertEquals("getPrecision", 0, ts
.getPrecision());
497 // ------------------------------------------------------------------------
499 // ------------------------------------------------------------------------
504 @SuppressWarnings("hiding")
505 public void testBasicCompareTo() {
506 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
507 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
508 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
509 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
511 assertTrue(ts1
.compareTo(ts1
) == 0);
513 assertTrue("CompareTo", ts1
.compareTo(ts2
) < 0);
514 assertTrue("CompareTo", ts1
.compareTo(ts3
) < 0);
515 assertTrue("CompareTo", ts1
.compareTo(ts4
) < 0);
517 assertTrue("CompareTo", ts2
.compareTo(ts1
) > 0);
518 assertTrue("CompareTo", ts2
.compareTo(ts3
) < 0);
519 assertTrue("CompareTo", ts2
.compareTo(ts4
) == 0);
521 assertTrue("CompareTo", ts3
.compareTo(ts1
) > 0);
522 assertTrue("CompareTo", ts3
.compareTo(ts2
) > 0);
523 assertTrue("CompareTo", ts3
.compareTo(ts4
) > 0);
529 public void testCompareToCornerCases1() {
530 final ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
531 final ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
532 final ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
533 final ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
535 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
536 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
537 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
538 assertTrue("compareTo", ts0
.compareTo(ts0c
, false) == -1);
539 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
545 public void testCompareToCornerCases2() {
546 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
547 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
548 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
550 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == 1);
551 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == -1);
553 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == -1);
554 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == -1);
556 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == 1);
557 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == 1);
563 public void testCompareToCornerCases3() {
564 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
565 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
566 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
568 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == -1);
569 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == 1);
571 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == 1);
572 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == 1);
574 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == -1);
575 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == -1);
581 public void testCompareToCornerCases4() {
582 assertTrue("compareTo", ts0
.compareTo(null, false) == 1);
583 assertTrue("compareTo", ts0
.compareTo(null, true) == 1);
589 @SuppressWarnings("hiding")
590 public void testCompareToSameScale() {
591 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
592 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
593 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
594 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
596 assertTrue(ts1
.compareTo(ts1
, false) == 0);
598 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
599 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
600 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
602 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
603 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
604 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
606 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
607 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
608 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
614 @SuppressWarnings("hiding")
615 public void testCompareToDifferentScale() {
616 final ITmfTimestamp ts1
= new TmfTimestamp(9000, -1, 50);
617 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
618 final ITmfTimestamp ts3
= new TmfTimestamp(110, 1, 50);
619 final ITmfTimestamp ts4
= new TmfTimestamp(1, 3, 75);
621 assertTrue("CompareTo", ts1
.compareTo(ts1
, false) == 0);
623 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
624 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
625 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
627 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
628 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
629 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
631 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
632 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
633 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
639 @SuppressWarnings("hiding")
640 public void testCompareToWithinPrecision() {
641 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
642 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
643 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
644 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
646 assertTrue("CompareTo", ts1
.compareTo(ts1
, true) == 0);
648 assertTrue("CompareTo", ts1
.compareTo(ts2
, true) == 0);
649 assertTrue("CompareTo", ts1
.compareTo(ts3
, true) < 0);
650 assertTrue("CompareTo", ts1
.compareTo(ts4
, true) == 0);
652 assertTrue("CompareTo", ts2
.compareTo(ts1
, true) == 0);
653 assertTrue("CompareTo", ts2
.compareTo(ts3
, true) == 0);
654 assertTrue("CompareTo", ts2
.compareTo(ts4
, true) == 0);
656 assertTrue("CompareTo", ts3
.compareTo(ts1
, true) > 0);
657 assertTrue("CompareTo", ts3
.compareTo(ts2
, true) == 0);
658 assertTrue("CompareTo", ts3
.compareTo(ts4
, true) == 0);
664 @SuppressWarnings("hiding")
665 public void testCompareToLargeScale1() {
666 final ITmfTimestamp ts1
= new TmfTimestamp(-1, 100);
667 final ITmfTimestamp ts2
= new TmfTimestamp(-1000, -100);
668 final ITmfTimestamp ts3
= new TmfTimestamp(1, 100);
669 final ITmfTimestamp ts4
= new TmfTimestamp(1000, -100);
671 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
672 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
673 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
675 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
676 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
677 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) < 0);
679 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
680 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
681 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
683 assertTrue("CompareTo", ts4
.compareTo(ts1
, false) > 0);
684 assertTrue("CompareTo", ts4
.compareTo(ts2
, false) > 0);
685 assertTrue("CompareTo", ts4
.compareTo(ts3
, false) < 0);
691 public void testCompareToLargeScale2() {
692 final ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
693 final ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
695 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
696 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
698 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
699 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
702 // ------------------------------------------------------------------------
704 // ------------------------------------------------------------------------
709 @SuppressWarnings("hiding")
710 public void testDelta() {
711 // Delta for same scale and precision (delta > 0)
712 ITmfTimestamp ts0
= new TmfTimestamp(10, 9);
713 ITmfTimestamp ts1
= new TmfTimestamp(5, 9);
714 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
716 ITmfTimestamp delta
= ts0
.getDelta(ts1
);
717 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
719 // Delta for same scale and precision (delta < 0)
720 ts0
= new TmfTimestamp(5, 9);
721 ts1
= new TmfTimestamp(10, 9);
722 exp
= new TmfTimestamp(-5, 9);
724 delta
= ts0
.getDelta(ts1
);
725 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
727 // Delta for different scale and same precision (delta > 0)
728 ts0
= new TmfTimestamp(5, 9);
729 ts1
= new TmfTimestamp(10, 8);
730 exp
= new TmfTimestamp(4, 9);
732 delta
= ts0
.getDelta(ts1
);
733 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
735 // Delta for different scale and same precision (delta > 0)
736 ts0
= new TmfTimestamp(5, 9);
737 ts1
= new TmfTimestamp(10, 7);
738 exp
= new TmfTimestamp(5, 9);
740 delta
= ts0
.getDelta(ts1
);
741 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
743 // Delta for different scale and same precision
744 ts0
= new TmfTimestamp(10, 9);
745 ts1
= new TmfTimestamp(5, 8);
746 exp
= new TmfTimestamp(10, 9);
748 delta
= ts0
.getDelta(ts1
);
749 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
751 // Delta for same scale and different precision
752 ts0
= new TmfTimestamp(10, 9, 1);
753 ts1
= new TmfTimestamp(5, 9, 2);
754 exp
= new TmfTimestamp(5, 9, 3);
756 delta
= ts0
.getDelta(ts1
);
757 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
758 assertEquals("precision", 3, delta
.getPrecision());
760 // Delta for same scale and different precision
761 ts0
= new TmfTimestamp(5, 9, 2);
762 ts1
= new TmfTimestamp(10, 9, 1);
763 exp
= new TmfTimestamp(-5, 9, 3);
765 delta
= ts0
.getDelta(ts1
);
766 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
767 assertEquals("precision", 3, delta
.getPrecision());
769 // Delta for different scale and different precision
770 ts0
= new TmfTimestamp(5, 9, 2);
771 ts1
= new TmfTimestamp(10, 8, 1);
772 exp
= new TmfTimestamp(4, 9, 3);
773 delta
= ts0
.getDelta(ts1
);
774 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
775 assertEquals("precision", 2, delta
.getPrecision());