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 * Patrick Tasse - Updated for negative value formatting
14 *******************************************************************************/
16 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.event
;
18 import static org
.junit
.Assert
.assertEquals
;
19 import static org
.junit
.Assert
.assertFalse
;
20 import static org
.junit
.Assert
.assertTrue
;
21 import static org
.junit
.Assert
.fail
;
23 import java
.text
.DateFormat
;
24 import java
.text
.SimpleDateFormat
;
25 import java
.util
.Date
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestampFormat
;
30 import org
.junit
.Test
;
33 * Test suite for the TmfTimestamp class.
35 @SuppressWarnings("javadoc")
36 public class TmfTimestampTest
{
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
42 private final ITmfTimestamp ts0
= new TmfTimestamp();
43 private final ITmfTimestamp ts1
= new TmfTimestamp(12345, 0);
44 private final ITmfTimestamp ts2
= new TmfTimestamp(12345, -1);
45 private final ITmfTimestamp ts3
= new TmfTimestamp(12345, 2, 5);
46 private final ITmfTimestamp ts4
= new TmfTimestamp(12345, -3, 0);
47 private final ITmfTimestamp ts5
= new TmfTimestamp(12345, -6, 0);
48 private final ITmfTimestamp ts6
= new TmfTimestamp(12345, -9, 0);
49 private final ITmfTimestamp ts7
= new TmfTimestamp(-12345, -3, 0);
50 private final ITmfTimestamp ts8
= new TmfTimestamp(-12345, -6, 0);
51 private final ITmfTimestamp ts9
= new TmfTimestamp(-12345, -9, 0);
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 public void testDefaultConstructor() {
59 assertEquals("getValue", 0, ts0
.getValue());
60 assertEquals("getscale", 0, ts0
.getScale());
61 assertEquals("getPrecision", 0, ts0
.getPrecision());
65 public void testValueConstructor() {
66 assertEquals("getValue", 12345, ts1
.getValue());
67 assertEquals("getscale", 0, ts1
.getScale());
68 assertEquals("getPrecision", 0, ts1
.getPrecision());
72 public void testValueScaleConstructor() {
73 assertEquals("getValue", 12345, ts2
.getValue());
74 assertEquals("getscale", -1, ts2
.getScale());
75 assertEquals("getPrecision", 0, ts2
.getPrecision());
79 public void testFullConstructor() {
80 assertEquals("getValue", 12345, ts3
.getValue());
81 assertEquals("getscale", 2, ts3
.getScale());
82 assertEquals("getPrecision", 5, ts3
.getPrecision());
86 public void testCopyConstructor() {
87 final ITmfTimestamp ts
= new TmfTimestamp(12345, 2, 5);
88 final ITmfTimestamp copy
= new TmfTimestamp(ts
);
90 assertEquals("getValue", ts
.getValue(), copy
.getValue());
91 assertEquals("getscale", ts
.getScale(), copy
.getScale());
92 assertEquals("getPrecision", ts
.getPrecision(), copy
.getPrecision());
94 assertEquals("getValue", 12345, copy
.getValue());
95 assertEquals("getscale", 2, copy
.getScale());
96 assertEquals("getPrecision", 5, copy
.getPrecision());
99 @Test(expected
=IllegalArgumentException
.class)
100 public void testCopyNullConstructor() {
101 new TmfTimestamp((TmfTimestamp
) null);
105 public void testCopyConstructorBigBang() {
106 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BIG_BANG
);
107 assertEquals("getValue", TmfTimestamp
.BIG_BANG
.getValue(), ts
.getValue());
108 assertEquals("getscale", TmfTimestamp
.BIG_BANG
.getScale(), ts
.getScale());
109 assertEquals("getPrecision", TmfTimestamp
.BIG_BANG
.getPrecision(), ts
.getPrecision());
113 public void testCopyConstructorBigCrunch() {
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());
121 public void testCopyConstructorZero() {
122 final ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.ZERO
);
123 assertEquals("getValue", TmfTimestamp
.ZERO
.getValue(), ts
.getValue());
124 assertEquals("getscale", TmfTimestamp
.ZERO
.getScale(), ts
.getScale());
125 assertEquals("getPrecision", TmfTimestamp
.ZERO
.getPrecision(), ts
.getPrecision());
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 public void testHashCode() {
134 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
135 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
136 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
138 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
139 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
140 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
142 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
145 // ------------------------------------------------------------------------
147 // ------------------------------------------------------------------------
150 public void testEqualsReflexivity() {
151 assertTrue("equals", ts0
.equals(ts0
));
152 assertTrue("equals", ts1
.equals(ts1
));
154 assertTrue("equals", !ts0
.equals(ts1
));
155 assertTrue("equals", !ts1
.equals(ts0
));
159 public void testEqualsSymmetry() {
160 final ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
161 assertTrue("equals", ts0
.equals(ts0copy
));
162 assertTrue("equals", ts0copy
.equals(ts0
));
164 final ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
165 assertTrue("equals", ts1
.equals(ts1copy
));
166 assertTrue("equals", ts1copy
.equals(ts1
));
168 final ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
169 assertTrue("equals", ts2
.equals(ts2copy
));
170 assertTrue("equals", ts2copy
.equals(ts2
));
174 public void testEqualsTransivity() {
175 final ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
176 final ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
177 assertTrue("equals", ts0
.equals(ts0copy1
));
178 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
179 assertTrue("equals", ts0
.equals(ts0copy2
));
181 final ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
182 final ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
183 assertTrue("equals", ts1
.equals(ts1copy1
));
184 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
185 assertTrue("equals", ts1
.equals(ts1copy2
));
187 final ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
188 final ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
189 assertTrue("equals", ts2
.equals(ts2copy1
));
190 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
191 assertTrue("equals", ts2
.equals(ts2copy2
));
195 public void testEqualsNull() {
196 assertTrue("equals", !ts0
.equals(null));
197 assertTrue("equals", !ts1
.equals(null));
201 public void testEqualsNonTimestamp() {
202 assertFalse("equals", ts0
.equals(ts0
.toString()));
205 // ------------------------------------------------------------------------
207 // ------------------------------------------------------------------------
210 public void testToStringDefault() {
211 DateFormat df
= new SimpleDateFormat("HH:mm:ss.SSS");
212 Date d0
= new Date((long) (ts0
.getValue() * Math
.pow(10, ts0
.getScale() + 3)));
213 Date d1
= new Date((long) (ts1
.getValue() * Math
.pow(10, ts1
.getScale() + 3)));
214 Date d2
= new Date((long) (ts2
.getValue() * Math
.pow(10, ts2
.getScale() + 3)));
215 Date d3
= new Date((long) (ts3
.getValue() * Math
.pow(10, ts3
.getScale() + 3)));
216 Date d4
= new Date((long) (ts4
.getValue() * Math
.pow(10, ts4
.getScale() + 3)));
217 Date d5
= new Date((long) (ts5
.getValue() * Math
.pow(10, ts5
.getScale() + 3)));
218 Date d6
= new Date((long) (ts6
.getValue() * Math
.pow(10, ts6
.getScale() + 3)));
219 Date d7
= new Date((long) (ts7
.getValue() * Math
.pow(10, ts7
.getScale() + 3)));
220 Date d8
= new Date((long) (ts8
.getValue() * Math
.pow(10, ts8
.getScale() + 3)) - 1);
221 Date d9
= new Date((long) (ts9
.getValue() * Math
.pow(10, ts9
.getScale() + 3)) - 1);
222 assertEquals("toString", df
.format(d0
) + " 000 000", ts0
.toString());
223 assertEquals("toString", df
.format(d1
) + " 000 000", ts1
.toString());
224 assertEquals("toString", df
.format(d2
) + " 000 000", ts2
.toString());
225 assertEquals("toString", df
.format(d3
) + " 000 000", ts3
.toString());
226 assertEquals("toString", df
.format(d4
) + " 000 000", ts4
.toString());
227 assertEquals("toString", df
.format(d5
) + " 345 000", ts5
.toString());
228 assertEquals("toString", df
.format(d6
) + " 012 345", ts6
.toString());
229 assertEquals("toString", df
.format(d7
) + " 000 000", ts7
.toString());
230 assertEquals("toString", df
.format(d8
) + " 655 000", ts8
.toString());
231 assertEquals("toString", df
.format(d9
) + " 987 655", ts9
.toString());
235 public void testToStringInterval() {
236 assertEquals("toString", "000.000 000 000", ts0
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
237 assertEquals("toString", "12345.000 000 000", ts1
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
238 assertEquals("toString", "1234.500 000 000", ts2
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
239 assertEquals("toString", "1234500.000 000 000", ts3
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
240 assertEquals("toString", "012.345 000 000", ts4
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
241 assertEquals("toString", "000.012 345 000", ts5
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
242 assertEquals("toString", "000.000 012 345", ts6
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
243 assertEquals("toString", "-012.345 000 000", ts7
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
244 assertEquals("toString", "-000.012 345 000", ts8
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
245 assertEquals("toString", "-000.000 012 345", ts9
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
248 // ------------------------------------------------------------------------
250 // ------------------------------------------------------------------------
253 public void testNormalizeOffset() {
254 ITmfTimestamp ts
= ts0
.normalize(0, 0);
255 assertEquals("getValue", 0, ts
.getValue());
256 assertEquals("getscale", 0, ts
.getScale());
257 assertEquals("getPrecision", 0, ts
.getPrecision());
259 ts
= ts0
.normalize(12345, 0);
260 assertEquals("getValue", 12345, ts
.getValue());
261 assertEquals("getscale", 0, ts
.getScale());
262 assertEquals("getPrecision", 0, ts
.getPrecision());
264 ts
= ts0
.normalize(10, 0);
265 assertEquals("getValue", 10, ts
.getValue());
266 assertEquals("getscale", 0, ts
.getScale());
267 assertEquals("getPrecision", 0, ts
.getPrecision());
269 ts
= ts0
.normalize(-10, 0);
270 assertEquals("getValue", -10, ts
.getValue());
271 assertEquals("getscale", 0, ts
.getScale());
272 assertEquals("getPrecision", 0, ts
.getPrecision());
276 public void testNormalizeOffsetLowerLimits() {
277 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5, 0);
279 ITmfTimestamp ts
= ref
.normalize(-4, 0);
280 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
281 assertEquals("getscale", 0, ts
.getScale());
282 assertEquals("getPrecision", 0, ts
.getPrecision());
284 ts
= ref
.normalize(-5, 0);
285 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
286 assertEquals("getscale", 0, ts
.getScale());
287 assertEquals("getPrecision", 0, ts
.getPrecision());
289 ts
= ref
.normalize(-6, 0);
290 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
291 assertEquals("getscale", 0, ts
.getScale());
292 assertEquals("getPrecision", 0, ts
.getPrecision());
296 public void testNormalizeOffsetUpperLimits() {
297 final ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5, 0);
299 ITmfTimestamp ts
= ref
.normalize(4, 0);
300 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
301 assertEquals("getscale", 0, ts
.getScale());
302 assertEquals("getPrecision", 0, ts
.getPrecision());
304 ts
= ref
.normalize(5, 0);
305 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
306 assertEquals("getscale", 0, ts
.getScale());
307 assertEquals("getPrecision", 0, ts
.getPrecision());
309 ts
= ref
.normalize(6, 0);
310 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
311 assertEquals("getscale", 0, ts
.getScale());
312 assertEquals("getPrecision", 0, ts
.getPrecision());
316 public void testNormalizeScale() {
317 ITmfTimestamp ts
= ts0
.normalize(0, 10);
318 assertEquals("getValue", 0, ts
.getValue());
319 assertEquals("getscale", 10, ts
.getScale());
320 assertEquals("getPrecision", 0, ts
.getPrecision());
322 ts
= ts0
.normalize(0, -10);
323 assertEquals("getValue", 0, ts
.getValue());
324 assertEquals("getscale", -10, ts
.getScale());
325 assertEquals("getPrecision", 0, ts
.getPrecision());
329 public void testNormalizedScaleLimits() {
330 final int MAX_SCALE_DIFF
= 19;
334 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
335 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
336 } catch (final ArithmeticException e
) {
337 fail("normalize: scale error");
342 ts1
.normalize(0, +MAX_SCALE_DIFF
);
343 fail("normalize: scale error");
344 ts1
.normalize(0, -MAX_SCALE_DIFF
);
345 fail("normalize: scale error");
346 } catch (final ArithmeticException e
) {
351 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
352 fail("normalize: scale error");
353 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
354 fail("normalize: scale error");
355 } catch (final ArithmeticException e
) {
360 public void testNormalizeOffsetAndScaleTrivial() {
361 final ITmfTimestamp ts
= ts0
.normalize(0, 0);
362 assertEquals("getValue", 0, ts
.getValue());
363 assertEquals("getscale", 0, ts
.getScale());
364 assertEquals("getPrecision", 0, ts
.getPrecision());
368 public void testNormalizeOffsetAndScale() {
369 final int SCALE
= 12;
371 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
372 assertEquals("getValue", 0, ts
.getValue());
373 assertEquals("getscale", SCALE
, ts
.getScale());
374 assertEquals("getPrecision", 0, ts
.getPrecision());
376 ts
= ts0
.normalize(12345, SCALE
);
377 assertEquals("getValue", 12345, ts
.getValue());
378 assertEquals("getscale", SCALE
, ts
.getScale());
379 assertEquals("getPrecision", 0, ts
.getPrecision());
381 ts
= ts0
.normalize(10, SCALE
);
382 assertEquals("getValue", 10, ts
.getValue());
383 assertEquals("getscale", SCALE
, ts
.getScale());
384 assertEquals("getPrecision", 0, ts
.getPrecision());
386 ts
= ts0
.normalize(-10, SCALE
);
387 assertEquals("getValue", -10, ts
.getValue());
388 assertEquals("getscale", SCALE
, ts
.getScale());
389 assertEquals("getPrecision", 0, ts
.getPrecision());
393 public void testNormalizeOffsetAndScale2() {
395 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
396 assertEquals("getValue", 123, ts
.getValue());
397 assertEquals("getscale", SCALE
, ts
.getScale());
398 assertEquals("getPrecision", 0, ts
.getPrecision());
400 ts
= ts1
.normalize(12345, SCALE
);
401 assertEquals("getValue", 12468, ts
.getValue());
402 assertEquals("getscale", SCALE
, ts
.getScale());
403 assertEquals("getPrecision", 0, ts
.getPrecision());
406 ts
= ts1
.normalize(0, SCALE
);
407 assertEquals("getValue", 1234500, ts
.getValue());
408 assertEquals("getscale", SCALE
, ts
.getScale());
409 assertEquals("getPrecision", 0, ts
.getPrecision());
411 ts
= ts1
.normalize(67, SCALE
);
412 assertEquals("getValue", 1234567, ts
.getValue());
413 assertEquals("getscale", SCALE
, ts
.getScale());
414 assertEquals("getPrecision", 0, ts
.getPrecision());
417 // ------------------------------------------------------------------------
419 // ------------------------------------------------------------------------
422 public void testBasicCompareTo() {
423 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
424 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
425 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
426 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
428 assertTrue(t1
.compareTo(t1
) == 0);
430 assertTrue("CompareTo", t1
.compareTo(t2
) < 0);
431 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
432 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
434 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
435 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
436 assertTrue("CompareTo", t2
.compareTo(t4
) == 0);
438 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
439 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
440 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
444 public void testCompareToCornerCases1() {
445 final ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
446 final ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
447 final ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
448 final ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
450 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
451 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
452 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
453 assertTrue("compareTo", ts0
.compareTo(ts0c
, false) == -1);
454 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
458 public void testCompareToCornerCases2() {
459 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
460 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
461 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
463 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == 1);
464 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == -1);
466 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == -1);
467 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == -1);
469 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == 1);
470 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == 1);
474 public void testCompareToCornerCases3() {
475 final ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
476 final ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
477 final ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
479 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false) == -1);
480 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false) == 1);
482 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false) == 1);
483 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false) == 1);
485 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false) == -1);
486 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false) == -1);
490 public void testCompareToCornerCases4() {
491 assertTrue("compareTo", ts0
.compareTo(null, false) == 1);
492 assertTrue("compareTo", ts0
.compareTo(null, true) == 1);
496 public void testCompareToSameScale() {
497 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
498 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
499 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
500 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
502 assertTrue(t1
.compareTo(t1
, false) == 0);
504 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
505 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
506 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
508 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
509 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
510 assertTrue("CompareTo", t2
.compareTo(t4
, false) == 0);
512 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
513 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
514 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
518 public void testCompareToDifferentScale() {
519 final ITmfTimestamp t1
= new TmfTimestamp(9000, -1, 50);
520 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
521 final ITmfTimestamp t3
= new TmfTimestamp(110, 1, 50);
522 final ITmfTimestamp t4
= new TmfTimestamp(1, 3, 75);
524 assertTrue("CompareTo", t1
.compareTo(t1
, false) == 0);
526 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
527 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
528 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
530 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
531 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
532 assertTrue("CompareTo", t2
.compareTo(t4
, false) == 0);
534 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
535 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
536 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
540 public void testCompareToWithinPrecision() {
541 final ITmfTimestamp t1
= new TmfTimestamp(900, 0, 50);
542 final ITmfTimestamp t2
= new TmfTimestamp(1000, 0, 50);
543 final ITmfTimestamp t3
= new TmfTimestamp(1100, 0, 50);
544 final ITmfTimestamp t4
= new TmfTimestamp(1000, 0, 75);
546 assertTrue("CompareTo", t1
.compareTo(t1
, true) == 0);
548 assertTrue("CompareTo", t1
.compareTo(t2
, true) == 0);
549 assertTrue("CompareTo", t1
.compareTo(t3
, true) < 0);
550 assertTrue("CompareTo", t1
.compareTo(t4
, true) == 0);
552 assertTrue("CompareTo", t2
.compareTo(t1
, true) == 0);
553 assertTrue("CompareTo", t2
.compareTo(t3
, true) == 0);
554 assertTrue("CompareTo", t2
.compareTo(t4
, true) == 0);
556 assertTrue("CompareTo", t3
.compareTo(t1
, true) > 0);
557 assertTrue("CompareTo", t3
.compareTo(t2
, true) == 0);
558 assertTrue("CompareTo", t3
.compareTo(t4
, true) == 0);
562 public void testCompareToLargeScale1() {
563 final ITmfTimestamp t1
= new TmfTimestamp(-1, 100);
564 final ITmfTimestamp t2
= new TmfTimestamp(-1000, -100);
565 final ITmfTimestamp t3
= new TmfTimestamp(1, 100);
566 final ITmfTimestamp t4
= new TmfTimestamp(1000, -100);
568 assertTrue("CompareTo", t1
.compareTo(t2
, false) < 0);
569 assertTrue("CompareTo", t1
.compareTo(t3
, false) < 0);
570 assertTrue("CompareTo", t1
.compareTo(t4
, false) < 0);
572 assertTrue("CompareTo", t2
.compareTo(t1
, false) > 0);
573 assertTrue("CompareTo", t2
.compareTo(t3
, false) < 0);
574 assertTrue("CompareTo", t2
.compareTo(t4
, false) < 0);
576 assertTrue("CompareTo", t3
.compareTo(t1
, false) > 0);
577 assertTrue("CompareTo", t3
.compareTo(t2
, false) > 0);
578 assertTrue("CompareTo", t3
.compareTo(t4
, false) > 0);
580 assertTrue("CompareTo", t4
.compareTo(t1
, false) > 0);
581 assertTrue("CompareTo", t4
.compareTo(t2
, false) > 0);
582 assertTrue("CompareTo", t4
.compareTo(t3
, false) < 0);
586 public void testCompareToLargeScale2() {
587 final ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
588 final ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
590 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
591 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
593 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
594 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
597 // ------------------------------------------------------------------------
599 // ------------------------------------------------------------------------
602 public void testDelta() {
603 // Delta for same scale and precision (delta > 0)
604 ITmfTimestamp t0
= new TmfTimestamp(10, 9);
605 ITmfTimestamp t1
= new TmfTimestamp(5, 9);
606 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
608 ITmfTimestamp delta
= t0
.getDelta(t1
);
609 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
611 // Delta for same scale and precision (delta < 0)
612 t0
= new TmfTimestamp(5, 9);
613 t1
= new TmfTimestamp(10, 9);
614 exp
= new TmfTimestamp(-5, 9);
616 delta
= t0
.getDelta(t1
);
617 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
619 // Delta for different scale and same precision (delta > 0)
620 t0
= new TmfTimestamp(5, 9);
621 t1
= new TmfTimestamp(10, 8);
622 exp
= new TmfTimestamp(4, 9);
624 delta
= t0
.getDelta(t1
);
625 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
627 // Delta for different scale and same precision (delta > 0)
628 t0
= new TmfTimestamp(5, 9);
629 t1
= new TmfTimestamp(10, 7);
630 exp
= new TmfTimestamp(5, 9);
632 delta
= t0
.getDelta(t1
);
633 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
635 // Delta for different scale and same precision
636 t0
= new TmfTimestamp(10, 9);
637 t1
= new TmfTimestamp(5, 8);
638 exp
= new TmfTimestamp(10, 9);
640 delta
= t0
.getDelta(t1
);
641 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
643 // Delta for same scale and different precision
644 t0
= new TmfTimestamp(10, 9, 1);
645 t1
= new TmfTimestamp(5, 9, 2);
646 exp
= new TmfTimestamp(5, 9, 3);
648 delta
= t0
.getDelta(t1
);
649 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
650 assertEquals("precision", 3, delta
.getPrecision());
652 // Delta for same scale and different precision
653 t0
= new TmfTimestamp(5, 9, 2);
654 t1
= new TmfTimestamp(10, 9, 1);
655 exp
= new TmfTimestamp(-5, 9, 3);
657 delta
= t0
.getDelta(t1
);
658 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
659 assertEquals("precision", 3, delta
.getPrecision());
661 // Delta for different scale and different precision
662 t0
= new TmfTimestamp(5, 9, 2);
663 t1
= new TmfTimestamp(10, 8, 1);
664 exp
= new TmfTimestamp(4, 9, 3);
665 delta
= t0
.getDelta(t1
);
666 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
667 assertEquals("precision", 2, delta
.getPrecision());
This page took 0.048707 seconds and 5 git commands to generate.