blob: 589224e431934c6d46ebba8bf16977ebe5ba70ff [file] [log] [blame]
Aart Bik6e74fa92016-01-25 16:51:32 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Alan Leung75b4e122017-09-07 15:20:26 -070017import java.lang.reflect.Method;
18
Aart Bik6e74fa92016-01-25 16:51:32 -080019public class Main {
20
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +010021 /// CHECK-START: void Main.$opt$noinline$testReplaceInputWithItself(int) builder (after)
Vladimir Markoc6b56272016-04-20 18:45:25 +010022 /// CHECK-DAG: <<ArgX:i\d+>> ParameterValue
Vladimir Markoc6b56272016-04-20 18:45:25 +010023 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0
Vladimir Marko5f846072020-04-09 13:20:11 +010024 /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<ArgX>>,<<Zero>>]
Vladimir Markoc6b56272016-04-20 18:45:25 +010025 /// CHECK-DAG: GreaterThanOrEqual [<<Cmp>>,<<Zero>>]
26
27 /// CHECK-START: void Main.$opt$noinline$testReplaceInputWithItself(int) instruction_simplifier (after)
28 /// CHECK-DAG: <<ArgX:i\d+>> ParameterValue
29 /// CHECK-DAG: <<Zero:i\d+>> IntConstant 0
30 /// CHECK-DAG: GreaterThanOrEqual [<<ArgX>>,<<Zero>>]
31
32 public static void $opt$noinline$testReplaceInputWithItself(int x) {
Vladimir Markoc6b56272016-04-20 18:45:25 +010033 // The instruction simplifier first replaces Integer.compare(x, 0) with Compare HIR
34 // and then merges the Compare into the GreaterThanOrEqual. This is a regression
35 // test that to check that it is allowed to replace the second input of the
36 // GreaterThanOrEqual, i.e. <<Zero>>, with the very same instruction.
37 if (Integer.compare(x, 0) < 0) {
38 System.out.println("OOOPS");
39 }
40 }
41
Roland Levillaina5c4a402016-03-15 15:02:50 +000042 /// CHECK-START: int Main.compareBooleans(boolean, boolean) select_generator (after)
43 /// CHECK-NOT: Phi
44
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070045 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier$after_bce (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000046 /// CHECK: <<ArgX:z\d+>> ParameterValue
47 /// CHECK: <<ArgY:z\d+>> ParameterValue
48 /// CHECK-DAG: <<Result:i\d+>> Compare [<<ArgX>>,<<ArgY>>]
49 /// CHECK-DAG: Return [<<Result>>]
50
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070051 /// CHECK-START: int Main.compareBooleans(boolean, boolean) instruction_simplifier$after_bce (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000052 /// CHECK-NOT: Select
53
54 private static int compareBooleans(boolean x, boolean y) {
55 return Integer.compare((x ? 1 : 0), (y ? 1 : 0));
56 }
57
Alan Leung75b4e122017-09-07 15:20:26 -070058 private static int compareBooleansSmali(boolean x, boolean y) throws Exception {
59 Class<?> c = Class.forName("Smali");
60 Method m = c.getMethod("compareBooleans", boolean.class, boolean.class);
61 return (Integer) m.invoke(null, x, y);
62 }
63
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +010064 /// CHECK-START: int Main.compareBytes(byte, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000065 /// CHECK-DAG: <<Result:i\d+>> Compare
66 /// CHECK-DAG: Return [<<Result>>]
67
Vladimir Marko5f846072020-04-09 13:20:11 +010068 /// CHECK-START: int Main.compareBytes(byte, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000069 /// CHECK-NOT: InvokeStaticOrDirect
70
71 private static int compareBytes(byte x, byte y) {
Aart Bik6e74fa92016-01-25 16:51:32 -080072 return Integer.compare(x, y);
73 }
74
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +010075 /// CHECK-START: int Main.compareShorts(short, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000076 /// CHECK-DAG: <<Result:i\d+>> Compare
77 /// CHECK-DAG: Return [<<Result>>]
78
Vladimir Marko5f846072020-04-09 13:20:11 +010079 /// CHECK-START: int Main.compareShorts(short, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000080 /// CHECK-NOT: InvokeStaticOrDirect
81
82 private static int compareShorts(short x, short y) {
83 return Integer.compare(x, y);
84 }
85
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +010086 /// CHECK-START: int Main.compareChars(char, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000087 /// CHECK-DAG: <<Result:i\d+>> Compare
88 /// CHECK-DAG: Return [<<Result>>]
89
Vladimir Marko5f846072020-04-09 13:20:11 +010090 /// CHECK-START: int Main.compareChars(char, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000091 /// CHECK-NOT: InvokeStaticOrDirect
92
93 private static int compareChars(char x, char y) {
94 return Integer.compare(x, y);
95 }
96
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +010097 /// CHECK-START: int Main.compareInts(int, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +000098 /// CHECK-DAG: <<Result:i\d+>> Compare
99 /// CHECK-DAG: Return [<<Result>>]
100
Vladimir Marko5f846072020-04-09 13:20:11 +0100101 /// CHECK-START: int Main.compareInts(int, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000102 /// CHECK-NOT: InvokeStaticOrDirect
103
104 private static int compareInts(int x, int y) {
105 return Integer.compare(x, y);
106 }
107
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100108 /// CHECK-START: int Main.compareLongs(long, long) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000109 /// CHECK-DAG: <<Result:i\d+>> Compare
110 /// CHECK-DAG: Return [<<Result>>]
111
Vladimir Marko5f846072020-04-09 13:20:11 +0100112 /// CHECK-START: int Main.compareLongs(long, long) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000113 /// CHECK-NOT: InvokeStaticOrDirect
114
115 private static int compareLongs(long x, long y) {
Aart Bik6e74fa92016-01-25 16:51:32 -0800116 return Long.compare(x, y);
117 }
118
Aart Bik6e74fa92016-01-25 16:51:32 -0800119
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100120 /// CHECK-START: int Main.compareByteShort(byte, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000121 /// CHECK-DAG: <<Result:i\d+>> Compare
122 /// CHECK-DAG: Return [<<Result>>]
123
Vladimir Marko5f846072020-04-09 13:20:11 +0100124 /// CHECK-START: int Main.compareByteShort(byte, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000125 /// CHECK-NOT: InvokeStaticOrDirect
126
127 public static int compareByteShort(byte x, short y) {
128 return Integer.compare(x, y);
129 }
130
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100131 /// CHECK-START: int Main.compareByteChar(byte, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000132 /// CHECK-DAG: <<Result:i\d+>> Compare
133 /// CHECK-DAG: Return [<<Result>>]
134
Vladimir Marko5f846072020-04-09 13:20:11 +0100135 /// CHECK-START: int Main.compareByteChar(byte, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000136 /// CHECK-NOT: InvokeStaticOrDirect
137
138 public static int compareByteChar(byte x, char y) {
139 return Integer.compare(x, y);
140 }
141
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100142 /// CHECK-START: int Main.compareByteInt(byte, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000143 /// CHECK-DAG: <<Result:i\d+>> Compare
144 /// CHECK-DAG: Return [<<Result>>]
145
Vladimir Marko5f846072020-04-09 13:20:11 +0100146 /// CHECK-START: int Main.compareByteInt(byte, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000147 /// CHECK-NOT: InvokeStaticOrDirect
148
149 public static int compareByteInt(byte x, int y) {
150 return Integer.compare(x, y);
151 }
152
153
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100154 /// CHECK-START: int Main.compareShortByte(short, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000155 /// CHECK-DAG: <<Result:i\d+>> Compare
156 /// CHECK-DAG: Return [<<Result>>]
157
Vladimir Marko5f846072020-04-09 13:20:11 +0100158 /// CHECK-START: int Main.compareShortByte(short, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000159 /// CHECK-NOT: InvokeStaticOrDirect
160
161 public static int compareShortByte(short x, byte y) {
162 return Integer.compare(x, y);
163 }
164
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100165 /// CHECK-START: int Main.compareShortChar(short, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000166 /// CHECK-DAG: <<Result:i\d+>> Compare
167 /// CHECK-DAG: Return [<<Result>>]
168
Vladimir Marko5f846072020-04-09 13:20:11 +0100169 /// CHECK-START: int Main.compareShortChar(short, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000170 /// CHECK-NOT: InvokeStaticOrDirect
171
172 public static int compareShortChar(short x, char y) {
173 return Integer.compare(x, y);
174 }
175
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100176 /// CHECK-START: int Main.compareShortInt(short, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000177 /// CHECK-DAG: <<Result:i\d+>> Compare
178 /// CHECK-DAG: Return [<<Result>>]
179
Vladimir Marko5f846072020-04-09 13:20:11 +0100180 /// CHECK-START: int Main.compareShortInt(short, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000181 /// CHECK-NOT: InvokeStaticOrDirect
182
183 public static int compareShortInt(short x, int y) {
184 return Integer.compare(x, y);
185 }
186
187
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100188 /// CHECK-START: int Main.compareCharByte(char, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000189 /// CHECK-DAG: <<Result:i\d+>> Compare
190 /// CHECK-DAG: Return [<<Result>>]
191
Vladimir Marko5f846072020-04-09 13:20:11 +0100192 /// CHECK-START: int Main.compareCharByte(char, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000193 /// CHECK-NOT: InvokeStaticOrDirect
194
195 public static int compareCharByte(char x, byte y) {
196 return Integer.compare(x, y);
197 }
198
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100199 /// CHECK-START: int Main.compareCharShort(char, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000200 /// CHECK-DAG: <<Result:i\d+>> Compare
201 /// CHECK-DAG: Return [<<Result>>]
202
Vladimir Marko5f846072020-04-09 13:20:11 +0100203 /// CHECK-START: int Main.compareCharShort(char, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000204 /// CHECK-NOT: InvokeStaticOrDirect
205
206 public static int compareCharShort(char x, short y) {
207 return Integer.compare(x, y);
208 }
209
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100210 /// CHECK-START: int Main.compareCharInt(char, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000211 /// CHECK-DAG: <<Result:i\d+>> Compare
212 /// CHECK-DAG: Return [<<Result>>]
213
Vladimir Marko5f846072020-04-09 13:20:11 +0100214 /// CHECK-START: int Main.compareCharInt(char, int) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000215 /// CHECK-NOT: InvokeStaticOrDirect
216
217 public static int compareCharInt(char x, int y) {
218 return Integer.compare(x, y);
219 }
220
221
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100222 /// CHECK-START: int Main.compareIntByte(int, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000223 /// CHECK-DAG: <<Result:i\d+>> Compare
224 /// CHECK-DAG: Return [<<Result>>]
225
Vladimir Marko5f846072020-04-09 13:20:11 +0100226 /// CHECK-START: int Main.compareIntByte(int, byte) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000227 /// CHECK-NOT: InvokeStaticOrDirect
228
229 public static int compareIntByte(int x, byte y) {
230 return Integer.compare(x, y);
231 }
232
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100233 /// CHECK-START: int Main.compareIntShort(int, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000234 /// CHECK-DAG: <<Result:i\d+>> Compare
235 /// CHECK-DAG: Return [<<Result>>]
236
Vladimir Marko5f846072020-04-09 13:20:11 +0100237 /// CHECK-START: int Main.compareIntShort(int, short) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000238 /// CHECK-NOT: InvokeStaticOrDirect
239
240 public static int compareIntShort(int x, short y) {
241 return Integer.compare(x, y);
242 }
243
Nicolas Geoffray76d4bb0f32018-09-21 12:58:45 +0100244 /// CHECK-START: int Main.compareIntChar(int, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000245 /// CHECK-DAG: <<Result:i\d+>> Compare
246 /// CHECK-DAG: Return [<<Result>>]
247
Vladimir Marko5f846072020-04-09 13:20:11 +0100248 /// CHECK-START: int Main.compareIntChar(int, char) builder (after)
Roland Levillaina5c4a402016-03-15 15:02:50 +0000249 /// CHECK-NOT: InvokeStaticOrDirect
250
251 public static int compareIntChar(int x, char y) {
252 return Integer.compare(x, y);
253 }
254
255
Alan Leung75b4e122017-09-07 15:20:26 -0700256 public static void testCompareBooleans() throws Exception {
Roland Levillaina5c4a402016-03-15 15:02:50 +0000257 expectEquals(-1, compareBooleans(false, true));
Alan Leung75b4e122017-09-07 15:20:26 -0700258 expectEquals(-1, compareBooleansSmali(false, true));
Roland Levillaina5c4a402016-03-15 15:02:50 +0000259
260 expectEquals(0, compareBooleans(false, false));
261 expectEquals(0, compareBooleans(true, true));
Alan Leung75b4e122017-09-07 15:20:26 -0700262 expectEquals(0, compareBooleansSmali(false, false));
263 expectEquals(0, compareBooleansSmali(true, true));
Roland Levillaina5c4a402016-03-15 15:02:50 +0000264
265 expectEquals(1, compareBooleans(true, false));
Alan Leung75b4e122017-09-07 15:20:26 -0700266 expectEquals(1, compareBooleansSmali(true, false));
Roland Levillaina5c4a402016-03-15 15:02:50 +0000267 }
268
269 public static void testCompareBytes() {
270 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1)));
271 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)-1));
272 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)0));
273 expectEquals(-1, compareBytes(Byte.MIN_VALUE, (byte)1));
274 expectEquals(-1, compareBytes(Byte.MIN_VALUE, Byte.MAX_VALUE));
275 expectEquals(-1, compareBytes((byte)-1, (byte)0));
276 expectEquals(-1, compareBytes((byte)-1, (byte)1));
277 expectEquals(-1, compareBytes((byte)0, (byte)1));
278
279 expectEquals(0, compareBytes(Byte.MIN_VALUE, Byte.MIN_VALUE));
280 expectEquals(0, compareBytes((byte)-1, (byte)-1));
281 expectEquals(0, compareBytes((byte)0, (byte)0));
282 expectEquals(0, compareBytes((byte)1, (byte)1));
283 expectEquals(0, compareBytes(Byte.MAX_VALUE, Byte.MAX_VALUE));
284
285 expectEquals(1, compareBytes((byte)0, (byte)-1));
286 expectEquals(1, compareBytes((byte)1, (byte)-1));
287 expectEquals(1, compareBytes((byte)1, (byte)0));
288 expectEquals(1, compareBytes(Byte.MAX_VALUE, Byte.MIN_VALUE));
289 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)-1));
290 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)0));
291 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)1));
292 expectEquals(1, compareBytes(Byte.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1)));
293
294 for (byte i = -11; i <= 11; i++) {
295 for (byte j = -11; j <= 11; j++) {
296 int expected = 0;
297 if (i < j) expected = -1;
298 else if (i > j) expected = 1;
299 expectEquals(expected, compareBytes(i, j));
300 }
301 }
302 }
303
304 public static void testCompareShorts() {
305 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)(Short.MIN_VALUE + 1)));
306 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)-1));
307 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)0));
308 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)1));
309 expectEquals(-1, compareShorts(Short.MIN_VALUE, (short)Short.MAX_VALUE));
310 expectEquals(-1, compareShorts((short)-1, (short)0));
311 expectEquals(-1, compareShorts((short)-1, (short)1));
312 expectEquals(-1, compareShorts((short)0, (short)1));
313
314 expectEquals(0, compareShorts(Short.MIN_VALUE, Short.MIN_VALUE));
315 expectEquals(0, compareShorts((short)-1, (short)-1));
316 expectEquals(0, compareShorts((short)0, (short)0));
317 expectEquals(0, compareShorts((short)1, (short)1));
318 expectEquals(0, compareShorts(Short.MAX_VALUE, Short.MAX_VALUE));
319
320 expectEquals(1, compareShorts((short)0, (short)-1));
321 expectEquals(1, compareShorts((short)1, (short)-1));
322 expectEquals(1, compareShorts((short)1, (short)0));
323 expectEquals(1, compareShorts(Short.MAX_VALUE, Short.MIN_VALUE));
324 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)-1));
325 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)0));
326 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)1));
327 expectEquals(1, compareShorts(Short.MAX_VALUE, (short)(Short.MAX_VALUE - 1)));
328
329 for (short i = -11; i <= 11; i++) {
330 for (short j = -11; j <= 11; j++) {
331 int expected = 0;
332 if (i < j) expected = -1;
333 else if (i > j) expected = 1;
334 expectEquals(expected, compareShorts(i, j));
335 }
336 }
337 }
338
339 public static void testCompareChars() {
340 expectEquals(-1, compareChars((char)0, Character.MAX_VALUE));
341 expectEquals(-1, compareChars((char)0, (char)1));
342
343 expectEquals(0, compareChars((char)0, (char)0));
344 expectEquals(0, compareChars((char)1, (char)1));
345 expectEquals(0, compareChars(Character.MAX_VALUE, Character.MAX_VALUE));
346
347 expectEquals(1, compareChars((char)1, (char)0));
348 expectEquals(1, compareChars(Character.MAX_VALUE, (char)0));
349 expectEquals(1, compareChars(Character.MAX_VALUE, (char)1));
350 expectEquals(1, compareChars(Character.MAX_VALUE, (char)(Character.MAX_VALUE - 1)));
351
352 for (char i = 0; i <= 11; i++) {
353 for (char j = 0; j <= 11; j++) {
354 int expected = 0;
355 if (i < j) expected = -1;
356 else if (i > j) expected = 1;
357 expectEquals(expected, compareChars(i, j));
358 }
359 }
360 }
361
362 public static void testCompareInts() {
363 expectEquals(-1, compareInts(Integer.MIN_VALUE, Integer.MIN_VALUE + 1));
364 expectEquals(-1, compareInts(Integer.MIN_VALUE, -1));
365 expectEquals(-1, compareInts(Integer.MIN_VALUE, 0));
366 expectEquals(-1, compareInts(Integer.MIN_VALUE, 1));
367 expectEquals(-1, compareInts(Integer.MIN_VALUE, Integer.MAX_VALUE));
368 expectEquals(-1, compareInts(-1, 0));
369 expectEquals(-1, compareInts(-1, 1));
370 expectEquals(-1, compareInts(0, 1));
371
372 expectEquals(0, compareInts(Integer.MIN_VALUE, Integer.MIN_VALUE));
373 expectEquals(0, compareInts(-1, -1));
374 expectEquals(0, compareInts(0, 0));
375 expectEquals(0, compareInts(1, 1));
376 expectEquals(0, compareInts(Integer.MAX_VALUE, Integer.MAX_VALUE));
377
378 expectEquals(1, compareInts(0, -1));
379 expectEquals(1, compareInts(1, -1));
380 expectEquals(1, compareInts(1, 0));
381 expectEquals(1, compareInts(Integer.MAX_VALUE, Integer.MIN_VALUE));
382 expectEquals(1, compareInts(Integer.MAX_VALUE, -1));
383 expectEquals(1, compareInts(Integer.MAX_VALUE, 0));
384 expectEquals(1, compareInts(Integer.MAX_VALUE, 1));
385 expectEquals(1, compareInts(Integer.MAX_VALUE, Integer.MAX_VALUE - 1));
Aart Bik6e74fa92016-01-25 16:51:32 -0800386
387 for (int i = -11; i <= 11; i++) {
388 for (int j = -11; j <= 11; j++) {
389 int expected = 0;
390 if (i < j) expected = -1;
391 else if (i > j) expected = 1;
Roland Levillaina5c4a402016-03-15 15:02:50 +0000392 expectEquals(expected, compareInts(i, j));
Aart Bik6e74fa92016-01-25 16:51:32 -0800393 }
394 }
Roland Levillaina5c4a402016-03-15 15:02:50 +0000395 }
Aart Bik6e74fa92016-01-25 16:51:32 -0800396
Roland Levillaina5c4a402016-03-15 15:02:50 +0000397 public static void testCompareLongs() {
398 expectEquals(-1, compareLongs(Long.MIN_VALUE, Long.MIN_VALUE + 1L));
399 expectEquals(-1, compareLongs(Long.MIN_VALUE, -1L));
400 expectEquals(-1, compareLongs(Long.MIN_VALUE, 0L));
401 expectEquals(-1, compareLongs(Long.MIN_VALUE, 1L));
402 expectEquals(-1, compareLongs(Long.MIN_VALUE, Long.MAX_VALUE));
403 expectEquals(-1, compareLongs(-1L, 0L));
404 expectEquals(-1, compareLongs(-1L, 1L));
405 expectEquals(-1, compareLongs(0L, 1L));
Aart Bik6e74fa92016-01-25 16:51:32 -0800406
Roland Levillaina5c4a402016-03-15 15:02:50 +0000407 expectEquals(0, compareLongs(Long.MIN_VALUE, Long.MIN_VALUE));
408 expectEquals(0, compareLongs(-1L, -1L));
409 expectEquals(0, compareLongs(0L, 0L));
410 expectEquals(0, compareLongs(1L, 1L));
411 expectEquals(0, compareLongs(Long.MAX_VALUE, Long.MAX_VALUE));
Aart Bik6e74fa92016-01-25 16:51:32 -0800412
Roland Levillaina5c4a402016-03-15 15:02:50 +0000413 expectEquals(1, compareLongs(0L, -1L));
414 expectEquals(1, compareLongs(1L, -1L));
415 expectEquals(1, compareLongs(1L, 0L));
416 expectEquals(1, compareLongs(Long.MAX_VALUE, Long.MIN_VALUE));
417 expectEquals(1, compareLongs(Long.MAX_VALUE, -1L));
418 expectEquals(1, compareLongs(Long.MAX_VALUE, 0L));
419 expectEquals(1, compareLongs(Long.MAX_VALUE, 1L));
420 expectEquals(1, compareLongs(Long.MAX_VALUE, Long.MAX_VALUE - 1L));
Aart Bik6e74fa92016-01-25 16:51:32 -0800421
Roland Levillaina5c4a402016-03-15 15:02:50 +0000422 expectEquals(-1, compareLongs(0x111111117FFFFFFFL, 0x11111111FFFFFFFFL));
423 expectEquals(0, compareLongs(0x111111117FFFFFFFL, 0x111111117FFFFFFFL));
424 expectEquals(1, compareLongs(0x11111111FFFFFFFFL, 0x111111117FFFFFFFL));
Aart Bika19616e2016-02-01 18:57:58 -0800425
Aart Bik6e74fa92016-01-25 16:51:32 -0800426 for (long i = -11L; i <= 11L; i++) {
427 for (long j = -11L; j <= 11L; j++) {
428 int expected = 0;
429 if (i < j) expected = -1;
430 else if (i > j) expected = 1;
Roland Levillaina5c4a402016-03-15 15:02:50 +0000431 expectEquals(expected, compareLongs(i, j));
Aart Bik6e74fa92016-01-25 16:51:32 -0800432 }
433 }
434
Aart Bika19616e2016-02-01 18:57:58 -0800435 for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 11L; i++) {
Roland Levillaina5c4a402016-03-15 15:02:50 +0000436 expectEquals(-1, compareLongs(i, 0));
Aart Bika19616e2016-02-01 18:57:58 -0800437 }
438
439 for (long i = Long.MAX_VALUE; i >= Long.MAX_VALUE - 11L; i--) {
Roland Levillaina5c4a402016-03-15 15:02:50 +0000440 expectEquals(1, compareLongs(i, 0));
Aart Bika19616e2016-02-01 18:57:58 -0800441 }
Roland Levillaina5c4a402016-03-15 15:02:50 +0000442 }
443
444
445 public static void testCompareByteShort() {
446 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)-1));
447 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)0));
448 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, (short)1));
449 expectEquals(-1, compareByteShort(Byte.MIN_VALUE, Short.MAX_VALUE));
450 expectEquals(-1, compareByteShort((byte)-1, (short)0));
451 expectEquals(-1, compareByteShort((byte)-1, (short)1));
452 expectEquals(-1, compareByteShort((byte)0, (short)1));
453 expectEquals(-1, compareByteShort(Byte.MAX_VALUE, (short)(Short.MAX_VALUE - 1)));
454 expectEquals(-1, compareByteShort(Byte.MAX_VALUE, Short.MAX_VALUE));
455
456 expectEquals(0, compareByteShort((byte)-1, (short)-1));
457 expectEquals(0, compareByteShort((byte)0, (short)0));
458 expectEquals(0, compareByteShort((byte)1, (short)1));
459
460 expectEquals(1, compareByteShort(Byte.MIN_VALUE, Short.MIN_VALUE));
461 expectEquals(1, compareByteShort(Byte.MIN_VALUE, (short)(Short.MIN_VALUE + 1)));
462 expectEquals(1, compareByteShort((byte)0, (short)-1));
463 expectEquals(1, compareByteShort((byte)1, (short)-1));
464 expectEquals(1, compareByteShort((byte)1, (short)0));
465 expectEquals(1, compareByteShort(Byte.MAX_VALUE, Short.MIN_VALUE));
466 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)-1));
467 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)0));
468 expectEquals(1, compareByteShort(Byte.MAX_VALUE, (short)1));
469
470 for (byte i = -11; i <= 11; i++) {
471 for (short j = -11; j <= 11; j++) {
472 int expected = 0;
473 if (i < j) expected = -1;
474 else if (i > j) expected = 1;
475 expectEquals(expected, compareByteShort(i, j));
476 }
477 }
478 }
479
480 public static void testCompareByteChar() {
481 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, (char)0));
482 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, (char)1));
483 expectEquals(-1, compareByteChar(Byte.MIN_VALUE, Character.MAX_VALUE));
484 expectEquals(-1, compareByteChar((byte)-1, (char)0));
485 expectEquals(-1, compareByteChar((byte)-1, (char)1));
486 expectEquals(-1, compareByteChar((byte)0, (char)1));
487 expectEquals(-1, compareByteChar(Byte.MAX_VALUE, (char)(Character.MAX_VALUE - 1)));
488 expectEquals(-1, compareByteChar(Byte.MAX_VALUE, Character.MAX_VALUE));
489
490 expectEquals(0, compareByteChar((byte)0, (char)0));
491 expectEquals(0, compareByteChar((byte)1, (char)1));
492
493 expectEquals(1, compareByteChar((byte)1, (char)0));
494 expectEquals(1, compareByteChar(Byte.MAX_VALUE, (char)0));
495 expectEquals(1, compareByteChar(Byte.MAX_VALUE, (char)1));
496
497 for (byte i = -11; i <= 11; i++) {
498 for (char j = 0; j <= 11; j++) {
499 int expected = 0;
500 if (i < j) expected = -1;
501 else if (i > j) expected = 1;
502 expectEquals(expected, compareByteChar(i, j));
503 }
504 }
505 }
506
507 public static void testCompareByteInt() {
508 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, -1));
509 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, 0));
510 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, 1));
511 expectEquals(-1, compareByteInt(Byte.MIN_VALUE, Integer.MAX_VALUE));
512 expectEquals(-1, compareByteInt((byte)-1, 0));
513 expectEquals(-1, compareByteInt((byte)-1, 1));
514 expectEquals(-1, compareByteInt((byte)0, 1));
515 expectEquals(-1, compareByteInt(Byte.MAX_VALUE, Integer.MAX_VALUE - 1));
516 expectEquals(-1, compareByteInt(Byte.MAX_VALUE, Integer.MAX_VALUE));
517
518 expectEquals(0, compareByteInt((byte)-1, -1));
519 expectEquals(0, compareByteInt((byte)0, 0));
520 expectEquals(0, compareByteInt((byte)1, 1));
521
522 expectEquals(1, compareByteInt(Byte.MIN_VALUE, Integer.MIN_VALUE));
523 expectEquals(1, compareByteInt(Byte.MIN_VALUE, Integer.MIN_VALUE + 1));
524 expectEquals(1, compareByteInt((byte)0, -1));
525 expectEquals(1, compareByteInt((byte)1, -1));
526 expectEquals(1, compareByteInt((byte)1, 0));
527 expectEquals(1, compareByteInt(Byte.MAX_VALUE, Integer.MIN_VALUE));
528 expectEquals(1, compareByteInt(Byte.MAX_VALUE, -1));
529 expectEquals(1, compareByteInt(Byte.MAX_VALUE, 0));
530 expectEquals(1, compareByteInt(Byte.MAX_VALUE, 1));
531
532 for (byte i = -11; i <= 11; i++) {
533 for (int j = -11; j <= 11; j++) {
534 int expected = 0;
535 if (i < j) expected = -1;
536 else if (i > j) expected = 1;
537 expectEquals(expected, compareByteInt(i, j));
538 }
539 }
540 }
541
542
543 public static void testCompareShortByte() {
544 expectEquals(-1, compareShortByte(Short.MIN_VALUE, Byte.MIN_VALUE));
545 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1)));
546 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)-1));
547 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)0));
548 expectEquals(-1, compareShortByte(Short.MIN_VALUE, (byte)1));
549 expectEquals(-1, compareShortByte(Short.MIN_VALUE, Byte.MAX_VALUE));
550 expectEquals(-1, compareShortByte((short)-1, (byte)0));
551 expectEquals(-1, compareShortByte((short)-1, (byte)1));
552 expectEquals(-1, compareShortByte((short)0, (byte)1));
553
554 expectEquals(0, compareShortByte((short)-1, (byte)-1));
555 expectEquals(0, compareShortByte((short)0, (byte)0));
556 expectEquals(0, compareShortByte((short)1, (byte)1));
557
558 expectEquals(1, compareShortByte((short)0, (byte)-1));
559 expectEquals(1, compareShortByte((short)1, (byte)-1));
560 expectEquals(1, compareShortByte((short)1, (byte)0));
561 expectEquals(1, compareShortByte(Short.MAX_VALUE, Byte.MIN_VALUE));
562 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)-1));
563 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)0));
564 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)1));
565 expectEquals(1, compareShortByte(Short.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1)));
566 expectEquals(1, compareShortByte(Short.MAX_VALUE, Byte.MAX_VALUE));
567
568 for (short i = -11; i <= 11; i++) {
569 for (byte j = -11; j <= 11; j++) {
570 int expected = 0;
571 if (i < j) expected = -1;
572 else if (i > j) expected = 1;
573 expectEquals(expected, compareShortByte(i, j));
574 }
575 }
576 }
577
578 public static void testCompareShortChar() {
579 expectEquals(-1, compareShortChar(Short.MIN_VALUE, (char)0));
580 expectEquals(-1, compareShortChar(Short.MIN_VALUE, (char)1));
581 expectEquals(-1, compareShortChar(Short.MIN_VALUE, Character.MAX_VALUE));
582 expectEquals(-1, compareShortChar((short)-1, (char)0));
583 expectEquals(-1, compareShortChar((short)-1, (char)1));
584 expectEquals(-1, compareShortChar((short)0, (char)1));
585 expectEquals(-1, compareShortChar(Short.MAX_VALUE, (char)(Character.MAX_VALUE - 1)));
586 expectEquals(-1, compareShortChar(Short.MAX_VALUE, Character.MAX_VALUE));
587
588 expectEquals(0, compareShortChar((short)0, (char)0));
589 expectEquals(0, compareShortChar((short)1, (char)1));
590
591 expectEquals(1, compareShortChar((short)1, (char)0));
592 expectEquals(1, compareShortChar(Short.MAX_VALUE, (char)0));
593 expectEquals(1, compareShortChar(Short.MAX_VALUE, (char)1));
594
595 for (short i = -11; i <= 11; i++) {
596 for (char j = 0; j <= 11; j++) {
597 int expected = 0;
598 if (i < j) expected = -1;
599 else if (i > j) expected = 1;
600 expectEquals(expected, compareShortChar(i, j));
601 }
602 }
603 }
604
605 public static void testCompareShortInt() {
606 expectEquals(-1, compareShortInt(Short.MIN_VALUE, -1));
607 expectEquals(-1, compareShortInt(Short.MIN_VALUE, 0));
608 expectEquals(-1, compareShortInt(Short.MIN_VALUE, 1));
609 expectEquals(-1, compareShortInt(Short.MIN_VALUE, Integer.MAX_VALUE));
610 expectEquals(-1, compareShortInt((short)-1, 0));
611 expectEquals(-1, compareShortInt((short)-1, 1));
612 expectEquals(-1, compareShortInt((short)0, 1));
613 expectEquals(-1, compareShortInt(Short.MAX_VALUE, Integer.MAX_VALUE - 1));
614 expectEquals(-1, compareShortInt(Short.MAX_VALUE, Integer.MAX_VALUE));
615
616 expectEquals(0, compareShortInt((short)-1, -1));
617 expectEquals(0, compareShortInt((short)0, 0));
618 expectEquals(0, compareShortInt((short)1, 1));
619
620 expectEquals(1, compareShortInt(Short.MIN_VALUE, Integer.MIN_VALUE));
621 expectEquals(1, compareShortInt(Short.MIN_VALUE, Integer.MIN_VALUE + 1));
622 expectEquals(1, compareShortInt((short)0, -1));
623 expectEquals(1, compareShortInt((short)1, -1));
624 expectEquals(1, compareShortInt((short)1, 0));
625 expectEquals(1, compareShortInt(Short.MAX_VALUE, Integer.MIN_VALUE));
626 expectEquals(1, compareShortInt(Short.MAX_VALUE, -1));
627 expectEquals(1, compareShortInt(Short.MAX_VALUE, 0));
628 expectEquals(1, compareShortInt(Short.MAX_VALUE, 1));
629
630 for (short i = -11; i <= 11; i++) {
631 for (int j = -11; j <= 11; j++) {
632 int expected = 0;
633 if (i < j) expected = -1;
634 else if (i > j) expected = 1;
635 expectEquals(expected, compareShortInt(i, j));
636 }
637 }
638 }
639
640
641 public static void testCompareCharByte() {
642 expectEquals(-1, compareCharByte((char)0, (byte)1));
643 expectEquals(-1, compareCharByte((char)0, Byte.MAX_VALUE));
644
645 expectEquals(0, compareCharByte((char)0, (byte)0));
646 expectEquals(0, compareCharByte((char)1, (byte)1));
647
648 expectEquals(1, compareCharByte((char)0, Byte.MIN_VALUE));
649 expectEquals(1, compareCharByte((char)0, (byte)(Byte.MIN_VALUE + 1)));
650 expectEquals(1, compareCharByte((char)0, (byte)-1));
651 expectEquals(1, compareCharByte((char)1, (byte)-1));
652 expectEquals(1, compareCharByte((char)1, (byte)0));
653 expectEquals(1, compareCharByte(Character.MAX_VALUE, Byte.MIN_VALUE));
654 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)-1));
655 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)0));
656 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)1));
657 expectEquals(1, compareCharByte(Character.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1)));
658 expectEquals(1, compareCharByte(Character.MAX_VALUE, Byte.MAX_VALUE));
659
660 for (char i = 0; i <= 11; i++) {
661 for (byte j = -11; j <= 11; j++) {
662 int expected = 0;
663 if (i < j) expected = -1;
664 else if (i > j) expected = 1;
665 expectEquals(expected, compareCharByte(i, j));
666 }
667 }
668 }
669
670 public static void testCompareCharShort() {
671 expectEquals(-1, compareCharShort((char)0, (short)1));
672 expectEquals(-1, compareCharShort((char)0, Short.MAX_VALUE));
673
674 expectEquals(0, compareCharShort((char)0, (short)0));
675 expectEquals(0, compareCharShort((char)1, (short)1));
676
677 expectEquals(1, compareCharShort((char)0, Short.MIN_VALUE));
678 expectEquals(1, compareCharShort((char)0, (short)(Short.MIN_VALUE + 1)));
679 expectEquals(1, compareCharShort((char)0, (short)-1));
680 expectEquals(1, compareCharShort((char)1, (short)-1));
681 expectEquals(1, compareCharShort((char)1, (short)0));
682 expectEquals(1, compareCharShort(Character.MAX_VALUE, Short.MIN_VALUE));
683 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)-1));
684 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)0));
685 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)1));
686 expectEquals(1, compareCharShort(Character.MAX_VALUE, (short)(Short.MAX_VALUE - 1)));
687 expectEquals(1, compareCharShort(Character.MAX_VALUE, Short.MAX_VALUE));
688
689 for (char i = 0; i <= 11; i++) {
690 for (short j = -11; j <= 11; j++) {
691 int expected = 0;
692 if (i < j) expected = -1;
693 else if (i > j) expected = 1;
694 expectEquals(expected, compareCharShort(i, j));
695 }
696 }
697 }
698
699 public static void testCompareCharInt() {
700 expectEquals(-1, compareCharInt((char)0, 1));
701 expectEquals(-1, compareCharInt((char)0, Integer.MAX_VALUE));
702 expectEquals(-1, compareCharInt(Character.MAX_VALUE, Integer.MAX_VALUE - 1));
703 expectEquals(-1, compareCharInt(Character.MAX_VALUE, Integer.MAX_VALUE));
704
705 expectEquals(0, compareCharInt((char)0, 0));
706 expectEquals(0, compareCharInt((char)1, 1));
707
708 expectEquals(1, compareCharInt((char)0, Integer.MIN_VALUE));
709 expectEquals(1, compareCharInt((char)0, Integer.MIN_VALUE + 1));
710 expectEquals(1, compareCharInt((char)0, -1));
711 expectEquals(1, compareCharInt((char)1, -1));
712 expectEquals(1, compareCharInt((char)1, 0));
713 expectEquals(1, compareCharInt(Character.MAX_VALUE, Integer.MIN_VALUE));
714 expectEquals(1, compareCharInt(Character.MAX_VALUE, -1));
715 expectEquals(1, compareCharInt(Character.MAX_VALUE, 0));
716 expectEquals(1, compareCharInt(Character.MAX_VALUE, 1));
717
718 for (char i = 0; i <= 11; i++) {
719 for (int j = -11; j <= 11; j++) {
720 int expected = 0;
721 if (i < j) expected = -1;
722 else if (i > j) expected = 1;
723 expectEquals(expected, compareCharInt(i, j));
724 }
725 }
726 }
727
728
729 public static void testCompareIntByte() {
730 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, Byte.MIN_VALUE));
731 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)(Byte.MIN_VALUE + 1)));
732 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)-1));
733 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)0));
734 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, (byte)1));
735 expectEquals(-1, compareIntByte(Integer.MIN_VALUE, Byte.MAX_VALUE));
736 expectEquals(-1, compareIntByte(-1, (byte)0));
737 expectEquals(-1, compareIntByte(-1, (byte)1));
738 expectEquals(-1, compareIntByte(0, (byte)1));
739
740 expectEquals(0, compareIntByte(-1, (byte)-1));
741 expectEquals(0, compareIntByte(0, (byte)0));
742 expectEquals(0, compareIntByte(1, (byte)1));
743
744 expectEquals(1, compareIntByte(0, (byte)-1));
745 expectEquals(1, compareIntByte(1, (byte)-1));
746 expectEquals(1, compareIntByte(1, (byte)0));
747 expectEquals(1, compareIntByte(Integer.MAX_VALUE, Byte.MIN_VALUE));
748 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)-1));
749 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)0));
750 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)1));
751 expectEquals(1, compareIntByte(Integer.MAX_VALUE, (byte)(Byte.MAX_VALUE - 1)));
752 expectEquals(1, compareIntByte(Integer.MAX_VALUE, Byte.MAX_VALUE));
753
754 for (int i = -11; i <= 11; i++) {
755 for (byte j = -11; j <= 11; j++) {
756 int expected = 0;
757 if (i < j) expected = -1;
758 else if (i > j) expected = 1;
759 expectEquals(expected, compareIntByte(i, j));
760 }
761 }
762 }
763
764 public static void testCompareIntShort() {
765 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, Short.MIN_VALUE));
766 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)(Short.MIN_VALUE + 1)));
767 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)-1));
768 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)0));
769 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, (short)1));
770 expectEquals(-1, compareIntShort(Integer.MIN_VALUE, Short.MAX_VALUE));
771 expectEquals(-1, compareIntShort(-1, (short)0));
772 expectEquals(-1, compareIntShort(-1, (short)1));
773 expectEquals(-1, compareIntShort(0, (short)1));
774
775 expectEquals(0, compareIntShort(-1, (short)-1));
776 expectEquals(0, compareIntShort(0, (short)0));
777 expectEquals(0, compareIntShort(1, (short)1));
778
779 expectEquals(1, compareIntShort(0, (short)-1));
780 expectEquals(1, compareIntShort(1, (short)-1));
781 expectEquals(1, compareIntShort(1, (short)0));
782 expectEquals(1, compareIntShort(Integer.MAX_VALUE, Short.MIN_VALUE));
783 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)-1));
784 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)0));
785 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)1));
786 expectEquals(1, compareIntShort(Integer.MAX_VALUE, (short)(Short.MAX_VALUE - 1)));
787 expectEquals(1, compareIntShort(Integer.MAX_VALUE, Short.MAX_VALUE));
788
789 for (int i = -11; i <= 11; i++) {
790 for (short j = -11; j <= 11; j++) {
791 int expected = 0;
792 if (i < j) expected = -1;
793 else if (i > j) expected = 1;
794 expectEquals(expected, compareIntShort(i, j));
795 }
796 }
797 }
798
799 public static void testCompareIntChar() {
800 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, (char)0));
801 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, (char)1));
802 expectEquals(-1, compareIntChar(Integer.MIN_VALUE, Character.MAX_VALUE));
803 expectEquals(-1, compareIntChar(-1, (char)0));
804 expectEquals(-1, compareIntChar(-1, (char)1));
805 expectEquals(-1, compareIntChar(0, (char)1));
806
807 expectEquals(0, compareIntChar(0, (char)0));
808 expectEquals(0, compareIntChar(1, (char)1));
809
810 expectEquals(1, compareIntChar(1, (char)0));
811 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)0));
812 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)1));
813 expectEquals(1, compareIntChar(Integer.MAX_VALUE, (char)(Character.MAX_VALUE - 1)));
814 expectEquals(1, compareIntChar(Integer.MAX_VALUE, Character.MAX_VALUE));
815
816 for (int i = -11; i <= 11; i++) {
817 for (char j = 0; j <= 11; j++) {
818 int expected = 0;
819 if (i < j) expected = -1;
820 else if (i > j) expected = 1;
821 expectEquals(expected, compareIntChar(i, j));
822 }
823 }
824 }
825
826
Alan Leung75b4e122017-09-07 15:20:26 -0700827 public static void main(String args[]) throws Exception {
Vladimir Markoc6b56272016-04-20 18:45:25 +0100828 $opt$noinline$testReplaceInputWithItself(42);
829
Roland Levillaina5c4a402016-03-15 15:02:50 +0000830 testCompareBooleans();
831 testCompareBytes();
832 testCompareShorts();
833 testCompareChars();
834 testCompareInts();
835 testCompareLongs();
836
837 testCompareByteShort();
838 testCompareByteChar();
839 testCompareByteInt();
840
841 testCompareShortByte();
842 testCompareShortChar();
843 testCompareShortInt();
844
845 testCompareCharByte();
846 testCompareCharShort();
847 testCompareCharInt();
848
849 testCompareIntByte();
850 testCompareIntShort();
851 testCompareIntChar();
Aart Bika19616e2016-02-01 18:57:58 -0800852
Aart Bik6e74fa92016-01-25 16:51:32 -0800853 System.out.println("passed");
854 }
855
856 private static void expectEquals(int expected, int result) {
857 if (expected != result) {
858 throw new Error("Expected: " + expected + ", found: " + result);
859 }
860 }
861}