blob: 5b8134df1cfe3a6d2566ab0d3369355663030727 [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();
52 }
53
Serban Constantinescu23abec92014-07-02 16:13:38 +010054 /*
55 * Determine if two floating point numbers are approximately equal.
56 *
57 * (Assumes that floating point is generally working, so we can't use
58 * this for the first set of tests.)
59 */
60 static boolean approxEqual(float a, float b, float maxDelta) {
61 if (a > b)
62 return (a - b) < maxDelta;
63 else
64 return (b - a) < maxDelta;
65 }
66 static boolean approxEqual(double a, double b, double maxDelta) {
67 if (a > b)
68 return (a - b) < maxDelta;
69 else
70 return (b - a) < maxDelta;
71 }
72
Elliott Hughes28c384b2012-06-15 16:46:25 -070073 public static void test_String_length() {
74 String str0 = "";
75 String str1 = "x";
76 String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
77
78 Assert.assertEquals(str0.length(), 0);
79 Assert.assertEquals(str1.length(), 1);
80 Assert.assertEquals(str80.length(), 80);
81
82 String strNull = null;
83 try {
84 strNull.length();
85 Assert.fail();
86 } catch (NullPointerException expected) {
87 }
88 }
89
90 public static void test_String_isEmpty() {
91 String str0 = "";
92 String str1 = "x";
93
94 Assert.assertTrue(str0.isEmpty());
95 Assert.assertFalse(str1.isEmpty());
96
97 String strNull = null;
98 try {
99 strNull.isEmpty();
100 Assert.fail();
101 } catch (NullPointerException expected) {
102 }
103 }
104
105 public static void test_String_charAt() {
106 String testStr = "Now is the time";
107
108 Assert.assertEquals('N', testStr.charAt(0));
109 Assert.assertEquals('o', testStr.charAt(1));
110 Assert.assertEquals(' ', testStr.charAt(10));
111 Assert.assertEquals('e', testStr.charAt(testStr.length()-1));
112
113 try {
114 testStr.charAt(-1);
115 Assert.fail();
116 } catch (StringIndexOutOfBoundsException expected) {
117 }
118 try {
119 testStr.charAt(80);
120 Assert.fail();
121 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700122 }
123
Elliott Hughes28c384b2012-06-15 16:46:25 -0700124 String strNull = null;
125 try {
126 strNull.charAt(0);
127 Assert.fail();
128 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700129 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700130 }
jeffhao5d1ac922011-09-29 17:41:15 -0700131
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700132 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700133 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700134 public static void test_String_indexOf() {
135 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700136 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700137 String str3 = "abc";
138 String str10 = "abcdefghij";
139 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700140
Elliott Hughes28c384b2012-06-15 16:46:25 -0700141 int supplementaryChar = 0x20b9f;
142 String surrogatePair = "\ud842\udf9f";
143 String stringWithSurrogates = "hello " + surrogatePair + " world";
jeffhao5d1ac922011-09-29 17:41:15 -0700144
Elliott Hughes28c384b2012-06-15 16:46:25 -0700145 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
146 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
147 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
148 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
jeffhao5d1ac922011-09-29 17:41:15 -0700149
Elliott Hughes28c384b2012-06-15 16:46:25 -0700150 Assert.assertEquals(str0.indexOf('a'), -1);
151 Assert.assertEquals(str3.indexOf('a'), 0);
152 Assert.assertEquals(str3.indexOf('b'), 1);
153 Assert.assertEquals(str3.indexOf('c'), 2);
154 Assert.assertEquals(str10.indexOf('j'), 9);
155 Assert.assertEquals(str40.indexOf('a'), 0);
156 Assert.assertEquals(str40.indexOf('b'), 38);
157 Assert.assertEquals(str40.indexOf('c'), 39);
158 Assert.assertEquals(str0.indexOf('a',20), -1);
159 Assert.assertEquals(str0.indexOf('a',0), -1);
160 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700161 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700162 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700163 Assert.assertEquals(str3.indexOf('a',0), 0);
164 Assert.assertEquals(str3.indexOf('a',1), -1);
165 Assert.assertEquals(str3.indexOf('a',1234), -1);
166 Assert.assertEquals(str3.indexOf('b',0), 1);
167 Assert.assertEquals(str3.indexOf('b',1), 1);
168 Assert.assertEquals(str3.indexOf('c',2), 2);
169 Assert.assertEquals(str10.indexOf('j',5), 9);
170 Assert.assertEquals(str10.indexOf('j',9), 9);
171 Assert.assertEquals(str40.indexOf('a',10), 10);
172 Assert.assertEquals(str40.indexOf('b',40), -1);
173
174 String strNull = null;
175 try {
176 strNull.indexOf('a');
177 Assert.fail();
178 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700179 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700180 try {
181 strNull.indexOf('a', 0);
182 Assert.fail();
183 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700184 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700185 try {
186 strNull.indexOf('a', -1);
187 Assert.fail();
188 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700189 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700190 }
jeffhao5d1ac922011-09-29 17:41:15 -0700191
Elliott Hughes28c384b2012-06-15 16:46:25 -0700192 public static void test_String_compareTo() {
193 String test = "0123456789";
194 String test1 = new String("0123456789"); // different object
195 String test2 = new String("0123456780"); // different value
196 String offset = new String("xxx0123456789yyy");
197 String sub = offset.substring(3, 13);
198 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
199 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
200 String lc = "abcdefg";
201 String uc = "ABCDEFG";
202 Object blah = new Object();
203
204 Assert.assertTrue(lc.toUpperCase().equals(uc));
205
206 Assert.assertEquals(str32.compareTo(str33), -1);
207 Assert.assertEquals(str33.compareTo(str32), 1);
208
209 Assert.assertTrue(test.equals(test));
210 Assert.assertTrue(test.equals(test1));
211 Assert.assertFalse(test.equals(test2));
212
213 Assert.assertEquals(test.compareTo(test1), 0);
214 Assert.assertTrue(test1.compareTo(test2) > 0);
215 Assert.assertTrue(test2.compareTo(test1) < 0);
216
217 // Compare string with a nonzero offset, in left/right side.
218 Assert.assertEquals(test.compareTo(sub), 0);
219 Assert.assertEquals(sub.compareTo(test), 0);
220 Assert.assertTrue(test.equals(sub));
221 Assert.assertTrue(sub.equals(test));
222 // Same base, one is a substring.
223 Assert.assertFalse(offset.equals(sub));
224 Assert.assertFalse(sub.equals(offset));
225 // Wrong class.
226 Assert.assertFalse(test.equals(blah));
227
228 // Null lhs - throw.
229 try {
230 test.compareTo(null);
231 Assert.fail("didn't get expected npe");
232 } catch (NullPointerException npe) {
233 }
234 // Null rhs - okay.
235 Assert.assertFalse(test.equals(null));
236
237 test = test.substring(1);
238 Assert.assertTrue(test.equals("123456789"));
239 Assert.assertFalse(test.equals(test1));
240
241 test = test.substring(1);
242 Assert.assertTrue(test.equals("23456789"));
243
244 test = test.substring(1);
245 Assert.assertTrue(test.equals("3456789"));
246
247 test = test.substring(1);
248 Assert.assertTrue(test.equals("456789"));
249
250 test = test.substring(3,5);
251 Assert.assertTrue(test.equals("78"));
252
253 test = "this/is/a/path";
254 String[] strings = test.split("/");
255 Assert.assertEquals(4, strings.length);
256
257 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
258 Assert.assertEquals("this is a path", test.replace("/", " "));
259 }
260
261 public static void test_Math_abs_I() {
262 Assert.assertEquals(Math.abs(0), 0);
263 Assert.assertEquals(Math.abs(123), 123);
264 Assert.assertEquals(Math.abs(-123), 123);
265 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
266 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
267 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100268 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700269 }
270
271 public static void test_Math_abs_J() {
272 Assert.assertEquals(Math.abs(0L), 0L);
273 Assert.assertEquals(Math.abs(123L), 123L);
274 Assert.assertEquals(Math.abs(-123L), 123L);
275 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
276 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
277 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
278 }
279
Serban Constantinescu23abec92014-07-02 16:13:38 +0100280 public static void test_Math_min_I() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700281 Assert.assertEquals(Math.min(0, 0), 0);
282 Assert.assertEquals(Math.min(1, 0), 0);
283 Assert.assertEquals(Math.min(0, 1), 0);
284 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
285 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
286 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
287 }
288
Serban Constantinescu23abec92014-07-02 16:13:38 +0100289 public static void test_Math_max_I() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700290 Assert.assertEquals(Math.max(0, 0), 0);
291 Assert.assertEquals(Math.max(1, 0), 1);
292 Assert.assertEquals(Math.max(0, 1), 1);
293 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
294 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
295 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
296 }
297
Serban Constantinescu23abec92014-07-02 16:13:38 +0100298 public static void test_Math_min_J() {
299 Assert.assertEquals(Math.min(0L, 0L), 0L);
300 Assert.assertEquals(Math.min(1L, 0L), 0L);
301 Assert.assertEquals(Math.min(0L, 1L), 0L);
302 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
303 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
304 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
305 }
306
307 public static void test_Math_max_J() {
308 Assert.assertEquals(Math.max(0L, 0L), 0L);
309 Assert.assertEquals(Math.max(1L, 0L), 1L);
310 Assert.assertEquals(Math.max(0L, 1L), 1L);
311 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
312 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
313 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
314 }
315
316 public static void test_Math_min_F() {
317 Assert.assertTrue(approxEqual(Math.min(0.0f, 0.0f), 0.0f, 0.001f));
318 Assert.assertTrue(approxEqual(Math.min(1.0f, 0.0f), 0.0f, 0.001f));
319 Assert.assertTrue(approxEqual(Math.min(0.0f, 1.0f), 0.0f, 0.001f));
320 Assert.assertTrue(approxEqual(Math.min(0.0f, Float.MAX_VALUE), 0.0f, 0.001f));
321 Assert.assertTrue(approxEqual(Math.min(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE, 0.001f));
322 Assert.assertTrue(approxEqual(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE, 0.001f));
323 }
324
325 public static void test_Math_max_F() {
326 Assert.assertTrue(approxEqual(Math.max(0.0f, 0.0f), 0.0f, 0.001f));
327 Assert.assertTrue(approxEqual(Math.max(1.0f, 0.0f), 1.0f, 0.001f));
328 Assert.assertTrue(approxEqual(Math.max(0.0f, 1.0f), 1.0f, 0.001f));
329 Assert.assertTrue(approxEqual(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
330 Assert.assertTrue(approxEqual(Math.max(Float.MIN_VALUE, 0.0f), 0.0f, 0.001f));
331 Assert.assertTrue(approxEqual(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
332 }
333
334 public static void test_Math_min_D() {
335 Assert.assertTrue(approxEqual(Math.min(0.0d, 0.0d), 0.0d, 0.001d));
336 Assert.assertTrue(approxEqual(Math.min(1.0d, 0.0d), 0.0d, 0.001d));
337 Assert.assertTrue(approxEqual(Math.min(0.0d, 1.0d), 0.0d, 0.001d));
338 Assert.assertTrue(approxEqual(Math.min(0.0d, Double.MAX_VALUE), 0.0d, 0.001d));
339 Assert.assertTrue(approxEqual(Math.min(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE, 0.001d));
340 Assert.assertTrue(approxEqual(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE, 0.001d));
341 }
342
343 public static void test_Math_max_D() {
344 Assert.assertTrue(approxEqual(Math.max(0.0d, 0.0d), 0.0d, 0.001d));
345 Assert.assertTrue(approxEqual(Math.max(1.0d, 0.0d), 1.0d, 0.001d));
346 Assert.assertTrue(approxEqual(Math.max(0.0d, 1.0d), 1.0d, 0.001d));
347 Assert.assertTrue(approxEqual(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
348 Assert.assertTrue(approxEqual(Math.max(Double.MIN_VALUE, 0.0d), 0.0d, 0.001d));
349 Assert.assertTrue(approxEqual(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
350 }
351
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100352 public static void test_StrictMath_abs_I() {
353 Assert.assertEquals(StrictMath.abs(0), 0);
354 Assert.assertEquals(StrictMath.abs(123), 123);
355 Assert.assertEquals(StrictMath.abs(-123), 123);
356 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
357 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
358 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
359 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
360 }
361
362 public static void test_StrictMath_abs_J() {
363 Assert.assertEquals(StrictMath.abs(0L), 0L);
364 Assert.assertEquals(StrictMath.abs(123L), 123L);
365 Assert.assertEquals(StrictMath.abs(-123L), 123L);
366 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
367 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
368 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
369 }
370
Serban Constantinescu23abec92014-07-02 16:13:38 +0100371 public static void test_StrictMath_min_I() {
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100372 Assert.assertEquals(StrictMath.min(0, 0), 0);
373 Assert.assertEquals(StrictMath.min(1, 0), 0);
374 Assert.assertEquals(StrictMath.min(0, 1), 0);
375 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
376 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
377 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
378 }
379
Serban Constantinescu23abec92014-07-02 16:13:38 +0100380 public static void test_StrictMath_max_I() {
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100381 Assert.assertEquals(StrictMath.max(0, 0), 0);
382 Assert.assertEquals(StrictMath.max(1, 0), 1);
383 Assert.assertEquals(StrictMath.max(0, 1), 1);
384 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
385 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
386 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
387 }
388
Serban Constantinescu23abec92014-07-02 16:13:38 +0100389 public static void test_StrictMath_min_J() {
390 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
391 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
392 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
393 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
394 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
395 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
396 }
397
398 public static void test_StrictMath_max_J() {
399 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
400 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
401 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
402 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
403 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
404 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
405 }
406
407 public static void test_StrictMath_min_F() {
408 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, 0.0f), 0.0f, 0.001f));
409 Assert.assertTrue(approxEqual(StrictMath.min(1.0f, 0.0f), 0.0f, 0.001f));
410 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, 1.0f), 0.0f, 0.001f));
411 Assert.assertTrue(approxEqual(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f, 0.001f));
412 Assert.assertTrue(approxEqual(StrictMath.min(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE, 0.001f));
413 Assert.assertTrue(approxEqual(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE, 0.001f));
414 }
415
416 public static void test_StrictMath_max_F() {
417 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, 0.0f), 0.0f, 0.001f));
418 Assert.assertTrue(approxEqual(StrictMath.max(1.0f, 0.0f), 1.0f, 0.001f));
419 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, 1.0f), 1.0f, 0.001f));
420 Assert.assertTrue(approxEqual(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
421 Assert.assertTrue(approxEqual(StrictMath.max(Float.MIN_VALUE, 0.0f), 0.0f, 0.001f));
422 Assert.assertTrue(approxEqual(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE, 0.001f));
423 }
424
425 public static void test_StrictMath_min_D() {
426 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, 0.0d), 0.0d, 0.001d));
427 Assert.assertTrue(approxEqual(StrictMath.min(1.0d, 0.0d), 0.0d, 0.001d));
428 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, 1.0d), 0.0d, 0.001d));
429 Assert.assertTrue(approxEqual(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d, 0.001d));
430 Assert.assertTrue(approxEqual(StrictMath.min(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE, 0.001d));
431 Assert.assertTrue(approxEqual(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE, 0.001d));
432 }
433
434 public static void test_StrictMath_max_D() {
435 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, 0.0d), 0.0d, 0.001d));
436 Assert.assertTrue(approxEqual(StrictMath.max(1.0d, 0.0d), 1.0d, 0.001d));
437 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, 1.0d), 1.0d, 0.001d));
438 Assert.assertTrue(approxEqual(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
439 Assert.assertTrue(approxEqual(StrictMath.max(Double.MIN_VALUE, 0.0d), 0.0d, 0.001d));
440 Assert.assertTrue(approxEqual(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE, 0.001d));
441 }
442
Elliott Hughes28c384b2012-06-15 16:46:25 -0700443 public static void test_Float_floatToRawIntBits() {
444 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
445 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
446 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
447 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
448 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
449 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
450 }
451
452 public static void test_Float_intBitsToFloat() {
453 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
454 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
455 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
456 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
457 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
458 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
459 }
460
461 public static void test_Double_doubleToRawLongBits() {
462 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
463 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
464 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
465 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
466 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
467 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
468 }
469
470 public static void test_Double_longBitsToDouble() {
471 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
472 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
473 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
474 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
475 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
476 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
477 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100478
479 public static void test_Integer_reverse() {
480 Assert.assertEquals(Integer.reverse(1), 0x80000000);
481 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
482 Assert.assertEquals(Integer.reverse(0), 0);
483 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
484 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
485 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
486 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
487 }
488
489 public static void test_Long_reverse() {
490 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
491 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
492 Assert.assertEquals(Long.reverse(0L), 0L);
493 // FIXME: This asserts fail with or without this patch. I have collected
494 // the expected results on my host machine.
495 // Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
496 // Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
497 // Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
498 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
499 }
500
jeffhao5d1ac922011-09-29 17:41:15 -0700501}