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 * <b><u>TmfTimestampTest</u></b>
24 * Test suite for the TmfTimestamp class.
26 @SuppressWarnings("nls")
27 public class TmfTimestampTest
extends TestCase
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 private final ITmfTimestamp ts0
= new TmfTimestamp();
34 private final ITmfTimestamp ts1
= new TmfTimestamp(12345);
35 private final ITmfTimestamp ts2
= new TmfTimestamp(12345, -1);
36 private final ITmfTimestamp ts3
= new TmfTimestamp(12345, 2, 5);
38 // ------------------------------------------------------------------------
40 // ------------------------------------------------------------------------
43 * @param name the test name
45 public TmfTimestampTest(String name
) {
50 protected void setUp() throws Exception
{
55 protected void tearDown() throws Exception
{
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 public void testDefaultConstructor() throws Exception
{
64 assertEquals("getValue", 0, ts0
.getValue());
65 assertEquals("getscale", 0, ts0
.getScale());
66 assertEquals("getPrecision", 0, ts0
.getPrecision());
69 public void testValueConstructor() throws Exception
{
70 assertEquals("getValue", 12345, ts1
.getValue());
71 assertEquals("getscale", 0, ts1
.getScale());
72 assertEquals("getPrecision", 0, ts1
.getPrecision());
75 public void testValueScaleConstructor() throws Exception
{
76 assertEquals("getValue", 12345, ts2
.getValue());
77 assertEquals("getscale", -1, ts2
.getScale());
78 assertEquals("getPrecision", 0, ts2
.getPrecision());
81 public void testFullConstructor() throws Exception
{
82 assertEquals("getValue", 12345, ts3
.getValue());
83 assertEquals("getscale", 2, ts3
.getScale());
84 assertEquals("getPrecision", 5, ts3
.getPrecision());
87 public void testCopyConstructor() throws Exception
{
88 ITmfTimestamp ts
= new TmfTimestamp(12345, 2, 5);
89 ITmfTimestamp copy
= new TmfTimestamp(ts
);
91 assertEquals("getValue", ts
.getValue(), copy
.getValue());
92 assertEquals("getscale", ts
.getScale(), copy
.getScale());
93 assertEquals("getPrecision", ts
.getPrecision(), copy
.getPrecision());
95 assertEquals("getValue", 12345, copy
.getValue());
96 assertEquals("getscale", 2, copy
.getScale());
97 assertEquals("getPrecision", 5, copy
.getPrecision());
100 public void testCopyNullConstructor() throws Exception
{
102 new TmfTimestamp(null);
103 fail("TmfTimestamp: null argument");
104 } catch (IllegalArgumentException e
) {
108 public void testCopyConstructorBigBang() throws Exception
{
109 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigBang
);
110 assertEquals("getValue", TmfTimestamp
.BigBang
.getValue(), ts
.getValue());
111 assertEquals("getscale", TmfTimestamp
.BigBang
.getScale(), ts
.getScale());
112 assertEquals("getPrecision", TmfTimestamp
.BigBang
.getPrecision(), ts
.getPrecision());
115 public void testCopyConstructorBigCrunch() throws Exception
{
116 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigCrunch
);
117 assertEquals("getValue", TmfTimestamp
.BigCrunch
.getValue(), ts
.getValue());
118 assertEquals("getscale", TmfTimestamp
.BigCrunch
.getScale(), ts
.getScale());
119 assertEquals("getPrecision", TmfTimestamp
.BigCrunch
.getPrecision(), ts
.getPrecision());
122 public void testCopyConstructorZero() throws Exception
{
123 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.Zero
);
124 assertEquals("getValue", TmfTimestamp
.Zero
.getValue(), ts
.getValue());
125 assertEquals("getscale", TmfTimestamp
.Zero
.getScale(), ts
.getScale());
126 assertEquals("getPrecision", TmfTimestamp
.Zero
.getPrecision(), ts
.getPrecision());
129 // ------------------------------------------------------------------------
131 // ------------------------------------------------------------------------
133 public static class MyTimestamp
extends TmfTimestamp
{
136 public boolean equals(Object other
) {
137 return super.equals(other
);
141 public MyTimestamp
clone() {
142 return (MyTimestamp
) super.clone();
146 public void testClone() throws Exception
{
147 ITmfTimestamp clone
= ts0
.clone();
148 assertEquals("clone", clone
, ts0
);
151 public void testClone2() throws Exception
{
152 MyTimestamp timestamp
= new MyTimestamp();
153 MyTimestamp clone
= timestamp
.clone();
154 assertEquals("clone", clone
, timestamp
);
157 // ------------------------------------------------------------------------
159 // ------------------------------------------------------------------------
161 public void testHashCode() throws Exception
{
162 ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
163 ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
164 ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
166 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
167 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
168 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
170 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
173 // ------------------------------------------------------------------------
175 // ------------------------------------------------------------------------
177 public void testEqualsReflexivity() throws Exception
{
178 assertTrue("equals", ts0
.equals(ts0
));
179 assertTrue("equals", ts1
.equals(ts1
));
181 assertTrue("equals", !ts0
.equals(ts1
));
182 assertTrue("equals", !ts1
.equals(ts0
));
185 public void testEqualsSymmetry() throws Exception
{
186 ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
187 assertTrue("equals", ts0
.equals(ts0copy
));
188 assertTrue("equals", ts0copy
.equals(ts0
));
190 ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
191 assertTrue("equals", ts1
.equals(ts1copy
));
192 assertTrue("equals", ts1copy
.equals(ts1
));
194 ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
195 assertTrue("equals", ts2
.equals(ts2copy
));
196 assertTrue("equals", ts2copy
.equals(ts2
));
199 public void testEqualsTransivity() throws Exception
{
200 ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
201 ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
202 assertTrue("equals", ts0
.equals(ts0copy1
));
203 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
204 assertTrue("equals", ts0
.equals(ts0copy2
));
206 ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
207 ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
208 assertTrue("equals", ts1
.equals(ts1copy1
));
209 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
210 assertTrue("equals", ts1
.equals(ts1copy2
));
212 ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
213 ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
214 assertTrue("equals", ts2
.equals(ts2copy1
));
215 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
216 assertTrue("equals", ts2
.equals(ts2copy2
));
219 public void testEqualsNull() throws Exception
{
220 assertTrue("equals", !ts0
.equals(null));
221 assertTrue("equals", !ts1
.equals(null));
224 public void testEqualsNonTimestamp() throws Exception
{
225 assertFalse("equals", ts0
.equals(ts0
.toString()));
228 // ------------------------------------------------------------------------
230 // ------------------------------------------------------------------------
232 public void testToString() throws Exception
{
233 assertEquals("toString", "TmfTimestamp [fValue=0, fScale=0, fPrecision=0]", ts0
.toString());
234 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=0, fPrecision=0]", ts1
.toString());
235 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=-1, fPrecision=0]", ts2
.toString());
236 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=2, fPrecision=5]", ts3
.toString());
239 // ------------------------------------------------------------------------
241 // ------------------------------------------------------------------------
243 public void testNormalizeOffset() throws Exception
{
244 ITmfTimestamp ts
= ts0
.normalize(0, 0);
245 assertEquals("getValue", 0, ts
.getValue());
246 assertEquals("getscale", 0, ts
.getScale());
247 assertEquals("getPrecision", 0, ts
.getPrecision());
249 ts
= ts0
.normalize(12345, 0);
250 assertEquals("getValue", 12345, ts
.getValue());
251 assertEquals("getscale", 0, ts
.getScale());
252 assertEquals("getPrecision", 0, ts
.getPrecision());
254 ts
= ts0
.normalize(10, 0);
255 assertEquals("getValue", 10, ts
.getValue());
256 assertEquals("getscale", 0, ts
.getScale());
257 assertEquals("getPrecision", 0, ts
.getPrecision());
259 ts
= ts0
.normalize(-10, 0);
260 assertEquals("getValue", -10, ts
.getValue());
261 assertEquals("getscale", 0, ts
.getScale());
262 assertEquals("getPrecision", 0, ts
.getPrecision());
265 public void testNormalizeOffsetLowerLimits() throws Exception
{
266 ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5);
268 ITmfTimestamp ts
= ref
.normalize(-4, 0);
269 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
270 assertEquals("getscale", 0, ts
.getScale());
271 assertEquals("getPrecision", 0, ts
.getPrecision());
273 ts
= ref
.normalize(-5, 0);
274 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
275 assertEquals("getscale", 0, ts
.getScale());
276 assertEquals("getPrecision", 0, ts
.getPrecision());
278 ts
= ref
.normalize(-6, 0);
279 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
280 assertEquals("getscale", 0, ts
.getScale());
281 assertEquals("getPrecision", 0, ts
.getPrecision());
284 public void testNormalizeOffsetUpperLimits() throws Exception
{
285 ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5);
287 ITmfTimestamp ts
= ref
.normalize(4, 0);
288 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
289 assertEquals("getscale", 0, ts
.getScale());
290 assertEquals("getPrecision", 0, ts
.getPrecision());
292 ts
= ref
.normalize(5, 0);
293 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
294 assertEquals("getscale", 0, ts
.getScale());
295 assertEquals("getPrecision", 0, ts
.getPrecision());
297 ts
= ref
.normalize(6, 0);
298 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
299 assertEquals("getscale", 0, ts
.getScale());
300 assertEquals("getPrecision", 0, ts
.getPrecision());
303 public void testNormalizeScale() throws Exception
{
304 ITmfTimestamp ts
= ts0
.normalize(0, 10);
305 assertEquals("getValue", 0, ts
.getValue());
306 assertEquals("getscale", 10, ts
.getScale());
307 assertEquals("getPrecision", 0, ts
.getPrecision());
309 ts
= ts0
.normalize(0, -10);
310 assertEquals("getValue", 0, ts
.getValue());
311 assertEquals("getscale", -10, ts
.getScale());
312 assertEquals("getPrecision", 0, ts
.getPrecision());
315 public void testNormalizedScaleLimits() throws Exception
{
316 int MAX_SCALE_DIFF
= 19;
320 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
321 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
322 } catch (ArithmeticException e
) {
323 fail("normalize: scale error");
328 ts1
.normalize(0, +MAX_SCALE_DIFF
);
329 fail("normalize: scale error");
330 ts1
.normalize(0, -MAX_SCALE_DIFF
);
331 fail("normalize: scale error");
332 } catch (ArithmeticException e
) {
337 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
338 fail("normalize: scale error");
339 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
340 fail("normalize: scale error");
341 } catch (ArithmeticException e
) {
345 public void testNormalizeOffsetAndScaleTrivial() throws Exception
{
346 ITmfTimestamp ts
= ts0
.normalize(0, 0);
347 assertEquals("getValue", 0, ts
.getValue());
348 assertEquals("getscale", 0, ts
.getScale());
349 assertEquals("getPrecision", 0, ts
.getPrecision());
352 public void testNormalizeOffsetAndScale() throws Exception
{
355 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
356 assertEquals("getValue", 0, ts
.getValue());
357 assertEquals("getscale", SCALE
, ts
.getScale());
358 assertEquals("getPrecision", 0, ts
.getPrecision());
360 ts
= ts0
.normalize(12345, SCALE
);
361 assertEquals("getValue", 12345, 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());
370 ts
= ts0
.normalize(-10, SCALE
);
371 assertEquals("getValue", -10, ts
.getValue());
372 assertEquals("getscale", SCALE
, ts
.getScale());
373 assertEquals("getPrecision", 0, ts
.getPrecision());
376 public void testNormalizeOffsetAndScale2() throws Exception
{
378 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
379 assertEquals("getValue", 123, ts
.getValue());
380 assertEquals("getscale", SCALE
, ts
.getScale());
381 assertEquals("getPrecision", 0, ts
.getPrecision());
383 ts
= ts1
.normalize(12345, SCALE
);
384 assertEquals("getValue", 12468, ts
.getValue());
385 assertEquals("getscale", SCALE
, ts
.getScale());
386 assertEquals("getPrecision", 0, ts
.getPrecision());
389 ts
= ts1
.normalize(0, SCALE
);
390 assertEquals("getValue", 1234500, ts
.getValue());
391 assertEquals("getscale", SCALE
, ts
.getScale());
392 assertEquals("getPrecision", 0, ts
.getPrecision());
394 ts
= ts1
.normalize(67, SCALE
);
395 assertEquals("getValue", 1234567, ts
.getValue());
396 assertEquals("getscale", SCALE
, ts
.getScale());
397 assertEquals("getPrecision", 0, ts
.getPrecision());
400 // ------------------------------------------------------------------------
402 // ------------------------------------------------------------------------
404 public void testBasicCompareTo() throws Exception
{
405 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
406 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
407 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
408 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
410 assertTrue(ts1
.compareTo(ts1
) == 0);
412 assertTrue("CompareTo", ts1
.compareTo(ts2
) < 0);
413 assertTrue("CompareTo", ts1
.compareTo(ts3
) < 0);
414 assertTrue("CompareTo", ts1
.compareTo(ts4
) < 0);
416 assertTrue("CompareTo", ts2
.compareTo(ts1
) > 0);
417 assertTrue("CompareTo", ts2
.compareTo(ts3
) < 0);
418 assertTrue("CompareTo", ts2
.compareTo(ts4
) == 0);
420 assertTrue("CompareTo", ts3
.compareTo(ts1
) > 0);
421 assertTrue("CompareTo", ts3
.compareTo(ts2
) > 0);
422 assertTrue("CompareTo", ts3
.compareTo(ts4
) > 0);
425 public void testCompareToCornerCases1() throws Exception
{
426 ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
427 ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
428 ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
429 ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
431 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
432 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
433 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
434 assertTrue("compareTo", ts0
.compareTo(ts0c
, false)== -1);
435 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
438 public void testCompareToCornerCases2() throws Exception
{
439 ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
440 ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
441 ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
443 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false)== 1);
444 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false)== -1);
446 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false)== -1);
447 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false)== -1);
449 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false)== 1);
450 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false)== 1);
453 public void testCompareToCornerCases3() throws Exception
{
454 ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
455 ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
456 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);
468 public void testCompareToSameScale() throws Exception
{
469 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
470 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
471 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
472 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
474 assertTrue(ts1
.compareTo(ts1
, false) == 0);
476 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
477 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
478 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
480 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
481 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
482 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
484 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
485 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
486 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
489 public void testCompareToDifferentScale() throws Exception
{
490 ITmfTimestamp ts1
= new TmfTimestamp(9000, -1, 50);
491 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
492 ITmfTimestamp ts3
= new TmfTimestamp(110, 1, 50);
493 ITmfTimestamp ts4
= new TmfTimestamp(1, 3, 75);
495 assertTrue("CompareTo", ts1
.compareTo(ts1
, false) == 0);
497 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
498 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
499 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
501 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
502 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
503 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
505 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
506 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
507 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
510 public void testCompareToWithinPrecision() throws Exception
{
511 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
512 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
513 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
514 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
516 assertTrue("CompareTo", ts1
.compareTo(ts1
, true) == 0);
518 assertTrue("CompareTo", ts1
.compareTo(ts2
, true) == 0);
519 assertTrue("CompareTo", ts1
.compareTo(ts3
, true) < 0);
520 assertTrue("CompareTo", ts1
.compareTo(ts4
, true) == 0);
522 assertTrue("CompareTo", ts2
.compareTo(ts1
, true) == 0);
523 assertTrue("CompareTo", ts2
.compareTo(ts3
, true) == 0);
524 assertTrue("CompareTo", ts2
.compareTo(ts4
, true) == 0);
526 assertTrue("CompareTo", ts3
.compareTo(ts1
, true) > 0);
527 assertTrue("CompareTo", ts3
.compareTo(ts2
, true) == 0);
528 assertTrue("CompareTo", ts3
.compareTo(ts4
, true) == 0);
531 public void testCompareToLargeScale1() throws Exception
{
532 ITmfTimestamp ts1
= new TmfTimestamp(-1, 100);
533 ITmfTimestamp ts2
= new TmfTimestamp(-1000, -100);
534 ITmfTimestamp ts3
= new TmfTimestamp(1, 100);
535 ITmfTimestamp ts4
= new TmfTimestamp(1000, -100);
537 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
538 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
539 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
541 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
542 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
543 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) < 0);
545 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
546 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
547 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
549 assertTrue("CompareTo", ts4
.compareTo(ts1
, false) > 0);
550 assertTrue("CompareTo", ts4
.compareTo(ts2
, false) > 0);
551 assertTrue("CompareTo", ts4
.compareTo(ts3
, false) < 0);
554 public void testCompareToLargeScale2() throws Exception
{
555 ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
556 ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
558 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
559 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
561 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
562 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
565 // ------------------------------------------------------------------------
567 // ------------------------------------------------------------------------
569 public void testDelta() throws Exception
{
570 // Delta for same scale and precision (delta > 0)
571 ITmfTimestamp ts0
= new TmfTimestamp(10, 9);
572 ITmfTimestamp ts1
= new TmfTimestamp(5, 9);
573 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
575 ITmfTimestamp delta
= ts0
.getDelta(ts1
);
576 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
578 // Delta for same scale and precision (delta < 0)
579 ts0
= new TmfTimestamp(5, 9);
580 ts1
= new TmfTimestamp(10, 9);
581 exp
= new TmfTimestamp(-5, 9);
583 delta
= ts0
.getDelta(ts1
);
584 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
586 // Delta for different scale and same precision (delta > 0)
587 ts0
= new TmfTimestamp(5, 9);
588 ts1
= new TmfTimestamp(10, 8);
589 exp
= new TmfTimestamp(4, 9);
591 delta
= ts0
.getDelta(ts1
);
592 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
594 // Delta for different scale and same precision (delta > 0)
595 ts0
= new TmfTimestamp(5, 9);
596 ts1
= new TmfTimestamp(10, 7);
597 exp
= new TmfTimestamp(5, 9);
599 delta
= ts0
.getDelta(ts1
);
600 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
602 // Delta for different scale and same precision
603 ts0
= new TmfTimestamp(10, 9);
604 ts1
= new TmfTimestamp(5, 8);
605 exp
= new TmfTimestamp(10, 9);
607 delta
= ts0
.getDelta(ts1
);
608 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
610 // Delta for same scale and different precision
611 ts0
= new TmfTimestamp(10, 9, 1);
612 ts1
= new TmfTimestamp(5, 9, 2);
613 exp
= new TmfTimestamp(5, 9, 3);
615 delta
= ts0
.getDelta(ts1
);
616 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
617 assertEquals("precision", 3, delta
.getPrecision());
619 // Delta for same scale and different precision
620 ts0
= new TmfTimestamp(5, 9, 2);
621 ts1
= new TmfTimestamp(10, 9, 1);
622 exp
= new TmfTimestamp(-5, 9, 3);
624 delta
= ts0
.getDelta(ts1
);
625 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
626 assertEquals("precision", 3, delta
.getPrecision());
628 // Delta for different scale and different precision
629 ts0
= new TmfTimestamp(5, 9, 2);
630 ts1
= new TmfTimestamp(10, 8, 1);
631 exp
= new TmfTimestamp(4, 9, 3);
632 delta
= ts0
.getDelta(ts1
);
633 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
634 assertEquals("precision", 2, delta
.getPrecision());