1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made availabComparisonOperator.LE under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is availabComparisonOperator.LE at
7 * http://www.eclipse.org/ComparisonOperator.LEgal/epl-v10.html
10 * Naser Ezzati - Initial API and implementation
11 ******************************************************************************/
13 package org
.eclipse
.tracecompass
.statesystem
.core
.tests
.statevalue
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import org
.eclipse
.jdt
.annotation
.NonNullByDefault
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
21 import org
.junit
.Test
;
24 * Unit test for the {@link ITmfStateValue#compareTo(ITmfStateValue)} method
26 * @author Naser Ezzati
29 public class StateValueCompareToTest
{
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
35 /* State values that will be used */
36 private static final ITmfStateValue BASE_INT_VALUE
= TmfStateValue
.newValueInt(10);
37 private static final ITmfStateValue BIGGER_INT_VALUE
= TmfStateValue
.newValueInt(20);
38 private static final ITmfStateValue SMALLER_INT_VALUE
= TmfStateValue
.newValueInt(6);
40 private static final ITmfStateValue BASE_LONG_VALUE
= TmfStateValue
.newValueLong(10);
41 private static final ITmfStateValue BIGGER_LONG_VALUE
= TmfStateValue
.newValueLong(20);
42 private static final ITmfStateValue SMALLER_LONG_VALUE
= TmfStateValue
.newValueLong(6);
43 private static final ITmfStateValue MIN_LONG_VALUE
= TmfStateValue
.newValueLong(Long
.MIN_VALUE
);
44 private static final ITmfStateValue MAX_LONG_VALUE
= TmfStateValue
.newValueLong(Long
.MAX_VALUE
);
46 private static final ITmfStateValue BASE_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(10.00);
47 private static final ITmfStateValue BIGGER_DOUBLE_VALUE1
= TmfStateValue
.newValueDouble(20.00);
48 private static final ITmfStateValue BIGGER_DOUBLE_VALUE2
= TmfStateValue
.newValueDouble(10.03);
49 private static final ITmfStateValue SMALLER_DOUBLE_VALUE1
= TmfStateValue
.newValueDouble(6.00);
50 private static final ITmfStateValue SMALLER_DOUBLE_VALUE2
= TmfStateValue
.newValueDouble(9.99);
51 private static final ITmfStateValue MIN_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(Double
.MIN_VALUE
);
52 private static final ITmfStateValue MAX_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(Double
.MAX_VALUE
);
53 private static final ITmfStateValue POSITIVE_INFINITY
= TmfStateValue
.newValueDouble(Double
.POSITIVE_INFINITY
);
54 private static final ITmfStateValue NEGATIVE_INFINITY
= TmfStateValue
.newValueDouble(Double
.NEGATIVE_INFINITY
);
56 private static final ITmfStateValue BASE_STRING_VALUE
= TmfStateValue
.newValueString("D");
57 private static final ITmfStateValue BIGGER_STRING_VALUE
= TmfStateValue
.newValueString("Z");
58 private static final ITmfStateValue SMALLER_STRING_VALUE
= TmfStateValue
.newValueString("A");
60 private static final ITmfStateValue NULL_VALUE
= TmfStateValue
.nullValue();
62 // ------------------------------------------------------------------------
63 // Comparisons of Integer state values
64 // ------------------------------------------------------------------------
67 * Compare Integer state values together
70 public void compareIntWithInt() {
71 assertTrue(BASE_INT_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
72 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
73 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
77 * Compare Integer with Long state values
80 public void compareIntWithLong() {
81 assertTrue(BASE_INT_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
82 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
83 assertTrue(BASE_INT_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
85 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_LONG_VALUE
) > 0);
86 assertTrue(BASE_INT_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
90 * Compare Integer with Double state values
93 public void compareIntWithDouble() {
94 assertTrue(BASE_INT_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
95 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_DOUBLE_VALUE1
) < 0);
96 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
97 assertTrue(BASE_INT_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
98 assertTrue(BASE_INT_VALUE
.compareTo(POSITIVE_INFINITY
) < 0);
99 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_DOUBLE_VALUE1
) > 0);
100 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
101 assertTrue(BASE_INT_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
102 assertTrue(BASE_INT_VALUE
.compareTo(NEGATIVE_INFINITY
) > 0);
106 * Compare Integer with Null state values
109 public void compareIntWithNull() {
110 assertTrue(BASE_INT_VALUE
.compareTo(NULL_VALUE
) > 0);
114 * Compare Integer with String state values (should fail)
116 @Test(expected
= StateValueTypeException
.class)
117 public void tcompareIntWithString() {
118 BASE_INT_VALUE
.compareTo(BASE_STRING_VALUE
);
121 // ------------------------------------------------------------------------
122 // Comparisons of Long state values
123 // ------------------------------------------------------------------------
126 * Compare Long with Integer state values
129 public void compareLongWithInt() {
131 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
132 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
133 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
137 * Compare Long state values together
140 public void compareLongWithLong() {
141 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
142 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
143 assertTrue(BASE_LONG_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
144 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_LONG_VALUE
) > 0);
145 assertTrue(BASE_LONG_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
149 * Compare Long with Double state values
152 public void compareLongWithDouble() {
153 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
154 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_DOUBLE_VALUE1
) < 0);
155 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
156 assertTrue(BASE_LONG_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
157 assertTrue(BASE_LONG_VALUE
.compareTo(POSITIVE_INFINITY
) < 0);
158 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_DOUBLE_VALUE1
) > 0);
159 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
160 assertTrue(BASE_LONG_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
161 assertTrue(BASE_LONG_VALUE
.compareTo(NEGATIVE_INFINITY
) > 0);
165 * Compare Long with Null state values
168 public void compareLongWithNull() {
169 assertTrue(BASE_LONG_VALUE
.compareTo(NULL_VALUE
) > 0);
173 * Compare Long with String state values (should fail)
175 @Test(expected
= StateValueTypeException
.class)
176 public void compareLongWithString() {
177 BASE_LONG_VALUE
.compareTo(BASE_STRING_VALUE
);
180 // ------------------------------------------------------------------------
181 // Comparisons of Double state values
182 // ------------------------------------------------------------------------
185 * Compare Double with Integer state values
188 public void compareDoubleWithInt() {
189 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
190 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
191 assertTrue(BASE_DOUBLE_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
195 * Compare Double with Long state values
198 public void compareDoubleWithLong() {
199 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
200 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
201 assertTrue(SMALLER_DOUBLE_VALUE2
.compareTo(BASE_LONG_VALUE
) < 0);
202 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
203 assertTrue(BIGGER_DOUBLE_VALUE1
.compareTo(SMALLER_LONG_VALUE
) > 0);
204 assertTrue(BIGGER_DOUBLE_VALUE2
.compareTo(BASE_LONG_VALUE
) > 0);
205 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
209 * Compare Double state values together
212 public void compareDoubleWithDouble() {
213 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
214 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
215 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
216 assertTrue(BASE_DOUBLE_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
217 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
221 * Compare Double with Null state values
224 public void compareDoubleWithNull() {
225 /* NullValue.unboxDouble returns NaN */
226 assertTrue(BASE_DOUBLE_VALUE
.compareTo(NULL_VALUE
) < 0);
230 * Compare Double with String state values (should fail)
232 @Test(expected
= StateValueTypeException
.class)
233 public void compareDoubleWithString() {
234 BASE_DOUBLE_VALUE
.compareTo(BASE_STRING_VALUE
);
237 // ------------------------------------------------------------------------
238 // Comparisons of String state values
239 // ------------------------------------------------------------------------
242 * Compare String with Integer state values (should fail)
244 @Test(expected
= StateValueTypeException
.class)
245 public void compareStringWithInt() {
246 BASE_STRING_VALUE
.compareTo(BASE_INT_VALUE
);
250 * Compare String with Long state values (should fail)
252 @Test(expected
= StateValueTypeException
.class)
253 public void compareStringWithLong() {
254 BASE_STRING_VALUE
.compareTo(BASE_LONG_VALUE
);
258 * Compare String with Double state values (should fail)
260 @Test(expected
= StateValueTypeException
.class)
261 public void compareStringWithDouble() {
262 BASE_STRING_VALUE
.compareTo(BASE_DOUBLE_VALUE
);
266 * Compare String state values together
269 public void compareStringWithString() {
270 assertTrue(BASE_STRING_VALUE
.compareTo(BASE_STRING_VALUE
) == 0);
271 assertTrue(BASE_STRING_VALUE
.compareTo(SMALLER_STRING_VALUE
) > 0);
272 assertTrue(BASE_STRING_VALUE
.compareTo(BIGGER_STRING_VALUE
) < 0);
276 * Compare String with Null state values
279 public void compareStringWithNull() {
280 assertTrue(BASE_STRING_VALUE
.compareTo(NULL_VALUE
) > 0);
283 // ------------------------------------------------------------------------
284 // Comparisons of Null state values
285 // ------------------------------------------------------------------------
288 * Compare Null with Integer state values
291 public void compareNullWithInt() {
292 assertTrue(NULL_VALUE
.compareTo(BASE_INT_VALUE
) < 0);
296 * Compare Null with Long state values
299 public void compareNullWithLong() {
300 assertTrue(NULL_VALUE
.compareTo(BASE_LONG_VALUE
) < 0);
304 * Compare Null with Double state values
307 public void compareNullWithDouble() {
308 /* NullValue.unboxDouble returns NaN */
309 assertTrue(NULL_VALUE
.compareTo(BASE_DOUBLE_VALUE
) > 0);
313 * Compare Null with String state values
316 public void compareNullWithString() {
317 assertTrue(NULL_VALUE
.compareTo(BASE_STRING_VALUE
) < 0);
321 * Compare Null state values together
324 public void compareNullWithNull() {
325 assertTrue(NULL_VALUE
.compareTo(NULL_VALUE
) == 0);