Commit | Line | Data |
---|---|---|
d18dd09b | 1 | /******************************************************************************* |
d7dbf09a | 2 | * Copyright (c) 2009, 2012 Ericsson |
d18dd09b ASL |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Francois Chouinard - Initial API and implementation | |
d7dbf09a | 11 | * Francois Chouinard - Revisit for TMF Event Model 1.0 |
d18dd09b ASL |
12 | *******************************************************************************/ |
13 | ||
6c13869b | 14 | package org.eclipse.linuxtools.tmf.core.tests.event; |
d18dd09b | 15 | |
75828b1a FC |
16 | import junit.framework.TestCase; |
17 | ||
5179fc01 | 18 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
6c13869b | 19 | import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp; |
cbd4ad82 | 20 | |
d18dd09b ASL |
21 | /** |
22 | * <b><u>TmfTimestampTest</u></b> | |
23 | * <p> | |
cbd4ad82 | 24 | * Test suite for the TmfTimestamp class. |
d18dd09b | 25 | */ |
3b38ea61 | 26 | @SuppressWarnings("nls") |
d18dd09b ASL |
27 | public class TmfTimestampTest extends TestCase { |
28 | ||
cbd4ad82 FC |
29 | // ------------------------------------------------------------------------ |
30 | // Variables | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | private final TmfTimestamp ts0 = new TmfTimestamp(); | |
34 | private final TmfTimestamp ts1 = new TmfTimestamp(12345); | |
5179fc01 FC |
35 | private final TmfTimestamp ts2 = new TmfTimestamp(12345, -1); |
36 | private final TmfTimestamp ts3 = new TmfTimestamp(12345, 2, 5); | |
cbd4ad82 FC |
37 | |
38 | private final TmfTimestamp ts0copy = new TmfTimestamp(); | |
39 | private final TmfTimestamp ts1copy = new TmfTimestamp(12345); | |
40 | ||
41 | private final TmfTimestamp ts0copy2 = new TmfTimestamp(); | |
42 | private final TmfTimestamp ts1copy2 = new TmfTimestamp(12345); | |
43 | ||
4df4581d | 44 | private final ITmfTimestamp bigBang = TmfTimestamp.BigBang; |
45 | private final ITmfTimestamp bigCrunch = TmfTimestamp.BigCrunch; | |
d18dd09b | 46 | |
cbd4ad82 FC |
47 | // ------------------------------------------------------------------------ |
48 | // Housekeping | |
49 | // ------------------------------------------------------------------------ | |
50 | ||
51 | /** | |
52 | * @param name the test name | |
53 | */ | |
d18dd09b ASL |
54 | public TmfTimestampTest(String name) { |
55 | super(name); | |
56 | } | |
57 | ||
58 | @Override | |
59 | protected void setUp() throws Exception { | |
60 | super.setUp(); | |
61 | } | |
62 | ||
63 | @Override | |
64 | protected void tearDown() throws Exception { | |
65 | super.tearDown(); | |
66 | } | |
67 | ||
cbd4ad82 | 68 | // ------------------------------------------------------------------------ |
d18dd09b | 69 | // Constructors |
cbd4ad82 | 70 | // ------------------------------------------------------------------------ |
d18dd09b ASL |
71 | |
72 | public void testDefaultConstructor() throws Exception { | |
cbd4ad82 FC |
73 | assertEquals("getValue", 0, ts0.getValue()); |
74 | assertEquals("getscale", 0, ts0.getScale()); | |
75 | assertEquals("getPrecision", 0, ts0.getPrecision()); | |
d18dd09b ASL |
76 | } |
77 | ||
78 | public void testSimpleConstructor() throws Exception { | |
cbd4ad82 FC |
79 | assertEquals("getValue", 12345, ts1.getValue()); |
80 | assertEquals("getscale", 0, ts1.getScale()); | |
81 | assertEquals("getPrecision", 0, ts1.getPrecision()); | |
d18dd09b ASL |
82 | } |
83 | ||
84 | public void testSimpleConstructor2() throws Exception { | |
cbd4ad82 FC |
85 | assertEquals("getValue", 12345, ts2.getValue()); |
86 | assertEquals("getscale", -1, ts2.getScale()); | |
87 | assertEquals("getPrecision", 0, ts2.getPrecision()); | |
d18dd09b ASL |
88 | } |
89 | ||
90 | public void testFullConstructor() throws Exception { | |
cbd4ad82 FC |
91 | assertEquals("getValue", 12345, ts3.getValue()); |
92 | assertEquals("getscale", 2, ts3.getScale()); | |
93 | assertEquals("getPrecision", 5, ts3.getPrecision()); | |
d18dd09b ASL |
94 | } |
95 | ||
96 | public void testCopyConstructor() throws Exception { | |
5179fc01 | 97 | TmfTimestamp ts0 = new TmfTimestamp(12345, 2, 5); |
d18dd09b ASL |
98 | TmfTimestamp ts = new TmfTimestamp(ts0); |
99 | assertEquals("getValue", 12345, ts.getValue()); | |
100 | assertEquals("getscale", 2, ts.getScale()); | |
101 | assertEquals("getPrecision", 5, ts.getPrecision()); | |
102 | } | |
103 | ||
cbd4ad82 FC |
104 | public void testCopyConstructor2() throws Exception { |
105 | try { | |
106 | @SuppressWarnings("unused") | |
107 | TmfTimestamp timestamp = new TmfTimestamp(null); | |
108 | fail("null copy"); | |
109 | } | |
110 | catch (IllegalArgumentException e) { | |
111 | // Success | |
112 | } | |
113 | } | |
d18dd09b ASL |
114 | |
115 | public void testCopyConstructorBigBang() throws Exception { | |
cbd4ad82 FC |
116 | assertEquals("getValue", TmfTimestamp.BigBang.getValue(), bigBang.getValue()); |
117 | assertEquals("getscale", TmfTimestamp.BigBang.getScale(), bigBang.getScale()); | |
118 | assertEquals("getPrecision", TmfTimestamp.BigBang.getPrecision(), bigBang.getPrecision()); | |
d18dd09b ASL |
119 | } |
120 | ||
121 | public void testCopyConstructorBigCrunch() throws Exception { | |
cbd4ad82 FC |
122 | assertEquals("getValue", TmfTimestamp.BigCrunch.getValue(), bigCrunch.getValue()); |
123 | assertEquals("getscale", TmfTimestamp.BigCrunch.getScale(), bigCrunch.getScale()); | |
124 | assertEquals("getPrecision", TmfTimestamp.BigCrunch.getPrecision(), bigCrunch.getPrecision()); | |
125 | } | |
126 | ||
127 | // ------------------------------------------------------------------------ | |
128 | // equals | |
129 | // ------------------------------------------------------------------------ | |
130 | ||
131 | public void testEqualsReflexivity() throws Exception { | |
132 | assertTrue("equals", ts0.equals(ts0)); | |
133 | assertTrue("equals", ts1.equals(ts1)); | |
134 | ||
135 | assertTrue("equals", !ts0.equals(ts1)); | |
136 | assertTrue("equals", !ts1.equals(ts0)); | |
d18dd09b | 137 | } |
cbd4ad82 FC |
138 | |
139 | public void testEqualsSymmetry() throws Exception { | |
140 | assertTrue("equals", ts0.equals(ts0copy)); | |
141 | assertTrue("equals", ts0copy.equals(ts0)); | |
d18dd09b | 142 | |
cbd4ad82 FC |
143 | assertTrue("equals", ts1.equals(ts1copy)); |
144 | assertTrue("equals", ts1copy.equals(ts1)); | |
145 | } | |
146 | ||
147 | public void testEqualsTransivity() throws Exception { | |
148 | assertTrue("equals", ts0.equals(ts0copy)); | |
149 | assertTrue("equals", ts0copy.equals(ts0copy2)); | |
150 | assertTrue("equals", ts0.equals(ts0copy2)); | |
151 | ||
152 | assertTrue("equals", ts1.equals(ts1copy)); | |
153 | assertTrue("equals", ts1copy.equals(ts1copy2)); | |
154 | assertTrue("equals", ts1.equals(ts1copy2)); | |
155 | } | |
156 | ||
cbd4ad82 FC |
157 | public void testEqualsNull() throws Exception { |
158 | assertTrue("equals", !ts0.equals(null)); | |
159 | assertTrue("equals", !ts1.equals(null)); | |
160 | } | |
161 | ||
2fb2eb37 FC |
162 | // ------------------------------------------------------------------------ |
163 | // hashCode | |
164 | // ------------------------------------------------------------------------ | |
165 | ||
166 | public void testHashCode() throws Exception { | |
167 | assertTrue("hashCode", ts0.hashCode() == ts0copy.hashCode()); | |
168 | assertTrue("hashCode", ts1.hashCode() == ts1copy.hashCode()); | |
169 | ||
170 | assertTrue("hashCode", ts0.hashCode() != ts1.hashCode()); | |
171 | } | |
172 | ||
cbd4ad82 | 173 | // ------------------------------------------------------------------------ |
d18dd09b | 174 | // toString |
cbd4ad82 | 175 | // ------------------------------------------------------------------------ |
d18dd09b ASL |
176 | |
177 | public void testToString() throws Exception { | |
5179fc01 FC |
178 | assertEquals("toString", "TmfTimestamp [fValue=0, fScale=0, fPrecision=0]", ts0.toString()); |
179 | assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=0, fPrecision=0]", ts1.toString()); | |
180 | assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=-1, fPrecision=0]", ts2.toString()); | |
181 | assertEquals("toString", "TmfTimestamp [fValue=12345, fScale=2, fPrecision=5]", ts3.toString()); | |
d18dd09b | 182 | } |
cbd4ad82 | 183 | |
ff4ed569 FC |
184 | // ------------------------------------------------------------------------ |
185 | // clone | |
186 | // ------------------------------------------------------------------------ | |
187 | ||
188 | public class MyTimestamp extends TmfTimestamp { | |
189 | @Override | |
190 | public boolean equals(Object other) { | |
191 | return super.equals(other); | |
192 | } | |
193 | @Override | |
194 | public MyTimestamp clone() { | |
195 | return (MyTimestamp) super.clone(); | |
196 | } | |
197 | } | |
198 | ||
199 | public void testClone() throws Exception { | |
4df4581d | 200 | ITmfTimestamp timestamp = ts0.clone(); |
ff4ed569 FC |
201 | assertEquals("clone", timestamp, ts0); |
202 | } | |
203 | ||
204 | public void testClone2() throws Exception { | |
205 | MyTimestamp timestamp = new MyTimestamp(); | |
206 | MyTimestamp clone = timestamp.clone(); | |
207 | assertEquals("clone", clone, timestamp); | |
208 | } | |
209 | ||
cbd4ad82 | 210 | // ------------------------------------------------------------------------ |
5179fc01 | 211 | // normalize |
cbd4ad82 | 212 | // ------------------------------------------------------------------------ |
d18dd09b | 213 | |
5179fc01 | 214 | public void testNormalizeOffset() throws Exception { |
d18dd09b | 215 | |
5179fc01 | 216 | ITmfTimestamp ts = ts0.normalize(0, 0); |
cbd4ad82 FC |
217 | assertEquals("getValue", 0, ts.getValue()); |
218 | assertEquals("getscale", 0, ts.getScale()); | |
219 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
220 | ||
5179fc01 | 221 | ts = ts0.normalize(12345, 0); |
cbd4ad82 FC |
222 | assertEquals("getValue", 12345, ts.getValue()); |
223 | assertEquals("getscale", 0, ts.getScale()); | |
224 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b | 225 | |
5179fc01 | 226 | ts = ts0.normalize(10, 0); |
cbd4ad82 FC |
227 | assertEquals("getValue", 10, ts.getValue()); |
228 | assertEquals("getscale", 0, ts.getScale()); | |
229 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b | 230 | |
5179fc01 | 231 | ts = ts0.normalize(-10, 0); |
cbd4ad82 FC |
232 | assertEquals("getValue", -10, ts.getValue()); |
233 | assertEquals("getscale", 0, ts.getScale()); | |
234 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b ASL |
235 | } |
236 | ||
5179fc01 | 237 | public void testNormalizeScale() throws Exception { |
d18dd09b | 238 | |
5179fc01 | 239 | ITmfTimestamp ts = ts0.normalize(0, 10); |
cbd4ad82 FC |
240 | assertEquals("getValue", 0, ts.getValue()); |
241 | assertEquals("getscale", 10, ts.getScale()); | |
242 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b | 243 | |
5179fc01 | 244 | ts = ts0.normalize(0, -10); |
cbd4ad82 FC |
245 | assertEquals("getValue", 0, ts.getValue()); |
246 | assertEquals("getscale", -10, ts.getScale()); | |
247 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
248 | } | |
d18dd09b | 249 | |
5179fc01 FC |
250 | public void testNormalizeOffsetAndScale() throws Exception { |
251 | int SCALE = 12; | |
cbd4ad82 | 252 | |
5179fc01 | 253 | ITmfTimestamp ts = ts0.normalize(0, SCALE); |
cbd4ad82 FC |
254 | assertEquals("getValue", 0, ts.getValue()); |
255 | assertEquals("getscale", SCALE, ts.getScale()); | |
d18dd09b ASL |
256 | assertEquals("getPrecision", 0, ts.getPrecision()); |
257 | ||
5179fc01 | 258 | ts = ts0.normalize(12345, SCALE); |
cbd4ad82 FC |
259 | assertEquals("getValue", 12345, ts.getValue()); |
260 | assertEquals("getscale", SCALE, ts.getScale()); | |
d18dd09b ASL |
261 | assertEquals("getPrecision", 0, ts.getPrecision()); |
262 | ||
5179fc01 | 263 | ts = ts0.normalize(10, SCALE); |
cbd4ad82 FC |
264 | assertEquals("getValue", 10, ts.getValue()); |
265 | assertEquals("getscale", SCALE, ts.getScale()); | |
266 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b | 267 | |
5179fc01 | 268 | ts = ts0.normalize(-10, SCALE); |
cbd4ad82 FC |
269 | assertEquals("getValue", -10, ts.getValue()); |
270 | assertEquals("getscale", SCALE, ts.getScale()); | |
271 | assertEquals("getPrecision", 0, ts.getPrecision()); | |
d18dd09b ASL |
272 | } |
273 | ||
cbd4ad82 | 274 | // ------------------------------------------------------------------------ |
5179fc01 | 275 | // compareTo |
cbd4ad82 | 276 | // ------------------------------------------------------------------------ |
d18dd09b ASL |
277 | |
278 | public void testCompareToSameScale() throws Exception { | |
5179fc01 FC |
279 | TmfTimestamp ts1 = new TmfTimestamp(900, 0, 50); |
280 | TmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); | |
281 | TmfTimestamp ts3 = new TmfTimestamp(1100, 0, 50); | |
282 | TmfTimestamp ts4 = new TmfTimestamp(1000, 0, 75); | |
d18dd09b ASL |
283 | |
284 | assertTrue(ts1.compareTo(ts1, false) == 0); | |
285 | ||
cbd4ad82 FC |
286 | assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); |
287 | assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); | |
288 | assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); | |
d18dd09b | 289 | |
cbd4ad82 FC |
290 | assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); |
291 | assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); | |
292 | assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0); | |
d18dd09b | 293 | |
cbd4ad82 FC |
294 | assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); |
295 | assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); | |
296 | assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); | |
d18dd09b ASL |
297 | } |
298 | ||
299 | public void testCompareToDifferentScale() throws Exception { | |
5179fc01 FC |
300 | TmfTimestamp ts1 = new TmfTimestamp(9000, -1, 50); |
301 | TmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); | |
302 | TmfTimestamp ts3 = new TmfTimestamp(110, 1, 50); | |
303 | TmfTimestamp ts4 = new TmfTimestamp(1, 3, 75); | |
d18dd09b | 304 | |
cbd4ad82 | 305 | assertTrue("CompareTo", ts1.compareTo(ts1, false) == 0); |
d18dd09b | 306 | |
cbd4ad82 FC |
307 | assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); |
308 | assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); | |
309 | assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); | |
d18dd09b | 310 | |
cbd4ad82 FC |
311 | assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); |
312 | assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); | |
313 | assertTrue("CompareTo", ts2.compareTo(ts4, false) == 0); | |
d18dd09b | 314 | |
cbd4ad82 FC |
315 | assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); |
316 | assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); | |
317 | assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); | |
d18dd09b ASL |
318 | } |
319 | ||
320 | public void testCompareToWithinPrecision() throws Exception { | |
5179fc01 FC |
321 | TmfTimestamp ts1 = new TmfTimestamp(900, 0, 50); |
322 | TmfTimestamp ts2 = new TmfTimestamp(1000, 0, 50); | |
323 | TmfTimestamp ts3 = new TmfTimestamp(1100, 0, 50); | |
324 | TmfTimestamp ts4 = new TmfTimestamp(1000, 0, 75); | |
d18dd09b | 325 | |
cbd4ad82 | 326 | assertTrue("CompareTo", ts1.compareTo(ts1, true) == 0); |
d18dd09b | 327 | |
cbd4ad82 FC |
328 | assertTrue("CompareTo", ts1.compareTo(ts2, true) == 0); |
329 | assertTrue("CompareTo", ts1.compareTo(ts3, true) < 0); | |
330 | assertTrue("CompareTo", ts1.compareTo(ts4, true) == 0); | |
d18dd09b | 331 | |
cbd4ad82 FC |
332 | assertTrue("CompareTo", ts2.compareTo(ts1, true) == 0); |
333 | assertTrue("CompareTo", ts2.compareTo(ts3, true) == 0); | |
334 | assertTrue("CompareTo", ts2.compareTo(ts4, true) == 0); | |
d18dd09b | 335 | |
cbd4ad82 FC |
336 | assertTrue("CompareTo", ts3.compareTo(ts1, true) > 0); |
337 | assertTrue("CompareTo", ts3.compareTo(ts2, true) == 0); | |
338 | assertTrue("CompareTo", ts3.compareTo(ts4, true) == 0); | |
d18dd09b ASL |
339 | } |
340 | ||
341 | public void testCompareToLargeScale() throws Exception { | |
5179fc01 FC |
342 | TmfTimestamp ts1 = new TmfTimestamp(-1, 100); |
343 | TmfTimestamp ts2 = new TmfTimestamp(-1000, -100); | |
344 | TmfTimestamp ts3 = new TmfTimestamp(1, 100); | |
345 | TmfTimestamp ts4 = new TmfTimestamp(1000, -100); | |
d18dd09b | 346 | |
cbd4ad82 FC |
347 | assertTrue("CompareTo", ts1.compareTo(ts2, false) < 0); |
348 | assertTrue("CompareTo", ts1.compareTo(ts3, false) < 0); | |
349 | assertTrue("CompareTo", ts1.compareTo(ts4, false) < 0); | |
d18dd09b | 350 | |
cbd4ad82 FC |
351 | assertTrue("CompareTo", ts2.compareTo(ts1, false) > 0); |
352 | assertTrue("CompareTo", ts2.compareTo(ts3, false) < 0); | |
353 | assertTrue("CompareTo", ts2.compareTo(ts4, false) < 0); | |
d18dd09b | 354 | |
cbd4ad82 FC |
355 | assertTrue("CompareTo", ts3.compareTo(ts1, false) > 0); |
356 | assertTrue("CompareTo", ts3.compareTo(ts2, false) > 0); | |
357 | assertTrue("CompareTo", ts3.compareTo(ts4, false) > 0); | |
d18dd09b | 358 | |
cbd4ad82 FC |
359 | assertTrue("CompareTo", ts4.compareTo(ts1, false) > 0); |
360 | assertTrue("CompareTo", ts4.compareTo(ts2, false) > 0); | |
361 | assertTrue("CompareTo", ts4.compareTo(ts3, false) < 0); | |
d18dd09b ASL |
362 | } |
363 | ||
cbd4ad82 | 364 | public void testCompareToBigRanges() throws Exception { |
5179fc01 FC |
365 | TmfTimestamp ts0a = new TmfTimestamp( 0, Integer.MAX_VALUE); |
366 | TmfTimestamp ts0b = new TmfTimestamp( 0, Integer.MIN_VALUE); | |
367 | TmfTimestamp ts1 = new TmfTimestamp(-1, Integer.MAX_VALUE); | |
368 | TmfTimestamp ts2 = new TmfTimestamp(-1, Integer.MIN_VALUE); | |
369 | TmfTimestamp ts3 = new TmfTimestamp( 1, Integer.MAX_VALUE); | |
370 | TmfTimestamp ts4 = new TmfTimestamp( 1, Integer.MIN_VALUE); | |
d18dd09b | 371 | |
f3a4c7f4 FC |
372 | assertEquals("CompareTo", 1, ts0a.compareTo(TmfTimestamp.BigBang, false)); |
373 | assertEquals("CompareTo", -1, ts0a.compareTo(TmfTimestamp.BigCrunch, false)); | |
cbd4ad82 | 374 | |
f3a4c7f4 FC |
375 | assertEquals("CompareTo", 1, ts0b.compareTo(TmfTimestamp.BigBang, false)); |
376 | assertEquals("CompareTo", -1, ts0b.compareTo(TmfTimestamp.BigCrunch, false)); | |
cbd4ad82 | 377 | |
f3a4c7f4 FC |
378 | assertEquals("CompareTo", 0, ts0a.compareTo(ts0b, false)); |
379 | assertEquals("CompareTo", 0, ts0b.compareTo(ts0a, false)); | |
cbd4ad82 | 380 | |
f3a4c7f4 FC |
381 | assertEquals("CompareTo", 1, ts0a.compareTo(TmfTimestamp.BigBang, false)); |
382 | assertEquals("CompareTo", -1, ts0a.compareTo(TmfTimestamp.BigCrunch, false)); | |
cbd4ad82 | 383 | |
f3a4c7f4 FC |
384 | assertEquals("CompareTo", 1, ts1.compareTo(TmfTimestamp.BigBang, false)); |
385 | assertEquals("CompareTo", -1, ts1.compareTo(TmfTimestamp.BigCrunch, false)); | |
d18dd09b | 386 | |
f3a4c7f4 FC |
387 | assertEquals("CompareTo", 1, ts2.compareTo(TmfTimestamp.BigBang, false)); |
388 | assertEquals("CompareTo", -1, ts2.compareTo(TmfTimestamp.BigCrunch, false)); | |
d18dd09b | 389 | |
f3a4c7f4 FC |
390 | assertEquals("CompareTo", 1, ts3.compareTo(TmfTimestamp.BigBang, false)); |
391 | assertEquals("CompareTo", -1, ts3.compareTo(TmfTimestamp.BigCrunch, false)); | |
d18dd09b | 392 | |
f3a4c7f4 FC |
393 | assertEquals("CompareTo", 1, ts4.compareTo(TmfTimestamp.BigBang, false)); |
394 | assertEquals("CompareTo", -1, ts4.compareTo(TmfTimestamp.BigCrunch, false)); | |
d18dd09b ASL |
395 | } |
396 | ||
73005152 BH |
397 | // ------------------------------------------------------------------------ |
398 | // getDelta | |
399 | // ------------------------------------------------------------------------ | |
400 | ||
401 | public void testDelta() throws Exception { | |
402 | // Delta for same scale and precision (delta > 0) | |
5179fc01 FC |
403 | TmfTimestamp ts0 = new TmfTimestamp(10, 9); |
404 | TmfTimestamp ts1 = new TmfTimestamp(5, 9); | |
405 | TmfTimestamp exp = new TmfTimestamp(5, 9); | |
73005152 | 406 | |
5179fc01 | 407 | ITmfTimestamp delta = ts0.getDelta(ts1); |
73005152 BH |
408 | assertEquals("getDelta", 0, delta.compareTo(exp, false)); |
409 | ||
410 | // Delta for same scale and precision (delta < 0) | |
5179fc01 FC |
411 | ts0 = new TmfTimestamp( 5, 9); |
412 | ts1 = new TmfTimestamp(10, 9); | |
413 | exp = new TmfTimestamp(-5, 9); | |
73005152 BH |
414 | |
415 | delta = ts0.getDelta(ts1); | |
416 | assertEquals("getDelta", 0, delta.compareTo(exp, false)); | |
417 | ||
418 | // Delta for different scale and same precision (delta > 0) | |
5179fc01 FC |
419 | ts0 = new TmfTimestamp( 5, 9); |
420 | ts1 = new TmfTimestamp(10, 8); | |
421 | exp = new TmfTimestamp( 4, 9); | |
73005152 BH |
422 | |
423 | delta = ts0.getDelta(ts1); | |
424 | assertEquals("getDelta", 0, delta.compareTo(exp, false)); | |
425 | ||
426 | // Delta for different scale and same precision (delta > 0) | |
5179fc01 FC |
427 | ts0 = new TmfTimestamp( 5, 9); |
428 | ts1 = new TmfTimestamp(10, 7); | |
429 | exp = new TmfTimestamp( 5, 9); | |
73005152 BH |
430 | |
431 | delta = ts0.getDelta(ts1); | |
432 | assertEquals("getDelta", 0, delta.compareTo(exp, false)); | |
433 | ||
434 | // Delta for different scale and same precision | |
5179fc01 FC |
435 | ts0 = new TmfTimestamp(10, 9); |
436 | ts1 = new TmfTimestamp( 5, 8); | |
437 | exp = new TmfTimestamp(10, 9); | |
73005152 BH |
438 | |
439 | delta = ts0.getDelta(ts1); | |
440 | assertEquals("getDelta", 0, delta.compareTo(exp, false)); | |
441 | ||
442 | // Delta for same scale and different precision | |
5179fc01 FC |
443 | ts0 = new TmfTimestamp(10, 9, 1); |
444 | ts1 = new TmfTimestamp( 5, 9, 2); | |
445 | exp = new TmfTimestamp( 5, 9, 3); | |
73005152 BH |
446 | |
447 | delta = ts0.getDelta(ts1); | |
448 | assertEquals("getDelta", 0, delta.compareTo(exp, true)); | |
5179fc01 | 449 | assertEquals("precision", 3, delta.getPrecision()); |
73005152 BH |
450 | |
451 | // Delta for same scale and different precision | |
5179fc01 FC |
452 | ts0 = new TmfTimestamp( 5, 9, 2); |
453 | ts1 = new TmfTimestamp(10, 9, 1); | |
454 | exp = new TmfTimestamp(-5, 9, 3); | |
73005152 BH |
455 | |
456 | delta = ts0.getDelta(ts1); | |
5179fc01 FC |
457 | assertEquals("getDelta", 0, delta.compareTo(exp, true)); |
458 | assertEquals("precision", 3, delta.getPrecision()); | |
73005152 BH |
459 | |
460 | // Delta for different scale and different precision | |
5179fc01 FC |
461 | ts0 = new TmfTimestamp( 5, 9, 2); |
462 | ts1 = new TmfTimestamp(10, 8, 1); | |
463 | exp = new TmfTimestamp( 4, 9, 3); | |
73005152 BH |
464 | delta = ts0.getDelta(ts1); |
465 | assertEquals("getDelta", 0, delta.compareTo(exp, true)); | |
466 | assertEquals("precision", 2, delta.getPrecision()); | |
467 | } | |
d18dd09b | 468 | } |