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