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
;
22 * Test suite for the TmfTimestamp class.
24 @SuppressWarnings("nls")
25 public class TmfTimestampTest
extends TestCase
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 private final ITmfTimestamp ts0
= new TmfTimestamp();
32 private final ITmfTimestamp ts1
= new TmfTimestamp(12345);
33 private final ITmfTimestamp ts2
= new TmfTimestamp(12345, -1);
34 private final ITmfTimestamp ts3
= new TmfTimestamp(12345, 2, 5);
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
41 * @param name the test name
43 public TmfTimestampTest(final String name
) {
48 protected void setUp() throws Exception
{
53 protected void tearDown() throws Exception
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
61 public void testDefaultConstructor() throws Exception
{
62 assertEquals("getValue", 0, ts0
.getValue());
63 assertEquals("getscale", 0, ts0
.getScale());
64 assertEquals("getPrecision", 0, ts0
.getPrecision());
67 public void testValueConstructor() throws Exception
{
68 assertEquals("getValue", 12345, ts1
.getValue());
69 assertEquals("getscale", 0, ts1
.getScale());
70 assertEquals("getPrecision", 0, ts1
.getPrecision());
73 public void testValueScaleConstructor() throws Exception
{
74 assertEquals("getValue", 12345, ts2
.getValue());
75 assertEquals("getscale", -1, ts2
.getScale());
76 assertEquals("getPrecision", 0, ts2
.getPrecision());
79 public void testFullConstructor() throws Exception
{
80 assertEquals("getValue", 12345, ts3
.getValue());
81 assertEquals("getscale", 2, ts3
.getScale());
82 assertEquals("getPrecision", 5, ts3
.getPrecision());
85 public void testCopyConstructor() throws Exception
{
86 final ITmfTimestamp ts
= new TmfTimestamp(12345, 2, 5);
87 final ITmfTimestamp copy
= new TmfTimestamp(ts
);
89 assertEquals("getValue", ts
.getValue(), copy
.getValue());
90 assertEquals("getscale", ts
.getScale(), copy
.getScale());
91 assertEquals("getPrecision", ts
.getPrecision(), copy
.getPrecision());
93 assertEquals("getValue", 12345, copy
.getValue());
94 assertEquals("getscale", 2, copy
.getScale());
95 assertEquals("getPrecision", 5, copy
.getPrecision());
98 public void testCopyNullConstructor() throws Exception
{
100 new TmfTimestamp(null);
101 fail("TmfTimestamp: null argument");
102 } catch (final IllegalArgumentException e
) {
106 public void testCopyConstructorBigBang() throws Exception
{
107 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_BANG
);
108 assertEquals("getValue", TmfTimestamp
.BIG_BANG
.getValue(), ts
.getValue());
109 assertEquals("getscale", TmfTimestamp
.BIG_BANG
.getScale(), ts
.getScale());
110 assertEquals("getPrecision", TmfTimestamp
.BIG_BANG
.getPrecision(), ts
.getPrecision());
113 public void testCopyConstructorBigCrunch() throws Exception
{
114 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_CRUNCH
);
115 assertEquals("getValue", TmfTimestamp
.BIG_CRUNCH
.getValue(), ts
.getValue());
116 assertEquals("getscale", TmfTimestamp
.BIG_CRUNCH
.getScale(), ts
.getScale());
117 assertEquals("getPrecision", TmfTimestamp
.BIG_CRUNCH
.getPrecision(), ts
.getPrecision());
120 public void testCopyConstructorZero() throws Exception
{
121 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.ZERO
);
122 assertEquals("getValue", TmfTimestamp
.ZERO
.getValue(), ts
.getValue());
123 assertEquals("getscale", TmfTimestamp
.ZERO
.getScale(), ts
.getScale());
124 assertEquals("getPrecision", TmfTimestamp
.ZERO
.getPrecision(), ts
.getPrecision());
127 // ------------------------------------------------------------------------
129 // ------------------------------------------------------------------------
131 public static class MyTimestamp
extends TmfTimestamp
{
134 public boolean equals(final Object other
) {
135 return super.equals(other
);
139 public MyTimestamp
clone() {
140 return (MyTimestamp
) super.clone();
144 public void testClone() throws Exception
{
145 final ITmfTimestamp clone
= ts0
.clone();
147 assertTrue("clone", ts0
.clone().equals(ts0
));
148 assertTrue("clone", clone
.clone().equals(clone
));
150 assertEquals("clone", clone
, ts0
);
151 assertEquals("clone", ts0
, clone
);
154 public void testClone2() throws Exception
{
155 final MyTimestamp timestamp
= new MyTimestamp();
156 final MyTimestamp clone
= timestamp
.clone();
158 assertTrue("clone", timestamp
.clone().equals(timestamp
));
159 assertTrue("clone", clone
.clone().equals(clone
));
161 assertEquals("clone", clone
, timestamp
);
162 assertEquals("clone", timestamp
, clone
);
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
169 public void testHashCode() throws Exception
{
170 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
171 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
172 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
174 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
175 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
176 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
178 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
181 // ------------------------------------------------------------------------
183 // ------------------------------------------------------------------------
185 public void testEqualsReflexivity() throws Exception
{
186 assertTrue("equals", ts0
.equals(ts0
));
187 assertTrue("equals", ts1
.equals(ts1
));
189 assertTrue("equals", !ts0
.equals(ts1
));
190 assertTrue("equals", !ts1
.equals(ts0
));
193 public void testEqualsSymmetry() throws Exception
{
194 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
195 assertTrue("equals", ts0
.equals(ts0copy
));
196 assertTrue("equals", ts0copy
.equals(ts0
));
198 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
199 assertTrue("equals", ts1
.equals(ts1copy
));
200 assertTrue("equals", ts1copy
.equals(ts1
));
202 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
203 assertTrue("equals", ts2
.equals(ts2copy
));
204 assertTrue("equals", ts2copy
.equals(ts2
));
207 public void testEqualsTransivity() throws Exception
{
208 final ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
209 final ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
210 assertTrue("equals", ts0
.equals(ts0copy1
));
211 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
212 assertTrue("equals", ts0
.equals(ts0copy2
));
214 final ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
215 final ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
216 assertTrue("equals", ts1
.equals(ts1copy1
));
217 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
218 assertTrue("equals", ts1
.equals(ts1copy2
));
220 final ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
221 final ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
222 assertTrue("equals", ts2
.equals(ts2copy1
));
223 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
224 assertTrue("equals", ts2
.equals(ts2copy2
));
227 public void testEqualsNull() throws Exception
{
228 assertTrue("equals", !ts0
.equals(null));
229 assertTrue("equals", !ts1
.equals(null));
232 public void testEqualsNonTimestamp() throws Exception
{
233 assertFalse("equals", ts0
.equals(ts0
.toString()));
236 // ------------------------------------------------------------------------
238 // ------------------------------------------------------------------------
240 public void testToString() throws Exception
{
241 assertEquals("toString", "TmfTimestamp [fValue=0, fScale=0, fPrecision=0]", ts0
.toString());
242 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=0, fPrecision=0]", ts1
.toString());
243 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=-1, fPrecision=0]", ts2
.toString());
244 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=2, fPrecision=5]", ts3
.toString());
247 // ------------------------------------------------------------------------
249 // ------------------------------------------------------------------------
251 public void testNormalizeOffset() throws Exception
{
252 ITmfTimestamp ts
= ts0
.normalize(0, 0);
253 assertEquals("getValue", 0, ts
.getValue());
254 assertEquals("getscale", 0, ts
.getScale());
255 assertEquals("getPrecision", 0, ts
.getPrecision());
257 ts
= ts0
.normalize(12345, 0);
258 assertEquals("getValue", 12345, ts
.getValue());
259 assertEquals("getscale", 0, ts
.getScale());
260 assertEquals("getPrecision", 0, ts
.getPrecision());
262 ts
= ts0
.normalize(10, 0);
263 assertEquals("getValue", 10, ts
.getValue());
264 assertEquals("getscale", 0, ts
.getScale());
265 assertEquals("getPrecision", 0, ts
.getPrecision());
267 ts
= ts0
.normalize(-10, 0);
268 assertEquals("getValue", -10, ts
.getValue());
269 assertEquals("getscale", 0, ts
.getScale());
270 assertEquals("getPrecision", 0, ts
.getPrecision());
273 public void testNormalizeOffsetLowerLimits() throws Exception
{
274 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5);
276 ITmfTimestamp ts
= ref
.normalize(-4, 0);
277 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
278 assertEquals("getscale", 0, ts
.getScale());
279 assertEquals("getPrecision", 0, ts
.getPrecision());
281 ts
= ref
.normalize(-5, 0);
282 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
283 assertEquals("getscale", 0, ts
.getScale());
284 assertEquals("getPrecision", 0, ts
.getPrecision());
286 ts
= ref
.normalize(-6, 0);
287 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
288 assertEquals("getscale", 0, ts
.getScale());
289 assertEquals("getPrecision", 0, ts
.getPrecision());
292 public void testNormalizeOffsetUpperLimits() throws Exception
{
293 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5);
295 ITmfTimestamp ts
= ref
.normalize(4, 0);
296 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
297 assertEquals("getscale", 0, ts
.getScale());
298 assertEquals("getPrecision", 0, ts
.getPrecision());
300 ts
= ref
.normalize(5, 0);
301 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
302 assertEquals("getscale", 0, ts
.getScale());
303 assertEquals("getPrecision", 0, ts
.getPrecision());
305 ts
= ref
.normalize(6, 0);
306 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
307 assertEquals("getscale", 0, ts
.getScale());
308 assertEquals("getPrecision", 0, ts
.getPrecision());
311 public void testNormalizeScale() throws Exception
{
312 ITmfTimestamp ts
= ts0
.normalize(0, 10);
313 assertEquals("getValue", 0, ts
.getValue());
314 assertEquals("getscale", 10, ts
.getScale());
315 assertEquals("getPrecision", 0, ts
.getPrecision());
317 ts
= ts0
.normalize(0, -10);
318 assertEquals("getValue", 0, ts
.getValue());
319 assertEquals("getscale", -10, ts
.getScale());
320 assertEquals("getPrecision", 0, ts
.getPrecision());
323 public void testNormalizedScaleLimits() throws Exception
{
324 final int MAX_SCALE_DIFF
= 19;
328 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
329 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
330 } catch (final ArithmeticException e
) {
331 fail("normalize: scale error");
336 ts1
.normalize(0, +MAX_SCALE_DIFF
);
337 fail("normalize: scale error");
338 ts1
.normalize(0, -MAX_SCALE_DIFF
);
339 fail("normalize: scale error");
340 } catch (final ArithmeticException e
) {
345 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
346 fail("normalize: scale error");
347 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
348 fail("normalize: scale error");
349 } catch (final ArithmeticException e
) {
353 public void testNormalizeOffsetAndScaleTrivial() throws Exception
{
354 final ITmfTimestamp ts
= ts0
.normalize(0, 0);
355 assertEquals("getValue", 0, ts
.getValue());
356 assertEquals("getscale", 0, ts
.getScale());
357 assertEquals("getPrecision", 0, ts
.getPrecision());
360 public void testNormalizeOffsetAndScale() throws Exception
{
361 final int SCALE
= 12;
363 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
364 assertEquals("getValue", 0, ts
.getValue());
365 assertEquals("getscale", SCALE
, ts
.getScale());
366 assertEquals("getPrecision", 0, ts
.getPrecision());
368 ts
= ts0
.normalize(12345, SCALE
);
369 assertEquals("getValue", 12345, ts
.getValue());
370 assertEquals("getscale", SCALE
, ts
.getScale());
371 assertEquals("getPrecision", 0, ts
.getPrecision());
373 ts
= ts0
.normalize(10, SCALE
);
374 assertEquals("getValue", 10, ts
.getValue());
375 assertEquals("getscale", SCALE
, ts
.getScale());
376 assertEquals("getPrecision", 0, ts
.getPrecision());
378 ts
= ts0
.normalize(-10, SCALE
);
379 assertEquals("getValue", -10, ts
.getValue());
380 assertEquals("getscale", SCALE
, ts
.getScale());
381 assertEquals("getPrecision", 0, ts
.getPrecision());
384 public void testNormalizeOffsetAndScale2() throws Exception
{
386 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
387 assertEquals("getValue", 123, ts
.getValue());
388 assertEquals("getscale", SCALE
, ts
.getScale());
389 assertEquals("getPrecision", 0, ts
.getPrecision());
391 ts
= ts1
.normalize(12345, SCALE
);
392 assertEquals("getValue", 12468, ts
.getValue());
393 assertEquals("getscale", SCALE
, ts
.getScale());
394 assertEquals("getPrecision", 0, ts
.getPrecision());
397 ts
= ts1
.normalize(0, SCALE
);
398 assertEquals("getValue", 1234500, ts
.getValue());
399 assertEquals("getscale", SCALE
, ts
.getScale());
400 assertEquals("getPrecision", 0, ts
.getPrecision());
402 ts
= ts1
.normalize(67, SCALE
);
403 assertEquals("getValue", 1234567, ts
.getValue());
404 assertEquals("getscale", SCALE
, ts
.getScale());
405 assertEquals("getPrecision", 0, ts
.getPrecision());
408 // ------------------------------------------------------------------------
410 // ------------------------------------------------------------------------
412 public void testBasicCompareTo() throws Exception
{
413 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
414 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
415 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
416 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
418 assertTrue(ts1
.compareTo(ts1
) == 0);
420 assertTrue("CompareTo", ts1
.compareTo(ts2
) < 0);
421 assertTrue("CompareTo", ts1
.compareTo(ts3
) < 0);
422 assertTrue("CompareTo", ts1
.compareTo(ts4
) < 0);
424 assertTrue("CompareTo", ts2
.compareTo(ts1
) > 0);
425 assertTrue("CompareTo", ts2
.compareTo(ts3
) < 0);
426 assertTrue("CompareTo", ts2
.compareTo(ts4
) == 0);
428 assertTrue("CompareTo", ts3
.compareTo(ts1
) > 0);
429 assertTrue("CompareTo", ts3
.compareTo(ts2
) > 0);
430 assertTrue("CompareTo", ts3
.compareTo(ts4
) > 0);
433 public void testCompareToCornerCases1() throws Exception
{
434 final ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
435 final ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
436 final ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
437 final ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
439 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
440 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
441 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
442 assertTrue("compareTo", ts0
.compareTo(ts0c
, false) == -1);
443 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
446 public void testCompareToCornerCases2() throws Exception
{
447 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
448 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
449 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
451 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == 1);
452 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == -1);
454 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == -1);
455 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == -1);
457 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == 1);
458 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == 1);
461 public void testCompareToCornerCases3() throws Exception
{
462 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
463 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
464 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
466 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == -1);
467 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == 1);
469 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == 1);
470 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == 1);
472 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == -1);
473 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == -1);
476 public void testCompareToCornerCases4() throws Exception
{
477 assertTrue("compareTo", ts0
.compareTo(null, false) == 1);
478 assertTrue("compareTo", ts0
.compareTo(null, true) == 1);
481 public void testCompareToSameScale() throws Exception
{
482 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
483 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
484 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
485 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
487 assertTrue(ts1
.compareTo(ts1
, false) == 0);
489 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
490 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
491 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
493 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
494 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
495 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
497 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
498 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
499 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
502 public void testCompareToDifferentScale() throws Exception
{
503 final ITmfTimestamp ts1
= new TmfTimestamp(9000, -1, 50);
504 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
505 final ITmfTimestamp ts3
= new TmfTimestamp(110, 1, 50);
506 final ITmfTimestamp ts4
= new TmfTimestamp(1, 3, 75);
508 assertTrue("CompareTo", ts1
.compareTo(ts1
, false) == 0);
510 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
511 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
512 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
514 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
515 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
516 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
518 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
519 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
520 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
523 public void testCompareToWithinPrecision() throws Exception
{
524 final ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
525 final ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
526 final ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
527 final ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
529 assertTrue("CompareTo", ts1
.compareTo(ts1
, true) == 0);
531 assertTrue("CompareTo", ts1
.compareTo(ts2
, true) == 0);
532 assertTrue("CompareTo", ts1
.compareTo(ts3
, true) < 0);
533 assertTrue("CompareTo", ts1
.compareTo(ts4
, true) == 0);
535 assertTrue("CompareTo", ts2
.compareTo(ts1
, true) == 0);
536 assertTrue("CompareTo", ts2
.compareTo(ts3
, true) == 0);
537 assertTrue("CompareTo", ts2
.compareTo(ts4
, true) == 0);
539 assertTrue("CompareTo", ts3
.compareTo(ts1
, true) > 0);
540 assertTrue("CompareTo", ts3
.compareTo(ts2
, true) == 0);
541 assertTrue("CompareTo", ts3
.compareTo(ts4
, true) == 0);
544 public void testCompareToLargeScale1() throws Exception
{
545 final ITmfTimestamp ts1
= new TmfTimestamp(-1, 100);
546 final ITmfTimestamp ts2
= new TmfTimestamp(-1000, -100);
547 final ITmfTimestamp ts3
= new TmfTimestamp(1, 100);
548 final ITmfTimestamp ts4
= new TmfTimestamp(1000, -100);
550 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
551 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
552 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
554 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
555 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
556 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) < 0);
558 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
559 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
560 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
562 assertTrue("CompareTo", ts4
.compareTo(ts1
, false) > 0);
563 assertTrue("CompareTo", ts4
.compareTo(ts2
, false) > 0);
564 assertTrue("CompareTo", ts4
.compareTo(ts3
, false) < 0);
567 public void testCompareToLargeScale2() throws Exception
{
568 final ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
569 final ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
571 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
572 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
574 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
575 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
578 // ------------------------------------------------------------------------
580 // ------------------------------------------------------------------------
582 public void testDelta() throws Exception
{
583 // Delta for same scale and precision (delta > 0)
584 ITmfTimestamp ts0
= new TmfTimestamp(10, 9);
585 ITmfTimestamp ts1
= new TmfTimestamp(5, 9);
586 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
588 ITmfTimestamp delta
= ts0
.getDelta(ts1
);
589 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
591 // Delta for same scale and precision (delta < 0)
592 ts0
= new TmfTimestamp(5, 9);
593 ts1
= new TmfTimestamp(10, 9);
594 exp
= new TmfTimestamp(-5, 9);
596 delta
= ts0
.getDelta(ts1
);
597 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
599 // Delta for different scale and same precision (delta > 0)
600 ts0
= new TmfTimestamp(5, 9);
601 ts1
= new TmfTimestamp(10, 8);
602 exp
= new TmfTimestamp(4, 9);
604 delta
= ts0
.getDelta(ts1
);
605 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
607 // Delta for different scale and same precision (delta > 0)
608 ts0
= new TmfTimestamp(5, 9);
609 ts1
= new TmfTimestamp(10, 7);
610 exp
= new TmfTimestamp(5, 9);
612 delta
= ts0
.getDelta(ts1
);
613 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
615 // Delta for different scale and same precision
616 ts0
= new TmfTimestamp(10, 9);
617 ts1
= new TmfTimestamp(5, 8);
618 exp
= new TmfTimestamp(10, 9);
620 delta
= ts0
.getDelta(ts1
);
621 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
623 // Delta for same scale and different precision
624 ts0
= new TmfTimestamp(10, 9, 1);
625 ts1
= new TmfTimestamp(5, 9, 2);
626 exp
= new TmfTimestamp(5, 9, 3);
628 delta
= ts0
.getDelta(ts1
);
629 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
630 assertEquals("precision", 3, delta
.getPrecision());
632 // Delta for same scale and different precision
633 ts0
= new TmfTimestamp(5, 9, 2);
634 ts1
= new TmfTimestamp(10, 9, 1);
635 exp
= new TmfTimestamp(-5, 9, 3);
637 delta
= ts0
.getDelta(ts1
);
638 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
639 assertEquals("precision", 3, delta
.getPrecision());
641 // Delta for different scale and different precision
642 ts0
= new TmfTimestamp(5, 9, 2);
643 ts1
= new TmfTimestamp(10, 8, 1);
644 exp
= new TmfTimestamp(4, 9, 3);
645 delta
= ts0
.getDelta(ts1
);
646 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
647 assertEquals("precision", 2, delta
.getPrecision());