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
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
20 import org
.junit
.Test
;
23 * Unit test for the {@link ITmfStateValue#compareTo(ITmfStateValue)} method
25 * @author Naser Ezzati
27 public class StateValueCompareToTest
{
29 // ------------------------------------------------------------------------
31 // ------------------------------------------------------------------------
33 /* State values that will be used */
34 private static final ITmfStateValue BASE_INT_VALUE
= TmfStateValue
.newValueInt(10);
35 private static final ITmfStateValue BIGGER_INT_VALUE
= TmfStateValue
.newValueInt(20);
36 private static final ITmfStateValue SMALLER_INT_VALUE
= TmfStateValue
.newValueInt(6);
38 private static final ITmfStateValue BASE_LONG_VALUE
= TmfStateValue
.newValueLong(10);
39 private static final ITmfStateValue BIGGER_LONG_VALUE
= TmfStateValue
.newValueLong(20);
40 private static final ITmfStateValue SMALLER_LONG_VALUE
= TmfStateValue
.newValueLong(6);
41 private static final ITmfStateValue MIN_LONG_VALUE
= TmfStateValue
.newValueLong(Long
.MIN_VALUE
);
42 private static final ITmfStateValue MAX_LONG_VALUE
= TmfStateValue
.newValueLong(Long
.MAX_VALUE
);
44 private static final ITmfStateValue BASE_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(10.00);
45 private static final ITmfStateValue BIGGER_DOUBLE_VALUE1
= TmfStateValue
.newValueDouble(20.00);
46 private static final ITmfStateValue BIGGER_DOUBLE_VALUE2
= TmfStateValue
.newValueDouble(10.03);
47 private static final ITmfStateValue SMALLER_DOUBLE_VALUE1
= TmfStateValue
.newValueDouble(6.00);
48 private static final ITmfStateValue SMALLER_DOUBLE_VALUE2
= TmfStateValue
.newValueDouble(9.99);
49 private static final ITmfStateValue MIN_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(Double
.MIN_VALUE
);
50 private static final ITmfStateValue MAX_DOUBLE_VALUE
= TmfStateValue
.newValueDouble(Double
.MAX_VALUE
);
51 private static final ITmfStateValue POSITIVE_INFINITY
= TmfStateValue
.newValueDouble(Double
.POSITIVE_INFINITY
);
52 private static final ITmfStateValue NEGATIVE_INFINITY
= TmfStateValue
.newValueDouble(Double
.NEGATIVE_INFINITY
);
54 private static final ITmfStateValue BASE_STRING_VALUE
= TmfStateValue
.newValueString("D");
55 private static final ITmfStateValue BIGGER_STRING_VALUE
= TmfStateValue
.newValueString("Z");
56 private static final ITmfStateValue SMALLER_STRING_VALUE
= TmfStateValue
.newValueString("A");
58 private static final ITmfStateValue NULL_VALUE
= TmfStateValue
.nullValue();
60 // ------------------------------------------------------------------------
61 // Comparisons of Integer state values
62 // ------------------------------------------------------------------------
65 * Compare Integer state values together
68 public void compareIntWithInt() {
69 assertTrue(BASE_INT_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
70 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
71 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
75 * Compare Integer with Long state values
78 public void compareIntWithLong() {
79 assertTrue(BASE_INT_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
80 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
81 assertTrue(BASE_INT_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
83 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_LONG_VALUE
) > 0);
84 assertTrue(BASE_INT_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
88 * Compare Integer with Double state values
91 public void compareIntWithDouble() {
92 assertTrue(BASE_INT_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
93 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_DOUBLE_VALUE1
) < 0);
94 assertTrue(BASE_INT_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
95 assertTrue(BASE_INT_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
96 assertTrue(BASE_INT_VALUE
.compareTo(POSITIVE_INFINITY
) < 0);
97 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_DOUBLE_VALUE1
) > 0);
98 assertTrue(BASE_INT_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
99 assertTrue(BASE_INT_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
100 assertTrue(BASE_INT_VALUE
.compareTo(NEGATIVE_INFINITY
) > 0);
104 * Compare Integer with Null state values
107 public void compareIntWithNull() {
108 assertTrue(BASE_INT_VALUE
.compareTo(NULL_VALUE
) > 0);
112 * Compare Integer with String state values (should fail)
114 @Test(expected
= StateValueTypeException
.class)
115 public void tcompareIntWithString() {
116 BASE_INT_VALUE
.compareTo(BASE_STRING_VALUE
);
119 // ------------------------------------------------------------------------
120 // Comparisons of Long state values
121 // ------------------------------------------------------------------------
124 * Compare Long with Integer state values
127 public void compareLongWithInt() {
129 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
130 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
131 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
135 * Compare Long state values together
138 public void compareLongWithLong() {
139 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
140 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
141 assertTrue(BASE_LONG_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
142 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_LONG_VALUE
) > 0);
143 assertTrue(BASE_LONG_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
147 * Compare Long with Double state values
150 public void compareLongWithDouble() {
151 assertTrue(BASE_LONG_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
152 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_DOUBLE_VALUE1
) < 0);
153 assertTrue(BASE_LONG_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
154 assertTrue(BASE_LONG_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
155 assertTrue(BASE_LONG_VALUE
.compareTo(POSITIVE_INFINITY
) < 0);
156 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_DOUBLE_VALUE1
) > 0);
157 assertTrue(BASE_LONG_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
158 assertTrue(BASE_LONG_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
159 assertTrue(BASE_LONG_VALUE
.compareTo(NEGATIVE_INFINITY
) > 0);
163 * Compare Long with Null state values
166 public void compareLongWithNull() {
167 assertTrue(BASE_LONG_VALUE
.compareTo(NULL_VALUE
) > 0);
171 * Compare Long with String state values (should fail)
173 @Test(expected
= StateValueTypeException
.class)
174 public void compareLongWithString() {
175 BASE_LONG_VALUE
.compareTo(BASE_STRING_VALUE
);
178 // ------------------------------------------------------------------------
179 // Comparisons of Double state values
180 // ------------------------------------------------------------------------
183 * Compare Double with Integer state values
186 public void compareDoubleWithInt() {
187 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_INT_VALUE
) == 0);
188 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_INT_VALUE
) < 0);
189 assertTrue(BASE_DOUBLE_VALUE
.compareTo(SMALLER_INT_VALUE
) > 0);
193 * Compare Double with Long state values
196 public void compareDoubleWithLong() {
197 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_LONG_VALUE
) == 0);
198 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_LONG_VALUE
) < 0);
199 assertTrue(SMALLER_DOUBLE_VALUE2
.compareTo(BASE_LONG_VALUE
) < 0);
200 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MAX_LONG_VALUE
) < 0);
201 assertTrue(BIGGER_DOUBLE_VALUE1
.compareTo(SMALLER_LONG_VALUE
) > 0);
202 assertTrue(BIGGER_DOUBLE_VALUE2
.compareTo(BASE_LONG_VALUE
) > 0);
203 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MIN_LONG_VALUE
) > 0);
207 * Compare Double state values together
210 public void compareDoubleWithDouble() {
211 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BASE_DOUBLE_VALUE
) == 0);
212 assertTrue(BASE_DOUBLE_VALUE
.compareTo(BIGGER_DOUBLE_VALUE2
) < 0);
213 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MAX_DOUBLE_VALUE
) < 0);
214 assertTrue(BASE_DOUBLE_VALUE
.compareTo(SMALLER_DOUBLE_VALUE2
) > 0);
215 assertTrue(BASE_DOUBLE_VALUE
.compareTo(MIN_DOUBLE_VALUE
) > 0);
219 * Compare Double with Null state values
222 public void compareDoubleWithNull() {
223 /* NullValue.unboxDouble returns NaN */
224 assertTrue(BASE_DOUBLE_VALUE
.compareTo(NULL_VALUE
) < 0);
228 * Compare Double with String state values (should fail)
230 @Test(expected
= StateValueTypeException
.class)
231 public void compareDoubleWithString() {
232 BASE_DOUBLE_VALUE
.compareTo(BASE_STRING_VALUE
);
235 // ------------------------------------------------------------------------
236 // Comparisons of String state values
237 // ------------------------------------------------------------------------
240 * Compare String with Integer state values (should fail)
242 @Test(expected
= StateValueTypeException
.class)
243 public void compareStringWithInt() {
244 BASE_STRING_VALUE
.compareTo(BASE_INT_VALUE
);
248 * Compare String with Long state values (should fail)
250 @Test(expected
= StateValueTypeException
.class)
251 public void compareStringWithLong() {
252 BASE_STRING_VALUE
.compareTo(BASE_LONG_VALUE
);
256 * Compare String with Double state values (should fail)
258 @Test(expected
= StateValueTypeException
.class)
259 public void compareStringWithDouble() {
260 BASE_STRING_VALUE
.compareTo(BASE_DOUBLE_VALUE
);
264 * Compare String state values together
267 public void compareStringWithString() {
268 assertTrue(BASE_STRING_VALUE
.compareTo(BASE_STRING_VALUE
) == 0);
269 assertTrue(BASE_STRING_VALUE
.compareTo(SMALLER_STRING_VALUE
) > 0);
270 assertTrue(BASE_STRING_VALUE
.compareTo(BIGGER_STRING_VALUE
) < 0);
274 * Compare String with Null state values
277 public void compareStringWithNull() {
278 assertTrue(BASE_STRING_VALUE
.compareTo(NULL_VALUE
) > 0);
281 // ------------------------------------------------------------------------
282 // Comparisons of Null state values
283 // ------------------------------------------------------------------------
286 * Compare Null with Integer state values
289 public void compareNullWithInt() {
290 assertTrue(NULL_VALUE
.compareTo(BASE_INT_VALUE
) < 0);
294 * Compare Null with Long state values
297 public void compareNullWithLong() {
298 assertTrue(NULL_VALUE
.compareTo(BASE_LONG_VALUE
) < 0);
302 * Compare Null with Double state values
305 public void compareNullWithDouble() {
306 /* NullValue.unboxDouble returns NaN */
307 assertTrue(NULL_VALUE
.compareTo(BASE_DOUBLE_VALUE
) > 0);
311 * Compare Null with String state values
314 public void compareNullWithString() {
315 assertTrue(NULL_VALUE
.compareTo(BASE_STRING_VALUE
) < 0);
319 * Compare Null state values together
322 public void compareNullWithNull() {
323 assertTrue(NULL_VALUE
.compareTo(NULL_VALUE
) == 0);