1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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
.tracecompass
.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
;
22 import java
.text
.DateFormat
;
23 import java
.text
.SimpleDateFormat
;
24 import java
.util
.Date
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
28 import org
.eclipse
.tracecompass
.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
= TmfTimestamp
.create(0, ITmfTimestamp
.SECOND_SCALE
);
42 private final ITmfTimestamp ts1
= TmfTimestamp
.create(12345, 0);
43 private final ITmfTimestamp ts2
= TmfTimestamp
.create(12345, -1);
44 private final ITmfTimestamp ts3
= TmfTimestamp
.create(12345, 2);
45 private final ITmfTimestamp ts4
= TmfTimestamp
.create(12345, -3);
46 private final ITmfTimestamp ts5
= TmfTimestamp
.create(12345, -6);
47 private final ITmfTimestamp ts6
= TmfTimestamp
.create(12345, -9);
48 private final ITmfTimestamp ts7
= TmfTimestamp
.create(-12345, -3);
49 private final ITmfTimestamp ts8
= TmfTimestamp
.create(-12345, -6);
50 private final ITmfTimestamp ts9
= TmfTimestamp
.create(-12345, -9);
51 private final ITmfTimestamp ts10
= TmfTimestamp
.create(Long
.MAX_VALUE
/ 100, -6);
52 private final ITmfTimestamp ts11
= TmfTimestamp
.create(Long
.MIN_VALUE
/ 100, -6);
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 public void testDefaultConstructor() {
60 assertEquals("getValue", 0, ts0
.getValue());
61 assertEquals("getscale", 0, ts0
.getScale());
65 public void testValueConstructor() {
66 assertEquals("getValue", 12345, ts1
.getValue());
67 assertEquals("getscale", 0, ts1
.getScale());
71 public void testValueScaleConstructor() {
72 assertEquals("getValue", 12345, ts2
.getValue());
73 assertEquals("getscale", -1, ts2
.getScale());
77 public void testFullConstructor() {
78 assertEquals("getValue", 12345, ts3
.getValue());
79 assertEquals("getscale", 2, ts3
.getScale());
83 public void testCopyConstructor() {
84 final ITmfTimestamp ts
= TmfTimestamp
.create(12345, 2);
85 final ITmfTimestamp copy
= TmfTimestamp
.create(ts
.getValue(), ts
.getScale());
87 assertEquals("getValue", ts
.getValue(), copy
.getValue());
88 assertEquals("getscale", ts
.getScale(), copy
.getScale());
90 assertEquals("getValue", 12345, copy
.getValue());
91 assertEquals("getscale", 2, copy
.getScale());
95 public void testCopyConstructorBigBang() {
96 final ITmfTimestamp ts
= TmfTimestamp
.create(TmfTimestamp
.BIG_BANG
.getValue(), TmfTimestamp
.BIG_BANG
.getScale());
97 assertEquals("getValue", TmfTimestamp
.BIG_BANG
.getValue(), ts
.getValue());
98 assertEquals("getscale", TmfTimestamp
.BIG_BANG
.getScale(), ts
.getScale());
102 public void testCopyConstructorBigCrunch() {
103 final ITmfTimestamp ts
= TmfTimestamp
.create(TmfTimestamp
.BIG_CRUNCH
.getValue(), TmfTimestamp
.BIG_CRUNCH
.getScale());
104 assertEquals("getValue", TmfTimestamp
.BIG_CRUNCH
.getValue(), ts
.getValue());
105 assertEquals("getscale", TmfTimestamp
.BIG_CRUNCH
.getScale(), ts
.getScale());
109 public void testCopyConstructorZero() {
110 final ITmfTimestamp ts
= TmfTimestamp
.create(TmfTimestamp
.ZERO
.getValue(), TmfTimestamp
.ZERO
.getScale());
111 assertEquals("getValue", TmfTimestamp
.ZERO
.getValue(), ts
.getValue());
112 assertEquals("getscale", TmfTimestamp
.ZERO
.getScale(), ts
.getScale());
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 public void testHashCode() {
121 final ITmfTimestamp ts0copy
= TmfTimestamp
.create(ts0
.getValue(), ts0
.getScale());
122 final ITmfTimestamp ts1copy
= TmfTimestamp
.create(ts1
.getValue(), ts1
.getScale());
123 final ITmfTimestamp ts2copy
= TmfTimestamp
.create(ts2
.getValue(), ts2
.getScale());
125 assertEquals("hashCode", ts0
.hashCode(), ts0copy
.hashCode());
126 assertEquals("hashCode", ts1
.hashCode(), ts1copy
.hashCode());
127 assertEquals("hashCode", ts2
.hashCode(), ts2copy
.hashCode());
129 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
132 // ------------------------------------------------------------------------
134 // ------------------------------------------------------------------------
137 public void testEqualsReflexivity() {
138 assertEquals("equals", ts0
, ts0
);
139 assertEquals("equals", ts1
, ts1
);
141 assertFalse("Different", ts0
.equals(ts1
));
142 assertFalse("Different", ts1
.equals(ts0
));
146 public void testEqualsSymmetry() {
147 final ITmfTimestamp ts0copy
= TmfTimestamp
.create(ts0
.getValue(), ts0
.getScale());
148 assertEquals("equals", ts0
, ts0copy
);
149 assertEquals("equals", ts0copy
, ts0
);
151 final ITmfTimestamp ts1copy
= TmfTimestamp
.create(ts1
.getValue(), ts1
.getScale());
152 assertEquals("equals", ts1
, ts1copy
);
153 assertEquals("equals", ts1copy
, ts1
);
155 final ITmfTimestamp ts2copy
= TmfTimestamp
.create(ts2
.getValue(), ts2
.getScale());
156 assertEquals("equals", ts2
, ts2copy
);
157 assertEquals("equals", ts2copy
, ts2
);
161 public void testEqualsTransivity() {
162 final ITmfTimestamp ts0copy1
= TmfTimestamp
.create(ts0
.getValue(), ts0
.getScale());
163 final ITmfTimestamp ts0copy2
= TmfTimestamp
.create(ts0copy1
.getValue(), ts0copy1
.getScale());
164 assertTrue("equals", ts0
.equals(ts0copy1
));
165 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
166 assertTrue("equals", ts0
.equals(ts0copy2
));
168 final ITmfTimestamp ts1copy1
= TmfTimestamp
.create(ts1
.getValue(), ts1
.getScale());
169 final ITmfTimestamp ts1copy2
= TmfTimestamp
.create(ts1copy1
.getValue(), ts1copy1
.getScale());
170 assertTrue("equals", ts1
.equals(ts1copy1
));
171 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
172 assertTrue("equals", ts1
.equals(ts1copy2
));
174 final ITmfTimestamp ts2copy1
= TmfTimestamp
.create(ts2
.getValue(), ts2
.getScale());
175 final ITmfTimestamp ts2copy2
= TmfTimestamp
.create(ts2copy1
.getValue(), ts2copy1
.getScale());
176 assertTrue("equals", ts2
.equals(ts2copy1
));
177 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
178 assertTrue("equals", ts2
.equals(ts2copy2
));
182 public void testEqualsNull() {
183 assertTrue("equals", !ts0
.equals(null));
184 assertTrue("equals", !ts1
.equals(null));
188 public void testEqualsNonTimestamp() {
189 assertFalse("equals", ts0
.equals(ts0
.toString()));
192 // ------------------------------------------------------------------------
194 // ------------------------------------------------------------------------
197 public void testToStringDefault() {
198 DateFormat df
= new SimpleDateFormat("HH:mm:ss.SSS");
199 Date d0
= new Date((long) (ts0
.getValue() * Math
.pow(10, ts0
.getScale() + 3)));
200 Date d1
= new Date((long) (ts1
.getValue() * Math
.pow(10, ts1
.getScale() + 3)));
201 Date d2
= new Date((long) (ts2
.getValue() * Math
.pow(10, ts2
.getScale() + 3)));
202 Date d3
= new Date((long) (ts3
.getValue() * Math
.pow(10, ts3
.getScale() + 3)));
203 Date d4
= new Date((long) (ts4
.getValue() * Math
.pow(10, ts4
.getScale() + 3)));
204 Date d5
= new Date((long) (ts5
.getValue() * Math
.pow(10, ts5
.getScale() + 3)));
205 Date d6
= new Date((long) (ts6
.getValue() * Math
.pow(10, ts6
.getScale() + 3)));
206 Date d7
= new Date((long) (ts7
.getValue() * Math
.pow(10, ts7
.getScale() + 3)));
207 Date d8
= new Date((long) (ts8
.getValue() * Math
.pow(10, ts8
.getScale() + 3)) - 1);
208 Date d9
= new Date((long) (ts9
.getValue() * Math
.pow(10, ts9
.getScale() + 3)) - 1);
209 assertEquals("toString", df
.format(d0
) + " 000 000", ts0
.toString());
210 assertEquals("toString", df
.format(d1
) + " 000 000", ts1
.toString());
211 assertEquals("toString", df
.format(d2
) + " 000 000", ts2
.toString());
212 assertEquals("toString", df
.format(d3
) + " 000 000", ts3
.toString());
213 assertEquals("toString", df
.format(d4
) + " 000 000", ts4
.toString());
214 assertEquals("toString", df
.format(d5
) + " 345 000", ts5
.toString());
215 assertEquals("toString", df
.format(d6
) + " 012 345", ts6
.toString());
216 assertEquals("toString", df
.format(d7
) + " 000 000", ts7
.toString());
217 assertEquals("toString", df
.format(d8
) + " 655 000", ts8
.toString());
218 assertEquals("toString", df
.format(d9
) + " 987 655", ts9
.toString());
222 public void testToStringInterval() {
223 assertEquals("toString", "000.000 000 000", ts0
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
224 assertEquals("toString", "12345.000 000 000", ts1
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
225 assertEquals("toString", "1234.500 000 000", ts2
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
226 assertEquals("toString", "1234500.000 000 000", ts3
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
227 assertEquals("toString", "012.345 000 000", ts4
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
228 assertEquals("toString", "000.012 345 000", ts5
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
229 assertEquals("toString", "000.000 012 345", ts6
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
230 assertEquals("toString", "-012.345 000 000", ts7
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
231 assertEquals("toString", "-000.012 345 000", ts8
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
232 assertEquals("toString", "-000.000 012 345", ts9
.toString(TmfTimestampFormat
.getDefaulIntervalFormat()));
235 // ------------------------------------------------------------------------
237 // ------------------------------------------------------------------------
240 public void testNormalizeOffset() {
241 ITmfTimestamp ts
= ts0
.normalize(0, 0);
242 assertEquals("getValue", 0, ts
.getValue());
243 assertEquals("getscale", 0, ts
.getScale());
245 ts
= ts0
.normalize(12345, 0);
246 assertEquals("getValue", 12345, ts
.getValue());
247 assertEquals("getscale", 0, ts
.getScale());
249 ts
= ts0
.normalize(10, 0);
250 assertEquals("getValue", 10, ts
.getValue());
251 assertEquals("getscale", 0, ts
.getScale());
253 ts
= ts0
.normalize(-10, 0);
254 assertEquals("getValue", -10, ts
.getValue());
255 assertEquals("getscale", 0, ts
.getScale());
259 public void testNormalizeOffsetLowerLimits() {
260 final ITmfTimestamp ref
= TmfTimestamp
.create(Long
.MIN_VALUE
+ 5, 0);
262 ITmfTimestamp ts
= ref
.normalize(-4, 0);
263 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
264 assertEquals("getscale", 0, ts
.getScale());
266 ts
= ref
.normalize(-5, 0);
267 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
268 assertEquals("getscale", 0, ts
.getScale());
270 ts
= ref
.normalize(-6, 0);
271 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
272 assertEquals("getscale", 0, ts
.getScale());
276 public void testNormalizeOffsetUpperLimits() {
277 final ITmfTimestamp ref
= TmfTimestamp
.create(Long
.MAX_VALUE
- 5, 0);
279 ITmfTimestamp ts
= ref
.normalize(4, 0);
280 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
281 assertEquals("getscale", 0, ts
.getScale());
283 ts
= ref
.normalize(5, 0);
284 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
285 assertEquals("getscale", 0, ts
.getScale());
287 ts
= ref
.normalize(6, 0);
288 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
289 assertEquals("getscale", 0, ts
.getScale());
293 public void testNormalizeScale() {
294 ITmfTimestamp ts
= ts0
.normalize(0, 10);
295 assertEquals("getValue", 0, ts
.getValue());
296 assertEquals("getscale", 10, ts
.getScale());
298 ts
= ts0
.normalize(0, -10);
299 assertEquals("getValue", 0, ts
.getValue());
300 assertEquals("getscale", -10, ts
.getScale());
304 public void testNormalizedScaleLimits() {
305 final int MAX_SCALE_DIFF
= 19;
308 assertEquals(Long
.MAX_VALUE
, ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1).getValue());
309 assertEquals(0, ts1
.normalize(0, +MAX_SCALE_DIFF
- 1).getValue());
312 assertEquals(Long
.MAX_VALUE
, ts1
.normalize(0, -MAX_SCALE_DIFF
).getValue());
313 assertEquals(0, ts1
.normalize(0, +MAX_SCALE_DIFF
).getValue());
316 assertEquals(Long
.MAX_VALUE
, ts1
.normalize(0, -MAX_SCALE_DIFF
- 1).getValue());
317 assertEquals(0, ts1
.normalize(0, +MAX_SCALE_DIFF
- 1).getValue());
321 public void testNormalizeOffsetAndScaleTrivial() {
322 final ITmfTimestamp ts
= ts0
.normalize(0, 0);
323 assertEquals("getValue", 0, ts
.getValue());
324 assertEquals("getscale", 0, ts
.getScale());
328 public void testNormalizeOffsetAndScale() {
329 final int SCALE
= 12;
331 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
332 assertEquals("getValue", 0, ts
.getValue());
333 assertEquals("getscale", SCALE
, ts
.getScale());
335 ts
= ts0
.normalize(12345, SCALE
);
336 assertEquals("getValue", 12345, ts
.getValue());
337 assertEquals("getscale", SCALE
, ts
.getScale());
339 ts
= ts0
.normalize(10, SCALE
);
340 assertEquals("getValue", 10, ts
.getValue());
341 assertEquals("getscale", SCALE
, ts
.getScale());
343 ts
= ts0
.normalize(-10, SCALE
);
344 assertEquals("getValue", -10, ts
.getValue());
345 assertEquals("getscale", SCALE
, ts
.getScale());
349 public void testNormalizeOffsetAndScale2() {
351 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
352 assertEquals("getValue", 123, ts
.getValue());
353 assertEquals("getscale", SCALE
, ts
.getScale());
355 ts
= ts1
.normalize(12345, SCALE
);
356 assertEquals("getValue", 12468, ts
.getValue());
357 assertEquals("getscale", SCALE
, ts
.getScale());
360 ts
= ts1
.normalize(0, SCALE
);
361 assertEquals("getValue", 1234500, ts
.getValue());
362 assertEquals("getscale", SCALE
, ts
.getScale());
364 ts
= ts1
.normalize(67, SCALE
);
365 assertEquals("getValue", 1234567, ts
.getValue());
366 assertEquals("getscale", SCALE
, ts
.getScale());
370 public void testToNanos() {
371 assertEquals(12345000000000L, ts1
.toNanos());
372 assertEquals(-12345, ts9
.toNanos());
373 assertEquals(Long
.MAX_VALUE
, ts10
.toNanos());
374 assertEquals(Long
.MIN_VALUE
, ts11
.toNanos());
377 // ------------------------------------------------------------------------
379 // ------------------------------------------------------------------------
382 public void testBasicCompareTo() {
383 final ITmfTimestamp t1
= TmfTimestamp
.create(900, 0);
384 final ITmfTimestamp t2
= TmfTimestamp
.create(1000, 0);
385 final ITmfTimestamp t3
= TmfTimestamp
.create(1100, 0);
386 final ITmfTimestamp t4
= TmfTimestamp
.create(1000, 0);
388 assertTrue(t1
.compareTo(t1
) == 0);
390 assertTrue("CompareTo", t1
.compareTo(t2
) < 0);
391 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
392 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
394 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
395 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
396 assertTrue("CompareTo", t2
.compareTo(t4
) == 0);
398 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
399 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
400 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
404 public void testCompareToCornerCases1() {
405 final ITmfTimestamp ts0a
= TmfTimestamp
.create(ts0
.getValue(), ts0
.getScale());
406 final ITmfTimestamp ts0b
= TmfTimestamp
.create(ts0
.getValue(), ts0
.getScale() + 1);
407 final ITmfTimestamp ts0c
= TmfTimestamp
.create(ts0
.getValue() + 1, ts0
.getScale());
408 final ITmfTimestamp ts0d
= TmfTimestamp
.create(ts0
.getValue() + 1, ts0
.getScale() + 1);
410 assertTrue("compareTo", ts0
.compareTo(ts0
) == 0);
411 assertTrue("compareTo", ts0
.compareTo(ts0a
) == 0);
412 assertTrue("compareTo", ts0
.compareTo(ts0b
) == 0);
413 assertTrue("compareTo", ts0
.compareTo(ts0c
) == -1);
414 assertTrue("compareTo", ts0
.compareTo(ts0d
) == -1);
418 public void testCompareToCornerCases2() {
419 final ITmfTimestamp ts0a
= TmfTimestamp
.create(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
420 final ITmfTimestamp ts0b
= TmfTimestamp
.create(0, Integer
.MAX_VALUE
);
421 final ITmfTimestamp ts0c
= TmfTimestamp
.create(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
423 assertEquals("compareTo", 1, ts0a
.compareTo(ts0b
));
424 assertEquals("compareTo", -1, ts0a
.compareTo(ts0c
));
426 assertEquals("compareTo", -1, ts0b
.compareTo(ts0a
));
427 assertEquals("compareTo", -1, ts0b
.compareTo(ts0c
));
429 assertEquals("compareTo", 1, ts0c
.compareTo(ts0a
));
430 assertEquals("compareTo", 1, ts0c
.compareTo(ts0b
));
434 public void testCompareToCornerCases3() {
435 final ITmfTimestamp ts0a
= TmfTimestamp
.create(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
436 final ITmfTimestamp ts0b
= TmfTimestamp
.create(0, Integer
.MAX_VALUE
);
437 final ITmfTimestamp ts0c
= TmfTimestamp
.create(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
439 assertEquals("compareTo", -1, ts0a
.compareTo(ts0b
));
440 assertEquals("compareTo", 1, ts0a
.compareTo(ts0c
));
442 assertEquals("compareTo", 1, ts0b
.compareTo(ts0a
));
443 assertEquals("compareTo", 1, ts0b
.compareTo(ts0c
));
445 assertEquals("compareTo", -1, ts0c
.compareTo(ts0a
));
446 assertEquals("compareTo", -1, ts0c
.compareTo(ts0b
));
450 public void testCompareToCornerCases4() {
451 assertEquals("compareTo", 1, ts0
.compareTo(null));
455 public void testCompareToSameScale() {
456 final ITmfTimestamp t1
= TmfTimestamp
.create(900, 0);
457 final ITmfTimestamp t2
= TmfTimestamp
.create(1000, 0);
458 final ITmfTimestamp t3
= TmfTimestamp
.create(1100, 0);
459 final ITmfTimestamp t4
= TmfTimestamp
.create(1000, 0);
461 assertEquals(0, t1
.compareTo(t1
));
463 assertTrue("CompareTo", t1
.compareTo(t2
) < 0);
464 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
465 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
467 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
468 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
469 assertTrue("CompareTo", t2
.compareTo(t4
) == 0);
471 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
472 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
473 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
477 public void testCompareToDifferentScale() {
478 final ITmfTimestamp t1
= TmfTimestamp
.create(9000, -1);
479 final ITmfTimestamp t2
= TmfTimestamp
.create(1000, 0);
480 final ITmfTimestamp t3
= TmfTimestamp
.create(110, 1);
481 final ITmfTimestamp t4
= TmfTimestamp
.create(1, 3);
483 assertTrue("CompareTo", t1
.compareTo(t1
) == 0);
485 assertTrue("CompareTo", t1
.compareTo(t2
) < 0);
486 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
487 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
489 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
490 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
491 assertTrue("CompareTo", t2
.compareTo(t4
) == 0);
493 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
494 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
495 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
499 public void testCompareToLargeScale1() {
500 final ITmfTimestamp t1
= TmfTimestamp
.create(-1, 100);
501 final ITmfTimestamp t2
= TmfTimestamp
.create(-1000, -100);
502 final ITmfTimestamp t3
= TmfTimestamp
.create(1, 100);
503 final ITmfTimestamp t4
= TmfTimestamp
.create(1000, -100);
505 assertEquals("CompareTo", -1, t1
.compareTo(t2
));
506 assertTrue("CompareTo", t1
.compareTo(t3
) < 0);
507 assertTrue("CompareTo", t1
.compareTo(t4
) < 0);
509 assertTrue("CompareTo", t2
.compareTo(t1
) > 0);
510 assertTrue("CompareTo", t2
.compareTo(t3
) < 0);
511 assertTrue("CompareTo", t2
.compareTo(t4
) < 0);
513 assertTrue("CompareTo", t3
.compareTo(t1
) > 0);
514 assertTrue("CompareTo", t3
.compareTo(t2
) > 0);
515 assertTrue("CompareTo", t3
.compareTo(t4
) > 0);
517 assertTrue("CompareTo", t4
.compareTo(t1
) > 0);
518 assertTrue("CompareTo", t4
.compareTo(t2
) > 0);
519 assertTrue("CompareTo", t4
.compareTo(t3
) < 0);
523 public void testCompareToLargeScale2() {
524 final ITmfTimestamp ts0a
= TmfTimestamp
.create(0, Integer
.MAX_VALUE
);
525 final ITmfTimestamp ts0b
= TmfTimestamp
.create(1, Integer
.MAX_VALUE
);
527 assertEquals("CompareTo", 0, ts0a
.compareTo(ts0
));
528 assertEquals("CompareTo", 0, ts0
.compareTo(ts0a
));
530 assertEquals("CompareTo", 1, ts0b
.compareTo(ts0
));
531 assertEquals("CompareTo", -1, ts0
.compareTo(ts0b
));
534 // ------------------------------------------------------------------------
536 // ------------------------------------------------------------------------
539 public void testDelta() {
540 // Delta for same scale and precision (delta > 0)
541 ITmfTimestamp t0
= TmfTimestamp
.create(10, 9);
542 ITmfTimestamp t1
= TmfTimestamp
.create(5, 9);
543 ITmfTimestamp exp
= TmfTimestamp
.create(5, 9);
545 ITmfTimestamp delta
= t0
.getDelta(t1
);
546 assertEquals("getDelta", 0, delta
.compareTo(exp
));
548 // Delta for same scale and precision (delta < 0)
549 t0
= TmfTimestamp
.create(5, 9);
550 t1
= TmfTimestamp
.create(10, 9);
551 exp
= TmfTimestamp
.create(-5, 9);
553 delta
= t0
.getDelta(t1
);
554 assertEquals("getDelta", 0, delta
.compareTo(exp
));
556 // Delta for different scale and same precision (delta > 0)
557 t0
= TmfTimestamp
.create(5, 9);
558 t1
= TmfTimestamp
.create(10, 8);
559 exp
= TmfTimestamp
.create(4, 9);
561 delta
= t0
.getDelta(t1
);
562 assertEquals("getDelta", 0, delta
.compareTo(exp
));
564 // Delta for different scale and same precision (delta > 0)
565 t0
= TmfTimestamp
.create(5, 9);
566 t1
= TmfTimestamp
.create(10, 7);
567 exp
= TmfTimestamp
.create(5, 9);
569 delta
= t0
.getDelta(t1
);
570 assertEquals("getDelta", 0, delta
.compareTo(exp
));
572 // Delta for different scale and same precision
573 t0
= TmfTimestamp
.create(10, 9);
574 t1
= TmfTimestamp
.create(5, 8);
575 exp
= TmfTimestamp
.create(10, 9);
577 delta
= t0
.getDelta(t1
);
578 assertEquals("getDelta", 0, delta
.compareTo(exp
));
580 // Delta for same scale
581 t0
= TmfTimestamp
.create(10, 9);
582 t1
= TmfTimestamp
.create(5, 9);
583 exp
= TmfTimestamp
.create(5, 9);
585 delta
= t0
.getDelta(t1
);
586 assertEquals("getDelta", 0, delta
.compareTo(exp
));
588 // Delta for different scale
589 t0
= TmfTimestamp
.create(5, 9);
590 t1
= TmfTimestamp
.create(10, 8);
591 exp
= TmfTimestamp
.create(4, 9);
592 delta
= t0
.getDelta(t1
);
593 assertEquals("getDelta", 0, delta
.compareTo(exp
));
This page took 0.043887 seconds and 5 git commands to generate.