1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 * Alexandre Montplaisir - Port to JUnit4
13 *******************************************************************************/
15 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.event
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertFalse
;
19 import static org
.junit
.Assert
.assertTrue
;
20 import static org
.junit
.Assert
.fail
;
22 import java
.text
.DateFormat
;
23 import java
.text
.SimpleDateFormat
;
24 import java
.util
.Date
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
29 import org
.junit
.Test
;
32 * Test suite for the TmfTimestamp class.
34 @SuppressWarnings("javadoc")
35 public class TmfTimestampTest
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 private final ITmfTimestamp ts0
= new TmfTimestamp();
42 private final ITmfTimestamp ts1
= new TmfTimestamp(12345, 0);
43 private final ITmfTimestamp ts2
= new TmfTimestamp(12345, -1);
44 private final ITmfTimestamp ts3
= new TmfTimestamp(12345, 2, 5);
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
51 public void testDefaultConstructor() {
52 assertEquals("getValue", 0, ts0
.getValue());
53 assertEquals("getscale", 0, ts0
.getScale());
54 assertEquals("getPrecision", 0, ts0
.getPrecision());
58 public void testValueConstructor() {
59 assertEquals("getValue", 12345, ts1
.getValue());
60 assertEquals("getscale", 0, ts1
.getScale());
61 assertEquals("getPrecision", 0, ts1
.getPrecision());
65 public void testValueScaleConstructor() {
66 assertEquals("getValue", 12345, ts2
.getValue());
67 assertEquals("getscale", -1, ts2
.getScale());
68 assertEquals("getPrecision", 0, ts2
.getPrecision());
72 public void testFullConstructor() {
73 assertEquals("getValue", 12345, ts3
.getValue());
74 assertEquals("getscale", 2, ts3
.getScale());
75 assertEquals("getPrecision", 5, ts3
.getPrecision());
79 public void testCopyConstructor() {
80 final ITmfTimestamp ts
= new TmfTimestamp(12345, 2, 5);
81 final ITmfTimestamp copy
= new TmfTimestamp(ts
);
83 assertEquals("getValue", ts
.getValue(), copy
.getValue());
84 assertEquals("getscale", ts
.getScale(), copy
.getScale());
85 assertEquals("getPrecision", ts
.getPrecision(), copy
.getPrecision());
87 assertEquals("getValue", 12345, copy
.getValue());
88 assertEquals("getscale", 2, copy
.getScale());
89 assertEquals("getPrecision", 5, copy
.getPrecision());
93 public void testCopyNullConstructor() {
95 new TmfTimestamp(null);
96 fail("TmfTimestamp: null argument");
97 } catch (final IllegalArgumentException e
) {
102 public void testCopyConstructorBigBang() {
103 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_BANG
);
104 assertEquals("getValue", TmfTimestamp
.BIG_BANG
.getValue(), ts
.getValue());
105 assertEquals("getscale", TmfTimestamp
.BIG_BANG
.getScale(), ts
.getScale());
106 assertEquals("getPrecision", TmfTimestamp
.BIG_BANG
.getPrecision(), ts
.getPrecision());
110 public void testCopyConstructorBigCrunch() {
111 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_CRUNCH
);
112 assertEquals("getValue", TmfTimestamp
.BIG_CRUNCH
.getValue(), ts
.getValue());
113 assertEquals("getscale", TmfTimestamp
.BIG_CRUNCH
.getScale(), ts
.getScale());
114 assertEquals("getPrecision", TmfTimestamp
.BIG_CRUNCH
.getPrecision(), ts
.getPrecision());
118 public void testCopyConstructorZero() {
119 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.ZERO
);
120 assertEquals("getValue", TmfTimestamp
.ZERO
.getValue(), ts
.getValue());
121 assertEquals("getscale", TmfTimestamp
.ZERO
.getScale(), ts
.getScale());
122 assertEquals("getPrecision", TmfTimestamp
.ZERO
.getPrecision(), ts
.getPrecision());
125 // ------------------------------------------------------------------------
127 // ------------------------------------------------------------------------
130 public void testHashCode() {
131 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
132 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
133 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
135 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
136 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
137 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
139 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
147 public void testEqualsReflexivity() {
148 assertTrue("equals", ts0
.equals(ts0
));
149 assertTrue("equals", ts1
.equals(ts1
));
151 assertTrue("equals", !ts0
.equals(ts1
));
152 assertTrue("equals", !ts1
.equals(ts0
));
156 public void testEqualsSymmetry() {
157 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
158 assertTrue("equals", ts0
.equals(ts0copy
));
159 assertTrue("equals", ts0copy
.equals(ts0
));
161 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
162 assertTrue("equals", ts1
.equals(ts1copy
));
163 assertTrue("equals", ts1copy
.equals(ts1
));
165 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
166 assertTrue("equals", ts2
.equals(ts2copy
));
167 assertTrue("equals", ts2copy
.equals(ts2
));
171 public void testEqualsTransivity() {
172 final ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
173 final ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
174 assertTrue("equals", ts0
.equals(ts0copy1
));
175 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
176 assertTrue("equals", ts0
.equals(ts0copy2
));
178 final ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
179 final ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
180 assertTrue("equals", ts1
.equals(ts1copy1
));
181 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
182 assertTrue("equals", ts1
.equals(ts1copy2
));
184 final ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
185 final ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
186 assertTrue("equals", ts2
.equals(ts2copy1
));
187 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
188 assertTrue("equals", ts2
.equals(ts2copy2
));
192 public void testEqualsNull() {
193 assertTrue("equals", !ts0
.equals(null));
194 assertTrue("equals", !ts1
.equals(null));
198 public void testEqualsNonTimestamp() {
199 assertFalse("equals", ts0
.equals(ts0
.toString()));
202 // ------------------------------------------------------------------------
204 // ------------------------------------------------------------------------
207 public void testToStringDefault() {
208 DateFormat df
= new SimpleDateFormat("HH:mm:ss.SSS");
209 Date d0
= new Date(ts0
.getValue() * (long) Math
.pow(10, ts0
.getScale() + 3));
210 Date d1
= new Date(ts1
.getValue() * (long) Math
.pow(10, ts1
.getScale() + 3));
211 Date d2
= new Date(ts2
.getValue() * (long) Math
.pow(10, ts2
.getScale() + 3));
212 Date d3
= new Date(ts3
.getValue() * (long) Math
.pow(10, ts3
.getScale() + 3));
213 assertEquals("toString", df
.format(d0
) + " 000 000", ts0
.toString());
214 assertEquals("toString", df
.format(d1
) + " 000 000", ts1
.toString());
215 assertEquals("toString", df
.format(d2
) + " 000 000", ts2
.toString());
216 assertEquals("toString", df
.format(d3
) + " 000 000", ts3
.toString());
220 public void testToStringInterval() {
221 assertEquals("toString", "000.000 000 000", ts0
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
222 assertEquals("toString", "12345.000 000 000", ts1
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
223 assertEquals("toString", "1234.500 000 000", ts2
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
224 assertEquals("toString", "1234500.000 000 000", ts3
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
227 // ------------------------------------------------------------------------
229 // ------------------------------------------------------------------------
232 public void testNormalizeOffset() {
233 ITmfTimestamp ts
= ts0
.normalize(0, 0);
234 assertEquals("getValue", 0, ts
.getValue());
235 assertEquals("getscale", 0, ts
.getScale());
236 assertEquals("getPrecision", 0, ts
.getPrecision());
238 ts
= ts0
.normalize(12345, 0);
239 assertEquals("getValue", 12345, ts
.getValue());
240 assertEquals("getscale", 0, ts
.getScale());
241 assertEquals("getPrecision", 0, ts
.getPrecision());
243 ts
= ts0
.normalize(10, 0);
244 assertEquals("getValue", 10, ts
.getValue());
245 assertEquals("getscale", 0, ts
.getScale());
246 assertEquals("getPrecision", 0, ts
.getPrecision());
248 ts
= ts0
.normalize(-10, 0);
249 assertEquals("getValue", -10, ts
.getValue());
250 assertEquals("getscale", 0, ts
.getScale());
251 assertEquals("getPrecision", 0, ts
.getPrecision());
255 public void testNormalizeOffsetLowerLimits() {
256 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5, 0);
258 ITmfTimestamp ts
= ref
.normalize(-4, 0);
259 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
260 assertEquals("getscale", 0, ts
.getScale());
261 assertEquals("getPrecision", 0, ts
.getPrecision());
263 ts
= ref
.normalize(-5, 0);
264 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
265 assertEquals("getscale", 0, ts
.getScale());
266 assertEquals("getPrecision", 0, ts
.getPrecision());
268 ts
= ref
.normalize(-6, 0);
269 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
270 assertEquals("getscale", 0, ts
.getScale());
271 assertEquals("getPrecision", 0, ts
.getPrecision());
275 public void testNormalizeOffsetUpperLimits() {
276 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5, 0);
278 ITmfTimestamp ts
= ref
.normalize(4, 0);
279 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
280 assertEquals("getscale", 0, ts
.getScale());
281 assertEquals("getPrecision", 0, ts
.getPrecision());
283 ts
= ref
.normalize(5, 0);
284 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
285 assertEquals("getscale", 0, ts
.getScale());
286 assertEquals("getPrecision", 0, ts
.getPrecision());
288 ts
= ref
.normalize(6, 0);
289 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
290 assertEquals("getscale", 0, ts
.getScale());
291 assertEquals("getPrecision", 0, ts
.getPrecision());
295 public void testNormalizeScale() {
296 ITmfTimestamp ts
= ts0
.normalize(0, 10);
297 assertEquals("getValue", 0, ts
.getValue());
298 assertEquals("getscale", 10, ts
.getScale());
299 assertEquals("getPrecision", 0, ts
.getPrecision());
301 ts
= ts0
.normalize(0, -10);
302 assertEquals("getValue", 0, ts
.getValue());
303 assertEquals("getscale", -10, ts
.getScale());
304 assertEquals("getPrecision", 0, ts
.getPrecision());
308 public void testNormalizedScaleLimits() {
309 final int MAX_SCALE_DIFF
= 19;
313 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
314 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
315 } catch (final ArithmeticException e
) {
316 fail("normalize: scale error");
321 ts1
.normalize(0, +MAX_SCALE_DIFF
);
322 fail("normalize: scale error");
323 ts1
.normalize(0, -MAX_SCALE_DIFF
);
324 fail("normalize: scale error");
325 } catch (final ArithmeticException e
) {
330 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
331 fail("normalize: scale error");
332 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
333 fail("normalize: scale error");
334 } catch (final ArithmeticException e
) {
339 public void testNormalizeOffsetAndScaleTrivial() {
340 final ITmfTimestamp ts
= ts0
.normalize(0, 0);
341 assertEquals("getValue", 0, ts
.getValue());
342 assertEquals("getscale", 0, ts
.getScale());
343 assertEquals("getPrecision", 0, ts
.getPrecision());
347 public void testNormalizeOffsetAndScale() {
348 final int SCALE
= 12;
350 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
351 assertEquals("getValue", 0, ts
.getValue());
352 assertEquals("getscale", SCALE
, ts
.getScale());
353 assertEquals("getPrecision", 0, ts
.getPrecision());
355 ts
= ts0
.normalize(12345, SCALE
);
356 assertEquals("getValue", 12345, ts
.getValue());
357 assertEquals("getscale", SCALE
, ts
.getScale());
358 assertEquals("getPrecision", 0, ts
.getPrecision());
360 ts
= ts0
.normalize(10, SCALE
);
361 assertEquals("getValue", 10, ts
.getValue());
362 assertEquals("getscale", SCALE
, ts
.getScale());
363 assertEquals("getPrecision", 0, ts
.getPrecision());
365 ts
= ts0
.normalize(-10, SCALE
);
366 assertEquals("getValue", -10, ts
.getValue());
367 assertEquals("getscale", SCALE
, ts
.getScale());
368 assertEquals("getPrecision", 0, ts
.getPrecision());
372 public void testNormalizeOffsetAndScale2() {
374 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
375 assertEquals("getValue", 123, ts
.getValue());
376 assertEquals("getscale", SCALE
, ts
.getScale());
377 assertEquals("getPrecision", 0, ts
.getPrecision());
379 ts
= ts1
.normalize(12345, SCALE
);
380 assertEquals("getValue", 12468, ts
.getValue());
381 assertEquals("getscale", SCALE
, ts
.getScale());
382 assertEquals("getPrecision", 0, ts
.getPrecision());
385 ts
= ts1
.normalize(0, SCALE
);
386 assertEquals("getValue", 1234500, ts
.getValue());
387 assertEquals("getscale", SCALE
, ts
.getScale());
388 assertEquals("getPrecision", 0, ts
.getPrecision());
390 ts
= ts1
.normalize(67, SCALE
);
391 assertEquals("getValue", 1234567, ts
.getValue());
392 assertEquals("getscale", SCALE
, ts
.getScale());
393 assertEquals("getPrecision", 0, ts
.getPrecision());
396 // ------------------------------------------------------------------------
398 // ------------------------------------------------------------------------
401 public void testBasicCompareTo() {
402 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
403 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
404 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
405 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
407 assertTrue(t1
.compareTo(t1
) == 0);
409 assertTrue("CompareTo", t1
.compareTo(t2
) < 0);
410 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
411 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
413 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
414 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
415 assertTrue("CompareTo", t2
.compareTo(t4
) == 0);
417 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
418 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
419 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
423 public void testCompareToCornerCases1() {
424 final ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
425 final ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
426 final ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
427 final ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
429 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
430 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
431 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
432 assertTrue("compareTo", ts0
.compareTo(ts0c
, false) == -1);
433 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
437 public void testCompareToCornerCases2() {
438 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
439 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
440 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
442 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == 1);
443 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == -1);
445 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == -1);
446 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == -1);
448 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == 1);
449 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == 1);
453 public void testCompareToCornerCases3() {
454 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
455 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
456 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
458 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == -1);
459 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == 1);
461 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == 1);
462 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == 1);
464 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == -1);
465 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == -1);
469 public void testCompareToCornerCases4() {
470 assertTrue("compareTo", ts0
.compareTo(null, false) == 1);
471 assertTrue("compareTo", ts0
.compareTo(null, true) == 1);
475 public void testCompareToSameScale() {
476 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
477 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
478 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
479 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
481 assertTrue(t1
.compareTo(t1
, false) == 0);
483 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
484 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
485 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
487 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
488 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
489 assertTrue("CompareTo", t2
.compareTo(t4
, false) == 0);
491 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
492 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
493 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
497 public void testCompareToDifferentScale() {
498 final ITmfTimestamp t1
= new TmfTimestamp(9000, -1, 50);
499 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
500 final ITmfTimestamp t3
= new TmfTimestamp(110, 1, 50);
501 final ITmfTimestamp t4
= new TmfTimestamp(1, 3, 75);
503 assertTrue("CompareTo", t1
.compareTo(t1
, false) == 0);
505 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
506 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
507 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
509 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
510 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
511 assertTrue("CompareTo", t2
.compareTo(t4
, false) == 0);
513 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
514 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
515 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
519 public void testCompareToWithinPrecision() {
520 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
521 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
522 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
523 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
525 assertTrue("CompareTo", t1
.compareTo(t1
, true) == 0);
527 assertTrue("CompareTo", t1
.compareTo(t2
, true) == 0);
528 assertTrue("CompareTo", t1
.compareTo(t3
, true) < 0);
529 assertTrue("CompareTo", t1
.compareTo(t4
, true) == 0);
531 assertTrue("CompareTo", t2
.compareTo(t1
, true) == 0);
532 assertTrue("CompareTo", t2
.compareTo(t3
, true) == 0);
533 assertTrue("CompareTo", t2
.compareTo(t4
, true) == 0);
535 assertTrue("CompareTo", t3
.compareTo(t1
, true) > 0);
536 assertTrue("CompareTo", t3
.compareTo(t2
, true) == 0);
537 assertTrue("CompareTo", t3
.compareTo(t4
, true) == 0);
541 public void testCompareToLargeScale1() {
542 final ITmfTimestamp t1
= new TmfTimestamp(-1, 100);
543 final ITmfTimestamp t2
= new TmfTimestamp(-1000, -100);
544 final ITmfTimestamp t3
= new TmfTimestamp(1, 100);
545 final ITmfTimestamp t4
= new TmfTimestamp(1000, -100);
547 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
548 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
549 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
551 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
552 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
553 assertTrue("CompareTo", t2
.compareTo(t4
, false) < 0);
555 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
556 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
557 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
559 assertTrue("CompareTo", t4
.compareTo(t1
, false) > 0);
560 assertTrue("CompareTo", t4
.compareTo(t2
, false) > 0);
561 assertTrue("CompareTo", t4
.compareTo(t3
, false) < 0);
565 public void testCompareToLargeScale2() {
566 final ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
567 final ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
569 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
570 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
572 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
573 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
576 // ------------------------------------------------------------------------
578 // ------------------------------------------------------------------------
581 public void testDelta() {
582 // Delta for same scale and precision (delta > 0)
583 ITmfTimestamp t0
= new TmfTimestamp(10, 9);
584 ITmfTimestamp t1
= new TmfTimestamp(5, 9);
585 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
587 ITmfTimestamp delta
= t0
.getDelta(t1
);
588 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
590 // Delta for same scale and precision (delta < 0)
591 t0
= new TmfTimestamp(5, 9);
592 t1
= new TmfTimestamp(10, 9);
593 exp
= new TmfTimestamp(-5, 9);
595 delta
= t0
.getDelta(t1
);
596 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
598 // Delta for different scale and same precision (delta > 0)
599 t0
= new TmfTimestamp(5, 9);
600 t1
= new TmfTimestamp(10, 8);
601 exp
= new TmfTimestamp(4, 9);
603 delta
= t0
.getDelta(t1
);
604 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
606 // Delta for different scale and same precision (delta > 0)
607 t0
= new TmfTimestamp(5, 9);
608 t1
= new TmfTimestamp(10, 7);
609 exp
= new TmfTimestamp(5, 9);
611 delta
= t0
.getDelta(t1
);
612 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
614 // Delta for different scale and same precision
615 t0
= new TmfTimestamp(10, 9);
616 t1
= new TmfTimestamp(5, 8);
617 exp
= new TmfTimestamp(10, 9);
619 delta
= t0
.getDelta(t1
);
620 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
622 // Delta for same scale and different precision
623 t0
= new TmfTimestamp(10, 9, 1);
624 t1
= new TmfTimestamp(5, 9, 2);
625 exp
= new TmfTimestamp(5, 9, 3);
627 delta
= t0
.getDelta(t1
);
628 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
629 assertEquals("precision", 3, delta
.getPrecision());
631 // Delta for same scale and different precision
632 t0
= new TmfTimestamp(5, 9, 2);
633 t1
= new TmfTimestamp(10, 9, 1);
634 exp
= new TmfTimestamp(-5, 9, 3);
636 delta
= t0
.getDelta(t1
);
637 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
638 assertEquals("precision", 3, delta
.getPrecision());
640 // Delta for different scale and different precision
641 t0
= new TmfTimestamp(5, 9, 2);
642 t1
= new TmfTimestamp(10, 8, 1);
643 exp
= new TmfTimestamp(4, 9, 3);
644 delta
= t0
.getDelta(t1
);
645 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
646 assertEquals("precision", 2, delta
.getPrecision());