Commit | Line | Data |
---|---|---|
f0247a1a NE |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Naser Ezzati - Initial API and implementation | |
11 | ******************************************************************************/ | |
12 | ||
13 | package org.eclipse.tracecompass.statesystem.core.tests.statevalue; | |
14 | ||
15 | import static org.junit.Assert.assertTrue; | |
16 | ||
aa353506 | 17 | import org.eclipse.jdt.annotation.NonNullByDefault; |
f0247a1a NE |
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; | |
22 | ||
23 | /** | |
24 | * Unit test for the {@link ITmfStateValue#compareTo(ITmfStateValue)} method | |
25 | * | |
26 | * @author Naser Ezzati | |
27 | */ | |
aa353506 | 28 | @NonNullByDefault |
f0247a1a NE |
29 | public class StateValueCompareToTest { |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Static fields | |
33 | // ------------------------------------------------------------------------ | |
34 | ||
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); | |
39 | ||
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); | |
45 | ||
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); | |
55 | ||
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"); | |
59 | ||
60 | private static final ITmfStateValue NULL_VALUE = TmfStateValue.nullValue(); | |
61 | ||
62 | // ------------------------------------------------------------------------ | |
63 | // Comparisons of Integer state values | |
64 | // ------------------------------------------------------------------------ | |
65 | ||
66 | /** | |
67 | * Compare Integer state values together | |
68 | */ | |
69 | @Test | |
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); | |
74 | } | |
75 | ||
76 | /** | |
77 | * Compare Integer with Long state values | |
78 | */ | |
79 | @Test | |
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); | |
84 | ||
85 | assertTrue(BASE_INT_VALUE.compareTo(SMALLER_LONG_VALUE) > 0); | |
86 | assertTrue(BASE_INT_VALUE.compareTo(MIN_LONG_VALUE) > 0); | |
87 | } | |
88 | ||
89 | /** | |
90 | * Compare Integer with Double state values | |
91 | */ | |
92 | @Test | |
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); | |
103 | } | |
104 | ||
105 | /** | |
106 | * Compare Integer with Null state values | |
107 | */ | |
108 | @Test | |
109 | public void compareIntWithNull() { | |
110 | assertTrue(BASE_INT_VALUE.compareTo(NULL_VALUE) > 0); | |
111 | } | |
112 | ||
113 | /** | |
114 | * Compare Integer with String state values (should fail) | |
115 | */ | |
116 | @Test(expected = StateValueTypeException.class) | |
117 | public void tcompareIntWithString() { | |
118 | BASE_INT_VALUE.compareTo(BASE_STRING_VALUE); | |
119 | } | |
120 | ||
121 | // ------------------------------------------------------------------------ | |
122 | // Comparisons of Long state values | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
125 | /** | |
126 | * Compare Long with Integer state values | |
127 | */ | |
128 | @Test | |
129 | public void compareLongWithInt() { | |
130 | // with Integer | |
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); | |
134 | } | |
135 | ||
136 | /** | |
137 | * Compare Long state values together | |
138 | */ | |
139 | @Test | |
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); | |
146 | } | |
147 | ||
148 | /** | |
149 | * Compare Long with Double state values | |
150 | */ | |
151 | @Test | |
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); | |
162 | } | |
163 | ||
164 | /** | |
165 | * Compare Long with Null state values | |
166 | */ | |
167 | @Test | |
168 | public void compareLongWithNull() { | |
169 | assertTrue(BASE_LONG_VALUE.compareTo(NULL_VALUE) > 0); | |
170 | } | |
171 | ||
172 | /** | |
173 | * Compare Long with String state values (should fail) | |
174 | */ | |
175 | @Test(expected = StateValueTypeException.class) | |
176 | public void compareLongWithString() { | |
177 | BASE_LONG_VALUE.compareTo(BASE_STRING_VALUE); | |
178 | } | |
179 | ||
180 | // ------------------------------------------------------------------------ | |
181 | // Comparisons of Double state values | |
182 | // ------------------------------------------------------------------------ | |
183 | ||
184 | /** | |
185 | * Compare Double with Integer state values | |
186 | */ | |
187 | @Test | |
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); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Compare Double with Long state values | |
196 | */ | |
197 | @Test | |
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); | |
206 | } | |
207 | ||
208 | /** | |
209 | * Compare Double state values together | |
210 | */ | |
211 | @Test | |
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); | |
218 | } | |
219 | ||
220 | /** | |
221 | * Compare Double with Null state values | |
222 | */ | |
223 | @Test | |
224 | public void compareDoubleWithNull() { | |
225 | /* NullValue.unboxDouble returns NaN */ | |
226 | assertTrue(BASE_DOUBLE_VALUE.compareTo(NULL_VALUE) < 0); | |
227 | } | |
228 | ||
229 | /** | |
230 | * Compare Double with String state values (should fail) | |
231 | */ | |
232 | @Test(expected = StateValueTypeException.class) | |
233 | public void compareDoubleWithString() { | |
234 | BASE_DOUBLE_VALUE.compareTo(BASE_STRING_VALUE); | |
235 | } | |
236 | ||
237 | // ------------------------------------------------------------------------ | |
238 | // Comparisons of String state values | |
239 | // ------------------------------------------------------------------------ | |
240 | ||
241 | /** | |
242 | * Compare String with Integer state values (should fail) | |
243 | */ | |
244 | @Test(expected = StateValueTypeException.class) | |
245 | public void compareStringWithInt() { | |
246 | BASE_STRING_VALUE.compareTo(BASE_INT_VALUE); | |
247 | } | |
248 | ||
249 | /** | |
250 | * Compare String with Long state values (should fail) | |
251 | */ | |
252 | @Test(expected = StateValueTypeException.class) | |
253 | public void compareStringWithLong() { | |
254 | BASE_STRING_VALUE.compareTo(BASE_LONG_VALUE); | |
255 | } | |
256 | ||
257 | /** | |
258 | * Compare String with Double state values (should fail) | |
259 | */ | |
260 | @Test(expected = StateValueTypeException.class) | |
261 | public void compareStringWithDouble() { | |
262 | BASE_STRING_VALUE.compareTo(BASE_DOUBLE_VALUE); | |
263 | } | |
264 | ||
265 | /** | |
266 | * Compare String state values together | |
267 | */ | |
268 | @Test | |
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); | |
273 | } | |
274 | ||
275 | /** | |
276 | * Compare String with Null state values | |
277 | */ | |
278 | @Test | |
279 | public void compareStringWithNull() { | |
280 | assertTrue(BASE_STRING_VALUE.compareTo(NULL_VALUE) > 0); | |
281 | } | |
282 | ||
283 | // ------------------------------------------------------------------------ | |
284 | // Comparisons of Null state values | |
285 | // ------------------------------------------------------------------------ | |
286 | ||
287 | /** | |
288 | * Compare Null with Integer state values | |
289 | */ | |
290 | @Test | |
291 | public void compareNullWithInt() { | |
292 | assertTrue(NULL_VALUE.compareTo(BASE_INT_VALUE) < 0); | |
293 | } | |
294 | ||
295 | /** | |
296 | * Compare Null with Long state values | |
297 | */ | |
298 | @Test | |
299 | public void compareNullWithLong() { | |
300 | assertTrue(NULL_VALUE.compareTo(BASE_LONG_VALUE) < 0); | |
301 | } | |
302 | ||
303 | /** | |
304 | * Compare Null with Double state values | |
305 | */ | |
306 | @Test | |
307 | public void compareNullWithDouble() { | |
308 | /* NullValue.unboxDouble returns NaN */ | |
309 | assertTrue(NULL_VALUE.compareTo(BASE_DOUBLE_VALUE) > 0); | |
310 | } | |
311 | ||
312 | /** | |
313 | * Compare Null with String state values | |
314 | */ | |
315 | @Test | |
316 | public void compareNullWithString() { | |
317 | assertTrue(NULL_VALUE.compareTo(BASE_STRING_VALUE) < 0); | |
318 | } | |
319 | ||
320 | /** | |
321 | * Compare Null state values together | |
322 | */ | |
323 | @Test | |
324 | public void compareNullWithNull() { | |
325 | assertTrue(NULL_VALUE.compareTo(NULL_VALUE) == 0); | |
326 | } | |
327 | ||
328 | } |