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 @SuppressWarnings("unused")
103 ITmfTimestamp timestamp
= new TmfTimestamp(null);
104 fail("TmfTimestamp: null argument");
105 } catch (IllegalArgumentException e
) {
109 public void testCopyConstructorBigBang() throws Exception
{
110 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigBang
);
111 assertEquals("getValue", TmfTimestamp
.BigBang
.getValue(), ts
.getValue());
112 assertEquals("getscale", TmfTimestamp
.BigBang
.getScale(), ts
.getScale());
113 assertEquals("getPrecision", TmfTimestamp
.BigBang
.getPrecision(), ts
.getPrecision());
116 public void testCopyConstructorBigCrunch() throws Exception
{
117 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigCrunch
);
118 assertEquals("getValue", TmfTimestamp
.BigCrunch
.getValue(), ts
.getValue());
119 assertEquals("getscale", TmfTimestamp
.BigCrunch
.getScale(), ts
.getScale());
120 assertEquals("getPrecision", TmfTimestamp
.BigCrunch
.getPrecision(), ts
.getPrecision());
123 public void testCopyConstructorZero() throws Exception
{
124 ITmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.Zero
);
125 assertEquals("getValue", TmfTimestamp
.Zero
.getValue(), ts
.getValue());
126 assertEquals("getscale", TmfTimestamp
.Zero
.getScale(), ts
.getScale());
127 assertEquals("getPrecision", TmfTimestamp
.Zero
.getPrecision(), ts
.getPrecision());
130 // ------------------------------------------------------------------------
132 // ------------------------------------------------------------------------
134 public class MyTimestamp
extends TmfTimestamp
{
137 public boolean equals(Object other
) {
138 return super.equals(other
);
142 public MyTimestamp
clone() {
143 return (MyTimestamp
) super.clone();
147 public void testClone() throws Exception
{
148 ITmfTimestamp clone
= ts0
.clone();
149 assertEquals("clone", clone
, ts0
);
152 public void testClone2() throws Exception
{
153 MyTimestamp timestamp
= new MyTimestamp();
154 MyTimestamp clone
= timestamp
.clone();
155 assertEquals("clone", clone
, timestamp
);
158 // ------------------------------------------------------------------------
160 // ------------------------------------------------------------------------
162 public void testHashCode() throws Exception
{
163 ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
164 ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
165 ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
167 assertTrue("hashCode", ts0
.hashCode() == ts0copy
.hashCode());
168 assertTrue("hashCode", ts1
.hashCode() == ts1copy
.hashCode());
169 assertTrue("hashCode", ts2
.hashCode() == ts2copy
.hashCode());
171 assertTrue("hashCode", ts0
.hashCode() != ts1
.hashCode());
174 // ------------------------------------------------------------------------
176 // ------------------------------------------------------------------------
178 public void testEqualsReflexivity() throws Exception
{
179 assertTrue("equals", ts0
.equals(ts0
));
180 assertTrue("equals", ts1
.equals(ts1
));
182 assertTrue("equals", !ts0
.equals(ts1
));
183 assertTrue("equals", !ts1
.equals(ts0
));
186 public void testEqualsSymmetry() throws Exception
{
187 ITmfTimestamp ts0copy
= new TmfTimestamp(ts0
);
188 assertTrue("equals", ts0
.equals(ts0copy
));
189 assertTrue("equals", ts0copy
.equals(ts0
));
191 ITmfTimestamp ts1copy
= new TmfTimestamp(ts1
);
192 assertTrue("equals", ts1
.equals(ts1copy
));
193 assertTrue("equals", ts1copy
.equals(ts1
));
195 ITmfTimestamp ts2copy
= new TmfTimestamp(ts2
);
196 assertTrue("equals", ts2
.equals(ts2copy
));
197 assertTrue("equals", ts2copy
.equals(ts2
));
200 public void testEqualsTransivity() throws Exception
{
201 ITmfTimestamp ts0copy1
= new TmfTimestamp(ts0
);
202 ITmfTimestamp ts0copy2
= new TmfTimestamp(ts0copy1
);
203 assertTrue("equals", ts0
.equals(ts0copy1
));
204 assertTrue("equals", ts0copy1
.equals(ts0copy2
));
205 assertTrue("equals", ts0
.equals(ts0copy2
));
207 ITmfTimestamp ts1copy1
= new TmfTimestamp(ts1
);
208 ITmfTimestamp ts1copy2
= new TmfTimestamp(ts1copy1
);
209 assertTrue("equals", ts1
.equals(ts1copy1
));
210 assertTrue("equals", ts1copy1
.equals(ts1copy2
));
211 assertTrue("equals", ts1
.equals(ts1copy2
));
213 ITmfTimestamp ts2copy1
= new TmfTimestamp(ts2
);
214 ITmfTimestamp ts2copy2
= new TmfTimestamp(ts2copy1
);
215 assertTrue("equals", ts2
.equals(ts2copy1
));
216 assertTrue("equals", ts2copy1
.equals(ts2copy2
));
217 assertTrue("equals", ts2
.equals(ts2copy2
));
220 public void testEqualsNull() throws Exception
{
221 assertTrue("equals", !ts0
.equals(null));
222 assertTrue("equals", !ts1
.equals(null));
225 public void testEqualsNonTimestamp() throws Exception
{
226 assertFalse("equals", ts0
.equals(ts0
.toString()));
229 // ------------------------------------------------------------------------
231 // ------------------------------------------------------------------------
233 public void testToString() throws Exception
{
234 assertEquals("toString", "TmfTimestamp [fValue=0, fScale=0, fPrecision=0]", ts0
.toString());
235 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=0, fPrecision=0]", ts1
.toString());
236 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=-1, fPrecision=0]", ts2
.toString());
237 assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=2, fPrecision=5]", ts3
.toString());
240 // ------------------------------------------------------------------------
242 // ------------------------------------------------------------------------
244 public void testNormalizeOffset() throws Exception
{
245 ITmfTimestamp ts
= ts0
.normalize(0, 0);
246 assertEquals("getValue", 0, ts
.getValue());
247 assertEquals("getscale", 0, ts
.getScale());
248 assertEquals("getPrecision", 0, ts
.getPrecision());
250 ts
= ts0
.normalize(12345, 0);
251 assertEquals("getValue", 12345, ts
.getValue());
252 assertEquals("getscale", 0, ts
.getScale());
253 assertEquals("getPrecision", 0, ts
.getPrecision());
255 ts
= ts0
.normalize(10, 0);
256 assertEquals("getValue", 10, ts
.getValue());
257 assertEquals("getscale", 0, ts
.getScale());
258 assertEquals("getPrecision", 0, ts
.getPrecision());
260 ts
= ts0
.normalize(-10, 0);
261 assertEquals("getValue", -10, ts
.getValue());
262 assertEquals("getscale", 0, ts
.getScale());
263 assertEquals("getPrecision", 0, ts
.getPrecision());
266 public void testNormalizeOffsetLowerLimits() throws Exception
{
267 ITmfTimestamp ref
= new TmfTimestamp(Long
.MIN_VALUE
+ 5);
269 ITmfTimestamp ts
= ref
.normalize(-4, 0);
270 assertEquals("getValue", Long
.MIN_VALUE
+ 1, ts
.getValue());
271 assertEquals("getscale", 0, ts
.getScale());
272 assertEquals("getPrecision", 0, ts
.getPrecision());
274 ts
= ref
.normalize(-5, 0);
275 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
276 assertEquals("getscale", 0, ts
.getScale());
277 assertEquals("getPrecision", 0, ts
.getPrecision());
279 ts
= ref
.normalize(-6, 0);
280 assertEquals("getValue", Long
.MIN_VALUE
, ts
.getValue());
281 assertEquals("getscale", 0, ts
.getScale());
282 assertEquals("getPrecision", 0, ts
.getPrecision());
285 public void testNormalizeOffsetUpperLimits() throws Exception
{
286 ITmfTimestamp ref
= new TmfTimestamp(Long
.MAX_VALUE
- 5);
288 ITmfTimestamp ts
= ref
.normalize(4, 0);
289 assertEquals("getValue", Long
.MAX_VALUE
- 1, ts
.getValue());
290 assertEquals("getscale", 0, ts
.getScale());
291 assertEquals("getPrecision", 0, ts
.getPrecision());
293 ts
= ref
.normalize(5, 0);
294 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
295 assertEquals("getscale", 0, ts
.getScale());
296 assertEquals("getPrecision", 0, ts
.getPrecision());
298 ts
= ref
.normalize(6, 0);
299 assertEquals("getValue", Long
.MAX_VALUE
, ts
.getValue());
300 assertEquals("getscale", 0, ts
.getScale());
301 assertEquals("getPrecision", 0, ts
.getPrecision());
304 public void testNormalizeScale() throws Exception
{
305 ITmfTimestamp ts
= ts0
.normalize(0, 10);
306 assertEquals("getValue", 0, ts
.getValue());
307 assertEquals("getscale", 10, ts
.getScale());
308 assertEquals("getPrecision", 0, ts
.getPrecision());
310 ts
= ts0
.normalize(0, -10);
311 assertEquals("getValue", 0, ts
.getValue());
312 assertEquals("getscale", -10, ts
.getScale());
313 assertEquals("getPrecision", 0, ts
.getPrecision());
316 public void testNormalizedScaleLimits() throws Exception
{
317 int MAX_SCALE_DIFF
= 19;
321 ts1
.normalize(0, +MAX_SCALE_DIFF
- 1);
322 ts1
.normalize(0, -MAX_SCALE_DIFF
+ 1);
323 } catch (ArithmeticException e
) {
324 fail("normalize: scale error");
329 ts1
.normalize(0, +MAX_SCALE_DIFF
);
330 fail("normalize: scale error");
331 ts1
.normalize(0, -MAX_SCALE_DIFF
);
332 fail("normalize: scale error");
333 } catch (ArithmeticException e
) {
338 ts1
.normalize(0, +MAX_SCALE_DIFF
+ 1);
339 fail("normalize: scale error");
340 ts1
.normalize(0, -MAX_SCALE_DIFF
- 1);
341 fail("normalize: scale error");
342 } catch (ArithmeticException e
) {
346 public void testNormalizeOffsetAndScaleTrivial() throws Exception
{
347 ITmfTimestamp ts
= ts0
.normalize(0, 0);
348 assertEquals("getValue", 0, ts
.getValue());
349 assertEquals("getscale", 0, ts
.getScale());
350 assertEquals("getPrecision", 0, ts
.getPrecision());
353 public void testNormalizeOffsetAndScale() throws Exception
{
356 ITmfTimestamp ts
= ts0
.normalize(0, SCALE
);
357 assertEquals("getValue", 0, ts
.getValue());
358 assertEquals("getscale", SCALE
, ts
.getScale());
359 assertEquals("getPrecision", 0, ts
.getPrecision());
361 ts
= ts0
.normalize(12345, SCALE
);
362 assertEquals("getValue", 12345, ts
.getValue());
363 assertEquals("getscale", SCALE
, ts
.getScale());
364 assertEquals("getPrecision", 0, ts
.getPrecision());
366 ts
= ts0
.normalize(10, SCALE
);
367 assertEquals("getValue", 10, ts
.getValue());
368 assertEquals("getscale", SCALE
, ts
.getScale());
369 assertEquals("getPrecision", 0, ts
.getPrecision());
371 ts
= ts0
.normalize(-10, SCALE
);
372 assertEquals("getValue", -10, ts
.getValue());
373 assertEquals("getscale", SCALE
, ts
.getScale());
374 assertEquals("getPrecision", 0, ts
.getPrecision());
377 public void testNormalizeOffsetAndScale2() throws Exception
{
379 ITmfTimestamp ts
= ts1
.normalize(0, SCALE
);
380 assertEquals("getValue", 123, ts
.getValue());
381 assertEquals("getscale", SCALE
, ts
.getScale());
382 assertEquals("getPrecision", 0, ts
.getPrecision());
384 ts
= ts1
.normalize(12345, SCALE
);
385 assertEquals("getValue", 12468, ts
.getValue());
386 assertEquals("getscale", SCALE
, ts
.getScale());
387 assertEquals("getPrecision", 0, ts
.getPrecision());
390 ts
= ts1
.normalize(0, SCALE
);
391 assertEquals("getValue", 1234500, ts
.getValue());
392 assertEquals("getscale", SCALE
, ts
.getScale());
393 assertEquals("getPrecision", 0, ts
.getPrecision());
395 ts
= ts1
.normalize(67, SCALE
);
396 assertEquals("getValue", 1234567, ts
.getValue());
397 assertEquals("getscale", SCALE
, ts
.getScale());
398 assertEquals("getPrecision", 0, ts
.getPrecision());
401 // ------------------------------------------------------------------------
403 // ------------------------------------------------------------------------
405 public void testBasicCompareTo() throws Exception
{
406 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
407 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
408 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
409 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
411 assertTrue(ts1
.compareTo(ts1
) == 0);
413 assertTrue("CompareTo", ts1
.compareTo(ts2
) < 0);
414 assertTrue("CompareTo", ts1
.compareTo(ts3
) < 0);
415 assertTrue("CompareTo", ts1
.compareTo(ts4
) < 0);
417 assertTrue("CompareTo", ts2
.compareTo(ts1
) > 0);
418 assertTrue("CompareTo", ts2
.compareTo(ts3
) < 0);
419 assertTrue("CompareTo", ts2
.compareTo(ts4
) == 0);
421 assertTrue("CompareTo", ts3
.compareTo(ts1
) > 0);
422 assertTrue("CompareTo", ts3
.compareTo(ts2
) > 0);
423 assertTrue("CompareTo", ts3
.compareTo(ts4
) > 0);
426 public void testCompareToCornerCases1() throws Exception
{
427 ITmfTimestamp ts0a
= new TmfTimestamp(ts0
);
428 ITmfTimestamp ts0b
= new TmfTimestamp(ts0
.getValue(), ts0
.getScale() + 1);
429 ITmfTimestamp ts0c
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale());
430 ITmfTimestamp ts0d
= new TmfTimestamp(ts0
.getValue() + 1, ts0
.getScale() + 1);
432 assertTrue("compareTo", ts0
.compareTo(ts0
, false) == 0);
433 assertTrue("compareTo", ts0
.compareTo(ts0a
, false) == 0);
434 assertTrue("compareTo", ts0
.compareTo(ts0b
, false) == 0);
435 assertTrue("compareTo", ts0
.compareTo(ts0c
, false)== -1);
436 assertTrue("compareTo", ts0
.compareTo(ts0d
, false) == -1);
439 public void testCompareToCornerCases2() throws Exception
{
440 ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
- 1);
441 ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
442 ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MAX_VALUE
, Integer
.MAX_VALUE
);
444 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false)== 1);
445 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false)== -1);
447 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false)== -1);
448 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false)== -1);
450 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false)== 1);
451 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false)== 1);
454 public void testCompareToCornerCases3() throws Exception
{
455 ITmfTimestamp ts0a
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
- 1);
456 ITmfTimestamp ts0b
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
457 ITmfTimestamp ts0c
= new TmfTimestamp(Long
.MIN_VALUE
, Integer
.MAX_VALUE
);
459 assertTrue("compareTo", ts0a
.compareTo(ts0b
, false)== -1);
460 assertTrue("compareTo", ts0a
.compareTo(ts0c
, false)== 1);
462 assertTrue("compareTo", ts0b
.compareTo(ts0a
, false)== 1);
463 assertTrue("compareTo", ts0b
.compareTo(ts0c
, false)== 1);
465 assertTrue("compareTo", ts0c
.compareTo(ts0a
, false)== -1);
466 assertTrue("compareTo", ts0c
.compareTo(ts0b
, false)== -1);
469 public void testCompareToSameScale() throws Exception
{
470 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
471 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
472 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
473 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
475 assertTrue(ts1
.compareTo(ts1
, false) == 0);
477 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
478 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
479 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
481 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
482 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
483 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
485 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
486 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
487 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
490 public void testCompareToDifferentScale() throws Exception
{
491 ITmfTimestamp ts1
= new TmfTimestamp(9000, -1, 50);
492 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
493 ITmfTimestamp ts3
= new TmfTimestamp(110, 1, 50);
494 ITmfTimestamp ts4
= new TmfTimestamp(1, 3, 75);
496 assertTrue("CompareTo", ts1
.compareTo(ts1
, false) == 0);
498 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
499 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
500 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
502 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
503 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
504 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) == 0);
506 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
507 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
508 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
511 public void testCompareToWithinPrecision() throws Exception
{
512 ITmfTimestamp ts1
= new TmfTimestamp(900, 0, 50);
513 ITmfTimestamp ts2
= new TmfTimestamp(1000, 0, 50);
514 ITmfTimestamp ts3
= new TmfTimestamp(1100, 0, 50);
515 ITmfTimestamp ts4
= new TmfTimestamp(1000, 0, 75);
517 assertTrue("CompareTo", ts1
.compareTo(ts1
, true) == 0);
519 assertTrue("CompareTo", ts1
.compareTo(ts2
, true) == 0);
520 assertTrue("CompareTo", ts1
.compareTo(ts3
, true) < 0);
521 assertTrue("CompareTo", ts1
.compareTo(ts4
, true) == 0);
523 assertTrue("CompareTo", ts2
.compareTo(ts1
, true) == 0);
524 assertTrue("CompareTo", ts2
.compareTo(ts3
, true) == 0);
525 assertTrue("CompareTo", ts2
.compareTo(ts4
, true) == 0);
527 assertTrue("CompareTo", ts3
.compareTo(ts1
, true) > 0);
528 assertTrue("CompareTo", ts3
.compareTo(ts2
, true) == 0);
529 assertTrue("CompareTo", ts3
.compareTo(ts4
, true) == 0);
532 public void testCompareToLargeScale1() throws Exception
{
533 ITmfTimestamp ts1
= new TmfTimestamp(-1, 100);
534 ITmfTimestamp ts2
= new TmfTimestamp(-1000, -100);
535 ITmfTimestamp ts3
= new TmfTimestamp(1, 100);
536 ITmfTimestamp ts4
= new TmfTimestamp(1000, -100);
538 assertTrue("CompareTo", ts1
.compareTo(ts2
, false) < 0);
539 assertTrue("CompareTo", ts1
.compareTo(ts3
, false) < 0);
540 assertTrue("CompareTo", ts1
.compareTo(ts4
, false) < 0);
542 assertTrue("CompareTo", ts2
.compareTo(ts1
, false) > 0);
543 assertTrue("CompareTo", ts2
.compareTo(ts3
, false) < 0);
544 assertTrue("CompareTo", ts2
.compareTo(ts4
, false) < 0);
546 assertTrue("CompareTo", ts3
.compareTo(ts1
, false) > 0);
547 assertTrue("CompareTo", ts3
.compareTo(ts2
, false) > 0);
548 assertTrue("CompareTo", ts3
.compareTo(ts4
, false) > 0);
550 assertTrue("CompareTo", ts4
.compareTo(ts1
, false) > 0);
551 assertTrue("CompareTo", ts4
.compareTo(ts2
, false) > 0);
552 assertTrue("CompareTo", ts4
.compareTo(ts3
, false) < 0);
555 public void testCompareToLargeScale2() throws Exception
{
556 ITmfTimestamp ts0a
= new TmfTimestamp(0, Integer
.MAX_VALUE
);
557 ITmfTimestamp ts0b
= new TmfTimestamp(1, Integer
.MAX_VALUE
);
559 assertTrue("CompareTo", ts0a
.compareTo(ts0
, false) == 0);
560 assertTrue("CompareTo", ts0
.compareTo(ts0a
, false) == 0);
562 assertTrue("CompareTo", ts0b
.compareTo(ts0
, false) == 1);
563 assertTrue("CompareTo", ts0
.compareTo(ts0b
, false) == -1);
566 // ------------------------------------------------------------------------
568 // ------------------------------------------------------------------------
570 public void testDelta() throws Exception
{
571 // Delta for same scale and precision (delta > 0)
572 ITmfTimestamp ts0
= new TmfTimestamp(10, 9);
573 ITmfTimestamp ts1
= new TmfTimestamp(5, 9);
574 ITmfTimestamp exp
= new TmfTimestamp(5, 9);
576 ITmfTimestamp delta
= ts0
.getDelta(ts1
);
577 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
579 // Delta for same scale and precision (delta < 0)
580 ts0
= new TmfTimestamp(5, 9);
581 ts1
= new TmfTimestamp(10, 9);
582 exp
= new TmfTimestamp(-5, 9);
584 delta
= ts0
.getDelta(ts1
);
585 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
587 // Delta for different scale and same precision (delta > 0)
588 ts0
= new TmfTimestamp(5, 9);
589 ts1
= new TmfTimestamp(10, 8);
590 exp
= new TmfTimestamp(4, 9);
592 delta
= ts0
.getDelta(ts1
);
593 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
595 // Delta for different scale and same precision (delta > 0)
596 ts0
= new TmfTimestamp(5, 9);
597 ts1
= new TmfTimestamp(10, 7);
598 exp
= new TmfTimestamp(5, 9);
600 delta
= ts0
.getDelta(ts1
);
601 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
603 // Delta for different scale and same precision
604 ts0
= new TmfTimestamp(10, 9);
605 ts1
= new TmfTimestamp(5, 8);
606 exp
= new TmfTimestamp(10, 9);
608 delta
= ts0
.getDelta(ts1
);
609 assertEquals("getDelta", 0, delta
.compareTo(exp
, false));
611 // Delta for same scale and different precision
612 ts0
= new TmfTimestamp(10, 9, 1);
613 ts1
= new TmfTimestamp(5, 9, 2);
614 exp
= new TmfTimestamp(5, 9, 3);
616 delta
= ts0
.getDelta(ts1
);
617 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
618 assertEquals("precision", 3, delta
.getPrecision());
620 // Delta for same scale and different precision
621 ts0
= new TmfTimestamp(5, 9, 2);
622 ts1
= new TmfTimestamp(10, 9, 1);
623 exp
= new TmfTimestamp(-5, 9, 3);
625 delta
= ts0
.getDelta(ts1
);
626 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
627 assertEquals("precision", 3, delta
.getPrecision());
629 // Delta for different scale and different precision
630 ts0
= new TmfTimestamp(5, 9, 2);
631 ts1
= new TmfTimestamp(10, 8, 1);
632 exp
= new TmfTimestamp(4, 9, 3);
633 delta
= ts0
.getDelta(ts1
);
634 assertEquals("getDelta", 0, delta
.compareTo(exp
, true));
635 assertEquals("precision", 2, delta
.getPrecision());