blob: 3b11879e080158aeebcb496ebb983f6dce69399f [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
2 * Copyright (C) 2007 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
jeffhao5d1ac922011-09-29 17:41:15 -070017import junit.framework.Assert;
18
19public class Main {
Elliott Hughes28c384b2012-06-15 16:46:25 -070020 public static void main(String args[]) {
21 test_Double_doubleToRawLongBits();
22 test_Double_longBitsToDouble();
23 test_Float_floatToRawIntBits();
24 test_Float_intBitsToFloat();
25 test_Math_abs_I();
26 test_Math_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010027 test_Math_min_I();
28 test_Math_max_I();
29 test_Math_min_J();
30 test_Math_max_J();
31 test_Math_min_F();
32 test_Math_max_F();
33 test_Math_min_D();
34 test_Math_max_D();
35 test_Integer_reverse();
36 test_Long_reverse();
Sebastien Hertzbf1442d2013-03-05 15:12:40 +010037 test_StrictMath_abs_I();
38 test_StrictMath_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010039 test_StrictMath_min_I();
40 test_StrictMath_max_I();
41 test_StrictMath_min_J();
42 test_StrictMath_max_J();
43 test_StrictMath_min_F();
44 test_StrictMath_max_F();
45 test_StrictMath_min_D();
46 test_StrictMath_max_D();
Elliott Hughes28c384b2012-06-15 16:46:25 -070047 test_String_charAt();
48 test_String_compareTo();
49 test_String_indexOf();
50 test_String_isEmpty();
51 test_String_length();
Andreas Gampe7a949612014-07-08 11:03:59 -070052 test_Thread_currentThread();
Elliott Hughes28c384b2012-06-15 16:46:25 -070053 }
54
Serban Constantinescu23abec92014-07-02 16:13:38 +010055 /*
56 * Determine if two floating point numbers are approximately equal.
57 *
58 * (Assumes that floating point is generally working, so we can't use
59 * this for the first set of tests.)
60 */
61 static boolean approxEqual(float a, float b, float maxDelta) {
62 if (a > b)
63 return (a - b) < maxDelta;
64 else
65 return (b - a) < maxDelta;
66 }
67 static boolean approxEqual(double a, double b, double maxDelta) {
68 if (a > b)
69 return (a - b) < maxDelta;
70 else
71 return (b - a) < maxDelta;
72 }
73
Andreas Gampe7a949612014-07-08 11:03:59 -070074 /**
75 * Will test inlining Thread.currentThread().
76 */
77 public static void test_Thread_currentThread() {
78 // 1. Do not use result.
79 Thread.currentThread();
80
81 // 2. Result should not be null.
82 Assert.assertNotNull(Thread.currentThread());
83 }
84
Elliott Hughes28c384b2012-06-15 16:46:25 -070085 public static void test_String_length() {
86 String str0 = "";
87 String str1 = "x";
88 String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
89
90 Assert.assertEquals(str0.length(), 0);
91 Assert.assertEquals(str1.length(), 1);
92 Assert.assertEquals(str80.length(), 80);
93
94 String strNull = null;
95 try {
96 strNull.length();
97 Assert.fail();
98 } catch (NullPointerException expected) {
99 }
100 }
101
102 public static void test_String_isEmpty() {
103 String str0 = "";
104 String str1 = "x";
105
106 Assert.assertTrue(str0.isEmpty());
107 Assert.assertFalse(str1.isEmpty());
108
109 String strNull = null;
110 try {
111 strNull.isEmpty();
112 Assert.fail();
113 } catch (NullPointerException expected) {
114 }
115 }
116
117 public static void test_String_charAt() {
118 String testStr = "Now is the time";
119
120 Assert.assertEquals('N', testStr.charAt(0));
121 Assert.assertEquals('o', testStr.charAt(1));
122 Assert.assertEquals(' ', testStr.charAt(10));
123 Assert.assertEquals('e', testStr.charAt(testStr.length()-1));
124
125 try {
126 testStr.charAt(-1);
127 Assert.fail();
128 } catch (StringIndexOutOfBoundsException expected) {
129 }
130 try {
131 testStr.charAt(80);
132 Assert.fail();
133 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700134 }
135
Elliott Hughes28c384b2012-06-15 16:46:25 -0700136 String strNull = null;
137 try {
138 strNull.charAt(0);
139 Assert.fail();
140 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700141 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700142 }
jeffhao5d1ac922011-09-29 17:41:15 -0700143
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700144 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700145 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700146 public static void test_String_indexOf() {
147 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700148 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700149 String str3 = "abc";
150 String str10 = "abcdefghij";
151 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700152
Elliott Hughes28c384b2012-06-15 16:46:25 -0700153 int supplementaryChar = 0x20b9f;
154 String surrogatePair = "\ud842\udf9f";
155 String stringWithSurrogates = "hello " + surrogatePair + " world";
jeffhao5d1ac922011-09-29 17:41:15 -0700156
Elliott Hughes28c384b2012-06-15 16:46:25 -0700157 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
158 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
159 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
160 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
jeffhao5d1ac922011-09-29 17:41:15 -0700161
Elliott Hughes28c384b2012-06-15 16:46:25 -0700162 Assert.assertEquals(str0.indexOf('a'), -1);
163 Assert.assertEquals(str3.indexOf('a'), 0);
164 Assert.assertEquals(str3.indexOf('b'), 1);
165 Assert.assertEquals(str3.indexOf('c'), 2);
166 Assert.assertEquals(str10.indexOf('j'), 9);
167 Assert.assertEquals(str40.indexOf('a'), 0);
168 Assert.assertEquals(str40.indexOf('b'), 38);
169 Assert.assertEquals(str40.indexOf('c'), 39);
170 Assert.assertEquals(str0.indexOf('a',20), -1);
171 Assert.assertEquals(str0.indexOf('a',0), -1);
172 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700173 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700174 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700175 Assert.assertEquals(str3.indexOf('a',0), 0);
176 Assert.assertEquals(str3.indexOf('a',1), -1);
177 Assert.assertEquals(str3.indexOf('a',1234), -1);
178 Assert.assertEquals(str3.indexOf('b',0), 1);
179 Assert.assertEquals(str3.indexOf('b',1), 1);
180 Assert.assertEquals(str3.indexOf('c',2), 2);
181 Assert.assertEquals(str10.indexOf('j',5), 9);
182 Assert.assertEquals(str10.indexOf('j',9), 9);
183 Assert.assertEquals(str40.indexOf('a',10), 10);
184 Assert.assertEquals(str40.indexOf('b',40), -1);
185
186 String strNull = null;
187 try {
188 strNull.indexOf('a');
189 Assert.fail();
190 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700191 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700192 try {
193 strNull.indexOf('a', 0);
194 Assert.fail();
195 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700196 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700197 try {
198 strNull.indexOf('a', -1);
199 Assert.fail();
200 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700201 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700202 }
jeffhao5d1ac922011-09-29 17:41:15 -0700203
Elliott Hughes28c384b2012-06-15 16:46:25 -0700204 public static void test_String_compareTo() {
205 String test = "0123456789";
206 String test1 = new String("0123456789"); // different object
207 String test2 = new String("0123456780"); // different value
208 String offset = new String("xxx0123456789yyy");
209 String sub = offset.substring(3, 13);
210 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
211 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
212 String lc = "abcdefg";
213 String uc = "ABCDEFG";
214 Object blah = new Object();
215
216 Assert.assertTrue(lc.toUpperCase().equals(uc));
217
218 Assert.assertEquals(str32.compareTo(str33), -1);
219 Assert.assertEquals(str33.compareTo(str32), 1);
220
221 Assert.assertTrue(test.equals(test));
222 Assert.assertTrue(test.equals(test1));
223 Assert.assertFalse(test.equals(test2));
224
225 Assert.assertEquals(test.compareTo(test1), 0);
226 Assert.assertTrue(test1.compareTo(test2) > 0);
227 Assert.assertTrue(test2.compareTo(test1) < 0);
228
229 // Compare string with a nonzero offset, in left/right side.
230 Assert.assertEquals(test.compareTo(sub), 0);
231 Assert.assertEquals(sub.compareTo(test), 0);
232 Assert.assertTrue(test.equals(sub));
233 Assert.assertTrue(sub.equals(test));
234 // Same base, one is a substring.
235 Assert.assertFalse(offset.equals(sub));
236 Assert.assertFalse(sub.equals(offset));
237 // Wrong class.
238 Assert.assertFalse(test.equals(blah));
239
240 // Null lhs - throw.
241 try {
242 test.compareTo(null);
243 Assert.fail("didn't get expected npe");
244 } catch (NullPointerException npe) {
245 }
246 // Null rhs - okay.
247 Assert.assertFalse(test.equals(null));
248
249 test = test.substring(1);
250 Assert.assertTrue(test.equals("123456789"));
251 Assert.assertFalse(test.equals(test1));
252
253 test = test.substring(1);
254 Assert.assertTrue(test.equals("23456789"));
255
256 test = test.substring(1);
257 Assert.assertTrue(test.equals("3456789"));
258
259 test = test.substring(1);
260 Assert.assertTrue(test.equals("456789"));
261
262 test = test.substring(3,5);
263 Assert.assertTrue(test.equals("78"));
264
265 test = "this/is/a/path";
266 String[] strings = test.split("/");
267 Assert.assertEquals(4, strings.length);
268
269 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
270 Assert.assertEquals("this is a path", test.replace("/", " "));
271 }
272
273 public static void test_Math_abs_I() {
274 Assert.assertEquals(Math.abs(0), 0);
275 Assert.assertEquals(Math.abs(123), 123);
276 Assert.assertEquals(Math.abs(-123), 123);
277 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
278 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
279 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100280 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700281 }
282
283 public static void test_Math_abs_J() {
284 Assert.assertEquals(Math.abs(0L), 0L);
285 Assert.assertEquals(Math.abs(123L), 123L);
286 Assert.assertEquals(Math.abs(-123L), 123L);
287 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
288 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
289 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
290 }
291
Serban Constantinescu23abec92014-07-02 16:13:38 +0100292 public static void test_Math_min_I() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700293 Assert.assertEquals(Math.min(0, 0), 0);
294 Assert.assertEquals(Math.min(1, 0), 0);
295 Assert.assertEquals(Math.min(0, 1), 0);
296 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
297 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
298 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
299 }
300
Serban Constantinescu23abec92014-07-02 16:13:38 +0100301 public static void test_Math_max_I() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700302 Assert.assertEquals(Math.max(0, 0), 0);
303 Assert.assertEquals(Math.max(1, 0), 1);
304 Assert.assertEquals(Math.max(0, 1), 1);
305 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
306 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
307 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
308 }
309
Serban Constantinescu23abec92014-07-02 16:13:38 +0100310 public static void test_Math_min_J() {
311 Assert.assertEquals(Math.min(0L, 0L), 0L);
312 Assert.assertEquals(Math.min(1L, 0L), 0L);
313 Assert.assertEquals(Math.min(0L, 1L), 0L);
314 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
315 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
316 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
317 }
318
319 public static void test_Math_max_J() {
320 Assert.assertEquals(Math.max(0L, 0L), 0L);
321 Assert.assertEquals(Math.max(1L, 0L), 1L);
322 Assert.assertEquals(Math.max(0L, 1L), 1L);
323 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
324 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
325 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
326 }
327
328 public static void test_Math_min_F() {
329 Assert.assertTrue(approxEqual(Math.min(0.0f, 0.0f), 0.0f, 0.001f));
330 Assert.assertTrue(approxEqual(Math.min(1.0f, 0.0f), 0.0f, 0.001f));
331 Assert.assertTrue(approxEqual(Math.min(0.0f, 1.0f), 0.0f, 0.001f));
332 Assert.assertTrue(approxEqual(Math.min(0.0f, Float.MAX_VALUE), 0.0f, 0.001f));
333 Assert.assertTrue(approxEqual(Math.min(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE, 0.001f));
334 Assert.assertTrue(approxEqual(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE, 0.001f));
335 }
336
337 public static void test_Math_max_F() {
338 Assert.assertTrue(approxEqual(Math.max(0.0f, 0.0f), 0.0f, 0.001f));
339 Assert.assertTrue(approxEqual(Math.max(1.0f, 0.0f), 1.0f, 0.001f));
340 Assert.assertTrue(approxEqual(Math.max(0.0f, 1.0f), 1.0f, 0.001f));
341 Assert.assertTrue(approxEqual(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
342 Assert.assertTrue(approxEqual(Math.max(Float.MIN_VALUE, 0.0f), 0.0f, 0.001f));
343 Assert.assertTrue(approxEqual(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
344 }
345
346 public static void test_Math_min_D() {
347 Assert.assertTrue(approxEqual(Math.min(0.0d, 0.0d), 0.0d, 0.001d));
348 Assert.assertTrue(approxEqual(Math.min(1.0d, 0.0d), 0.0d, 0.001d));
349 Assert.assertTrue(approxEqual(Math.min(0.0d, 1.0d), 0.0d, 0.001d));
350 Assert.assertTrue(approxEqual(Math.min(0.0d, Double.MAX_VALUE), 0.0d, 0.001d));
351 Assert.assertTrue(approxEqual(Math.min(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE, 0.001d));
352 Assert.assertTrue(approxEqual(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE, 0.001d));
353 }
354
355 public static void test_Math_max_D() {
356 Assert.assertTrue(approxEqual(Math.max(0.0d, 0.0d), 0.0d, 0.001d));
357 Assert.assertTrue(approxEqual(Math.max(1.0d, 0.0d), 1.0d, 0.001d));
358 Assert.assertTrue(approxEqual(Math.max(0.0d, 1.0d), 1.0d, 0.001d));
359 Assert.assertTrue(approxEqual(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
360 Assert.assertTrue(approxEqual(Math.max(Double.MIN_VALUE, 0.0d), 0.0d, 0.001d));
361 Assert.assertTrue(approxEqual(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
362 }
363
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100364 public static void test_StrictMath_abs_I() {
365 Assert.assertEquals(StrictMath.abs(0), 0);
366 Assert.assertEquals(StrictMath.abs(123), 123);
367 Assert.assertEquals(StrictMath.abs(-123), 123);
368 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
369 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
370 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
371 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
372 }
373
374 public static void test_StrictMath_abs_J() {
375 Assert.assertEquals(StrictMath.abs(0L), 0L);
376 Assert.assertEquals(StrictMath.abs(123L), 123L);
377 Assert.assertEquals(StrictMath.abs(-123L), 123L);
378 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
379 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
380 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
381 }
382
Serban Constantinescu23abec92014-07-02 16:13:38 +0100383 public static void test_StrictMath_min_I() {
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100384 Assert.assertEquals(StrictMath.min(0, 0), 0);
385 Assert.assertEquals(StrictMath.min(1, 0), 0);
386 Assert.assertEquals(StrictMath.min(0, 1), 0);
387 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
388 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
389 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
390 }
391
Serban Constantinescu23abec92014-07-02 16:13:38 +0100392 public static void test_StrictMath_max_I() {
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100393 Assert.assertEquals(StrictMath.max(0, 0), 0);
394 Assert.assertEquals(StrictMath.max(1, 0), 1);
395 Assert.assertEquals(StrictMath.max(0, 1), 1);
396 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
397 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
398 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
399 }
400
Serban Constantinescu23abec92014-07-02 16:13:38 +0100401 public static void test_StrictMath_min_J() {
402 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
403 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
404 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
405 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
406 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
407 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
408 }
409
410 public static void test_StrictMath_max_J() {
411 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
412 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
413 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
414 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
415 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
416 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
417 }
418
419 public static void test_StrictMath_min_F() {
420 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, 0.0f), 0.0f, 0.001f));
421 Assert.assertTrue(approxEqual(StrictMath.min(1.0f, 0.0f), 0.0f, 0.001f));
422 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, 1.0f), 0.0f, 0.001f));
423 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f, 0.001f));
424 Assert.assertTrue(approxEqual(StrictMath.min(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE, 0.001f));
425 Assert.assertTrue(approxEqual(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE, 0.001f));
426 }
427
428 public static void test_StrictMath_max_F() {
429 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, 0.0f), 0.0f, 0.001f));
430 Assert.assertTrue(approxEqual(StrictMath.max(1.0f, 0.0f), 1.0f, 0.001f));
431 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, 1.0f), 1.0f, 0.001f));
432 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
433 Assert.assertTrue(approxEqual(StrictMath.max(Float.MIN_VALUE, 0.0f), 0.0f, 0.001f));
434 Assert.assertTrue(approxEqual(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
435 }
436
437 public static void test_StrictMath_min_D() {
438 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, 0.0d), 0.0d, 0.001d));
439 Assert.assertTrue(approxEqual(StrictMath.min(1.0d, 0.0d), 0.0d, 0.001d));
440 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, 1.0d), 0.0d, 0.001d));
441 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d, 0.001d));
442 Assert.assertTrue(approxEqual(StrictMath.min(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE, 0.001d));
443 Assert.assertTrue(approxEqual(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE, 0.001d));
444 }
445
446 public static void test_StrictMath_max_D() {
447 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, 0.0d), 0.0d, 0.001d));
448 Assert.assertTrue(approxEqual(StrictMath.max(1.0d, 0.0d), 1.0d, 0.001d));
449 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, 1.0d), 1.0d, 0.001d));
450 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
451 Assert.assertTrue(approxEqual(StrictMath.max(Double.MIN_VALUE, 0.0d), 0.0d, 0.001d));
452 Assert.assertTrue(approxEqual(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
453 }
454
Elliott Hughes28c384b2012-06-15 16:46:25 -0700455 public static void test_Float_floatToRawIntBits() {
456 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
457 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
458 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
459 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
460 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
461 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
462 }
463
464 public static void test_Float_intBitsToFloat() {
465 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
466 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
467 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
468 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
469 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
470 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
471 }
472
473 public static void test_Double_doubleToRawLongBits() {
474 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
475 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
476 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
477 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
478 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
479 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
480 }
481
482 public static void test_Double_longBitsToDouble() {
483 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
484 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
485 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
486 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
487 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
488 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
489 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100490
491 public static void test_Integer_reverse() {
492 Assert.assertEquals(Integer.reverse(1), 0x80000000);
493 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
494 Assert.assertEquals(Integer.reverse(0), 0);
495 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
496 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
497 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
498 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
499 }
500
501 public static void test_Long_reverse() {
502 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
503 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
504 Assert.assertEquals(Long.reverse(0L), 0L);
505 // FIXME: This asserts fail with or without this patch. I have collected
506 // the expected results on my host machine.
507 // Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
508 // Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
509 // Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
510 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
511 }
512
jeffhao5d1ac922011-09-29 17:41:15 -0700513}