1 /*******************************************************************************
2 * Copyright (c) 2009 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.event
;
15 import junit
.framework
.TestCase
;
18 * <b><u>TmfTimestampTest</u></b>
20 * TODO: Implement me. Please.
22 public class TmfTimestampTest
extends TestCase
{
24 // ========================================================================
26 // ========================================================================
28 public TmfTimestampTest(String name
) {
33 protected void setUp() throws Exception
{
38 protected void tearDown() throws Exception
{
42 // ========================================================================
44 // ========================================================================
46 public void testDefaultConstructor() throws Exception
{
47 TmfTimestamp ts
= new TmfTimestamp();
48 assertEquals("getValue", 0, ts
.getValue());
49 assertEquals("getscale", 0, ts
.getScale());
50 assertEquals("getPrecision", 0, ts
.getPrecision());
53 public void testSimpleConstructor() throws Exception
{
54 TmfTimestamp ts
= new TmfTimestamp(12345);
55 assertEquals("getValue", 12345, ts
.getValue());
56 assertEquals("getscale", 0, ts
.getScale());
57 assertEquals("getPrecision", 0, ts
.getPrecision());
60 public void testSimpleConstructor2() throws Exception
{
61 TmfTimestamp ts
= new TmfTimestamp(12345, (byte) -1);
62 assertEquals("getValue", 12345, ts
.getValue());
63 assertEquals("getscale", -1, ts
.getScale());
64 assertEquals("getPrecision", 0, ts
.getPrecision());
67 public void testFullConstructor() throws Exception
{
68 TmfTimestamp ts
= new TmfTimestamp(12345, (byte) 2, 5);
69 assertEquals("getValue", 12345, ts
.getValue());
70 assertEquals("getscale", 2, ts
.getScale());
71 assertEquals("getPrecision", 5, ts
.getPrecision());
74 public void testCopyConstructor() throws Exception
{
75 TmfTimestamp ts0
= new TmfTimestamp(12345, (byte) 2, 5);
76 TmfTimestamp ts
= new TmfTimestamp(ts0
);
77 assertEquals("getValue", 12345, ts
.getValue());
78 assertEquals("getscale", 2, ts
.getScale());
79 assertEquals("getPrecision", 5, ts
.getPrecision());
82 // ========================================================================
84 // ========================================================================
86 public void testCopyConstructorBigBang() throws Exception
{
87 TmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigBang
);
88 assertEquals("getValue", TmfTimestamp
.BigBang
.getValue(), ts
.getValue());
89 assertEquals("getscale", TmfTimestamp
.BigBang
.getScale(), ts
.getScale());
90 assertEquals("getPrecision", TmfTimestamp
.BigBang
.getPrecision(), ts
.getPrecision());
93 public void testCopyConstructorBigCrunch() throws Exception
{
94 TmfTimestamp ts
= new TmfTimestamp(TmfTimestamp
.BigCrunch
);
95 assertEquals("getValue", TmfTimestamp
.BigCrunch
.getValue(), ts
.getValue());
96 assertEquals("getscale", TmfTimestamp
.BigCrunch
.getScale(), ts
.getScale());
97 assertEquals("getPrecision", TmfTimestamp
.BigCrunch
.getPrecision(), ts
.getPrecision());
100 // ========================================================================
102 // ========================================================================
104 public void testToString() throws Exception
{
105 TmfTimestamp ts1
= new TmfTimestamp();
106 TmfTimestamp ts2
= new TmfTimestamp(1234, (byte) 2);
107 TmfTimestamp ts3
= new TmfTimestamp(1234, (byte) 2, 1);
108 TmfTimestamp ts4
= new TmfTimestamp(-1234, (byte) -1, 4);
110 assertEquals("toString", "[TmfTimestamp(0,0,0)]", ts1
.toString());
111 assertEquals("toString", "[TmfTimestamp(1234,2,0)]", ts2
.toString());
112 assertEquals("toString", "[TmfTimestamp(1234,2,1)]", ts3
.toString());
113 assertEquals("toString", "[TmfTimestamp(-1234,-1,4)]", ts4
.toString());
116 // ========================================================================
118 // ========================================================================
120 public void testSynchronizeOffset() throws Exception
{
121 TmfTimestamp ts0
= new TmfTimestamp(1234, (byte) 0, 1);
122 TmfTimestamp ts
= new TmfTimestamp();
124 ts
= ts0
.synchronize(0, (byte) 0);
125 assertEquals("getValue", 1234, ts
.getValue());
126 assertEquals("getscale", 0, ts
.getScale());
127 assertEquals("getPrecision", 1, ts
.getPrecision());
129 ts
= ts0
.synchronize(10, (byte) 0);
130 assertEquals("getValue", 1244, ts
.getValue());
131 assertEquals("getscale", 0, ts
.getScale());
132 assertEquals("getPrecision", 1, ts
.getPrecision());
134 ts
= ts0
.synchronize(-10, (byte) 0);
135 assertEquals("getValue", 1224, ts
.getValue());
136 assertEquals("getscale", 0, ts
.getScale());
137 assertEquals("getPrecision", 1, ts
.getPrecision());
140 public void testSynchronizeScale() throws Exception
{
141 TmfTimestamp ts0
= new TmfTimestamp(1234, (byte) 0, 12);
142 TmfTimestamp ts
= new TmfTimestamp();
144 ts
= ts0
.synchronize(0, (byte) 0);
145 assertEquals("getValue", 1234, ts
.getValue());
146 assertEquals("getscale", 0, ts
.getScale());
147 assertEquals("getPrecision", 12, ts
.getPrecision());
149 ts
= ts0
.synchronize(0, (byte) 1);
150 assertEquals("getValue", 123, ts
.getValue());
151 assertEquals("getscale", 1, ts
.getScale());
152 assertEquals("getPrecision", 1, ts
.getPrecision());
154 ts
= ts0
.synchronize(0, (byte) 2);
155 assertEquals("getValue", 12, ts
.getValue());
156 assertEquals("getscale", 2, ts
.getScale());
157 assertEquals("getPrecision", 0, ts
.getPrecision());
159 ts
= ts0
.synchronize(0, (byte) 4);
160 assertEquals("getValue", 0, ts
.getValue());
161 assertEquals("getscale", 4, ts
.getScale());
162 assertEquals("getPrecision", 0, ts
.getPrecision());
164 ts
= ts0
.synchronize(0, (byte) -2);
165 assertEquals("getValue", 123400, ts
.getValue());
166 assertEquals("getscale", -2, ts
.getScale());
167 assertEquals("getPrecision", 1200, ts
.getPrecision());
170 public void testSynchronizeOffsetAndScale() throws Exception
{
171 TmfTimestamp ts0
= new TmfTimestamp(1234, (byte) 0, 12);
172 TmfTimestamp ts
= new TmfTimestamp();
174 ts
= ts0
.synchronize(10, (byte) 1);
175 assertEquals("getValue", 133, ts
.getValue());
176 assertEquals("getscale", 1, ts
.getScale());
177 assertEquals("getPrecision", 1, ts
.getPrecision());
179 ts
= ts0
.synchronize(-10, (byte) -1);
180 assertEquals("getValue", 12330, ts
.getValue());
181 assertEquals("getscale", -1, ts
.getScale());
182 assertEquals("getPrecision", 120, ts
.getPrecision());
185 // ========================================================================
187 // ========================================================================
189 public void testGetAdjustmentSameScale() throws Exception
{
190 TmfTimestamp ts0
= new TmfTimestamp(12345, (byte) -2);
191 TmfTimestamp ts
= new TmfTimestamp(10000, (byte) -2);
193 long delta
= ts
.getAdjustment(ts0
);
194 assertEquals("delta", 2345, delta
);
197 public void testGetAdjustmentDifferentScale() throws Exception
{
198 TmfTimestamp ts0
= new TmfTimestamp(12345, (byte) -2);
199 TmfTimestamp ts
= new TmfTimestamp(1, (byte) 2);
201 long delta
= ts
.getAdjustment(ts0
);
202 assertEquals("delta", 2345, delta
);
204 delta
= ts0
.getAdjustment(ts
);
205 assertEquals("delta", 0, delta
);
208 // ========================================================================
210 // ========================================================================
212 public void testCompareToSameScale() throws Exception
{
213 TmfTimestamp ts1
= new TmfTimestamp(900, (byte) 0, 50);
214 TmfTimestamp ts2
= new TmfTimestamp(1000, (byte) 0, 50);
215 TmfTimestamp ts3
= new TmfTimestamp(1100, (byte) 0, 50);
216 TmfTimestamp ts4
= new TmfTimestamp(1000, (byte) 0, 75);
218 assertTrue(ts1
.compareTo(ts1
, false) == 0);
220 assertTrue(ts1
.compareTo(ts2
, false) < 0);
221 assertTrue(ts1
.compareTo(ts3
, false) < 0);
222 assertTrue(ts1
.compareTo(ts4
, false) < 0);
224 assertTrue(ts2
.compareTo(ts1
, false) > 0);
225 assertTrue(ts2
.compareTo(ts3
, false) < 0);
226 assertTrue(ts2
.compareTo(ts4
, false) == 0);
228 assertTrue(ts3
.compareTo(ts1
, false) > 0);
229 assertTrue(ts3
.compareTo(ts2
, false) > 0);
230 assertTrue(ts3
.compareTo(ts4
, false) > 0);
233 public void testCompareToDifferentScale() throws Exception
{
234 TmfTimestamp ts1
= new TmfTimestamp(9000, (byte) -1, 50);
235 TmfTimestamp ts2
= new TmfTimestamp(1000, (byte) 0, 50);
236 TmfTimestamp ts3
= new TmfTimestamp(110, (byte) 1, 50);
237 TmfTimestamp ts4
= new TmfTimestamp(1, (byte) 3, 75);
239 assertTrue(ts1
.compareTo(ts1
, false) == 0);
241 assertTrue(ts1
.compareTo(ts2
, false) < 0);
242 assertTrue(ts1
.compareTo(ts3
, false) < 0);
243 assertTrue(ts1
.compareTo(ts4
, false) < 0);
245 assertTrue(ts2
.compareTo(ts1
, false) > 0);
246 assertTrue(ts2
.compareTo(ts3
, false) < 0);
247 assertTrue(ts2
.compareTo(ts4
, false) == 0);
249 assertTrue(ts3
.compareTo(ts1
, false) > 0);
250 assertTrue(ts3
.compareTo(ts2
, false) > 0);
251 assertTrue(ts3
.compareTo(ts4
, false) > 0);
254 public void testCompareToWithinPrecision() throws Exception
{
255 TmfTimestamp ts1
= new TmfTimestamp(900, (byte) 0, 50);
256 TmfTimestamp ts2
= new TmfTimestamp(1000, (byte) 0, 50);
257 TmfTimestamp ts3
= new TmfTimestamp(1100, (byte) 0, 50);
258 TmfTimestamp ts4
= new TmfTimestamp(1000, (byte) 0, 75);
260 assertTrue(ts1
.compareTo(ts1
, true) == 0);
262 assertTrue(ts1
.compareTo(ts2
, true) == 0);
263 assertTrue(ts1
.compareTo(ts3
, true) < 0);
264 assertTrue(ts1
.compareTo(ts4
, true) == 0);
266 assertTrue(ts2
.compareTo(ts1
, true) == 0);
267 assertTrue(ts2
.compareTo(ts3
, true) == 0);
268 assertTrue(ts2
.compareTo(ts4
, true) == 0);
270 assertTrue(ts3
.compareTo(ts1
, true) > 0);
271 assertTrue(ts3
.compareTo(ts2
, true) == 0);
272 assertTrue(ts3
.compareTo(ts4
, true) == 0);
275 public void testCompareToLargeScale() throws Exception
{
276 TmfTimestamp ts1
= new TmfTimestamp(-1, (byte) 100);
277 TmfTimestamp ts2
= new TmfTimestamp(-1000, (byte) -100);
278 TmfTimestamp ts3
= new TmfTimestamp(1, (byte) 100);
279 TmfTimestamp ts4
= new TmfTimestamp(1000, (byte) -100);
281 assertTrue(ts1
.compareTo(ts2
, false) < 0);
282 assertTrue(ts1
.compareTo(ts3
, false) < 0);
283 assertTrue(ts1
.compareTo(ts4
, false) < 0);
285 assertTrue(ts2
.compareTo(ts1
, false) > 0);
286 assertTrue(ts2
.compareTo(ts3
, false) < 0);
287 assertTrue(ts2
.compareTo(ts4
, false) < 0);
289 assertTrue(ts3
.compareTo(ts1
, false) > 0);
290 assertTrue(ts3
.compareTo(ts2
, false) > 0);
291 assertTrue(ts3
.compareTo(ts4
, false) > 0);
293 assertTrue(ts4
.compareTo(ts1
, false) > 0);
294 assertTrue(ts4
.compareTo(ts2
, false) > 0);
295 assertTrue(ts4
.compareTo(ts3
, false) < 0);
298 public void testCompareToBigGuys() throws Exception
{
299 TmfTimestamp ts1
= new TmfTimestamp(-1, Byte
.MAX_VALUE
);
300 TmfTimestamp ts2
= new TmfTimestamp(-1, Byte
.MIN_VALUE
);
301 TmfTimestamp ts3
= new TmfTimestamp(1, Byte
.MAX_VALUE
);
302 TmfTimestamp ts4
= new TmfTimestamp(1, Byte
.MIN_VALUE
);
304 assertTrue(ts1
.compareTo(TmfTimestamp
.BigBang
, false) > 0);
305 assertTrue(ts1
.compareTo(TmfTimestamp
.BigCrunch
, false) < 0);
307 assertTrue(ts2
.compareTo(TmfTimestamp
.BigBang
, false) > 0);
308 assertTrue(ts2
.compareTo(TmfTimestamp
.BigCrunch
, false) < 0);
310 assertTrue(ts3
.compareTo(TmfTimestamp
.BigBang
, false) > 0);
311 assertTrue(ts3
.compareTo(TmfTimestamp
.BigCrunch
, false) < 0);
313 assertTrue(ts4
.compareTo(TmfTimestamp
.BigBang
, false) > 0);
314 assertTrue(ts4
.compareTo(TmfTimestamp
.BigCrunch
, false) < 0);
This page took 0.037885 seconds and 5 git commands to generate.