blob: 5561a09c886a418319b00f1824303a4fedf7beaa [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;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070018import java.util.Arrays;
19import java.lang.reflect.Method;
jeffhao5d1ac922011-09-29 17:41:15 -070020
21public class Main {
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070022 public static void main(String args[]) throws Exception {
Elliott Hughes28c384b2012-06-15 16:46:25 -070023 test_Double_doubleToRawLongBits();
24 test_Double_longBitsToDouble();
25 test_Float_floatToRawIntBits();
26 test_Float_intBitsToFloat();
27 test_Math_abs_I();
28 test_Math_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010029 test_Math_min_I();
30 test_Math_max_I();
31 test_Math_min_J();
32 test_Math_max_J();
33 test_Math_min_F();
34 test_Math_max_F();
35 test_Math_min_D();
36 test_Math_max_D();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080037 test_Math_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010038 test_Math_ceil();
39 test_Math_floor();
40 test_Math_rint();
41 test_Math_round_D();
42 test_Math_round_F();
Zheng Xua3fe7422014-07-09 14:03:15 +080043 test_Short_reverseBytes();
44 test_Integer_reverseBytes();
45 test_Long_reverseBytes();
Serban Constantinescu23abec92014-07-02 16:13:38 +010046 test_Integer_reverse();
47 test_Long_reverse();
Sebastien Hertzbf1442d2013-03-05 15:12:40 +010048 test_StrictMath_abs_I();
49 test_StrictMath_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010050 test_StrictMath_min_I();
51 test_StrictMath_max_I();
52 test_StrictMath_min_J();
53 test_StrictMath_max_J();
54 test_StrictMath_min_F();
55 test_StrictMath_max_F();
56 test_StrictMath_min_D();
57 test_StrictMath_max_D();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080058 test_StrictMath_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010059 test_StrictMath_ceil();
60 test_StrictMath_floor();
61 test_StrictMath_rint();
62 test_StrictMath_round_D();
63 test_StrictMath_round_F();
Elliott Hughes28c384b2012-06-15 16:46:25 -070064 test_String_charAt();
65 test_String_compareTo();
66 test_String_indexOf();
67 test_String_isEmpty();
68 test_String_length();
Andreas Gampe7a949612014-07-08 11:03:59 -070069 test_Thread_currentThread();
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070070 initSupportMethodsForPeekPoke();
71 test_Memory_peekByte();
72 test_Memory_peekShort();
73 test_Memory_peekInt();
74 test_Memory_peekLong();
75 test_Memory_pokeByte();
76 test_Memory_pokeShort();
77 test_Memory_pokeInt();
78 test_Memory_pokeLong();
Elliott Hughes28c384b2012-06-15 16:46:25 -070079 }
80
Andreas Gampe7a949612014-07-08 11:03:59 -070081 /**
82 * Will test inlining Thread.currentThread().
83 */
84 public static void test_Thread_currentThread() {
85 // 1. Do not use result.
86 Thread.currentThread();
87
88 // 2. Result should not be null.
89 Assert.assertNotNull(Thread.currentThread());
90 }
91
Elliott Hughes28c384b2012-06-15 16:46:25 -070092 public static void test_String_length() {
93 String str0 = "";
94 String str1 = "x";
95 String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
96
97 Assert.assertEquals(str0.length(), 0);
98 Assert.assertEquals(str1.length(), 1);
99 Assert.assertEquals(str80.length(), 80);
100
101 String strNull = null;
102 try {
103 strNull.length();
104 Assert.fail();
105 } catch (NullPointerException expected) {
106 }
107 }
108
109 public static void test_String_isEmpty() {
110 String str0 = "";
111 String str1 = "x";
112
113 Assert.assertTrue(str0.isEmpty());
114 Assert.assertFalse(str1.isEmpty());
115
116 String strNull = null;
117 try {
118 strNull.isEmpty();
119 Assert.fail();
120 } catch (NullPointerException expected) {
121 }
122 }
123
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800124 // Break up the charAt tests. The optimizing compiler doesn't optimize methods with try-catch yet,
125 // so we need to separate out the tests that are expected to throw exception
126
Elliott Hughes28c384b2012-06-15 16:46:25 -0700127 public static void test_String_charAt() {
128 String testStr = "Now is the time";
129
130 Assert.assertEquals('N', testStr.charAt(0));
131 Assert.assertEquals('o', testStr.charAt(1));
132 Assert.assertEquals(' ', testStr.charAt(10));
Vladimir Marko00ca8472015-01-26 14:06:46 +0000133 Assert.assertEquals('e', testStr.charAt(14)); // 14 = testStr.length()-1 as a constant.
134 Assert.assertEquals('N', test_String_charAt_inner(testStr, 0));
135 Assert.assertEquals('o', test_String_charAt_inner(testStr, 1));
136 Assert.assertEquals(' ', test_String_charAt_inner(testStr, 10));
137 Assert.assertEquals('e', test_String_charAt_inner(testStr, testStr.length()-1));
Elliott Hughes28c384b2012-06-15 16:46:25 -0700138
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800139 test_String_charAtExc();
140 test_String_charAtExc2();
141 }
142
143 private static void test_String_charAtExc() {
144 String testStr = "Now is the time";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700145 try {
146 testStr.charAt(-1);
147 Assert.fail();
148 } catch (StringIndexOutOfBoundsException expected) {
149 }
150 try {
151 testStr.charAt(80);
152 Assert.fail();
153 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700154 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000155 try {
156 testStr.charAt(15); // 15 = "Now is the time".length()
157 Assert.fail();
158 } catch (StringIndexOutOfBoundsException expected) {
159 }
160 try {
161 test_String_charAt_inner(testStr, -1);
162 Assert.fail();
163 } catch (StringIndexOutOfBoundsException expected) {
164 }
165 try {
166 test_String_charAt_inner(testStr, 80);
167 Assert.fail();
168 } catch (StringIndexOutOfBoundsException expected) {
169 }
170 try {
171 test_String_charAt_inner(testStr, 15); // 15 = "Now is the time".length()
172 Assert.fail();
173 } catch (StringIndexOutOfBoundsException expected) {
174 }
175
176 String strEmpty = "";
177 try {
178 strEmpty.charAt(0);
179 Assert.fail();
180 } catch (StringIndexOutOfBoundsException expected) {
181 }
jeffhao5d1ac922011-09-29 17:41:15 -0700182
Elliott Hughes28c384b2012-06-15 16:46:25 -0700183 String strNull = null;
184 try {
185 strNull.charAt(0);
186 Assert.fail();
187 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700188 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700189 }
jeffhao5d1ac922011-09-29 17:41:15 -0700190
Vladimir Marko00ca8472015-01-26 14:06:46 +0000191 private static char test_String_charAt_inner(String s, int index) {
192 // Using non-constant index here (assuming that this method wasn't inlined).
193 return s.charAt(index);
194 }
195
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800196 private static void test_String_charAtExc2() {
197 try {
198 test_String_charAtExc3();
199 Assert.fail();
200 } catch (StringIndexOutOfBoundsException expected) {
201 }
202 }
203
204 private static void test_String_charAtExc3() {
205 String testStr = "Now is the time";
206 Assert.assertEquals('N', testStr.charAt(-1));
207 }
208
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700209 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700210 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700211 public static void test_String_indexOf() {
212 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700213 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700214 String str3 = "abc";
215 String str10 = "abcdefghij";
216 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700217
Elliott Hughes28c384b2012-06-15 16:46:25 -0700218 int supplementaryChar = 0x20b9f;
219 String surrogatePair = "\ud842\udf9f";
220 String stringWithSurrogates = "hello " + surrogatePair + " world";
jeffhao5d1ac922011-09-29 17:41:15 -0700221
Elliott Hughes28c384b2012-06-15 16:46:25 -0700222 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
223 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
224 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
225 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
jeffhao5d1ac922011-09-29 17:41:15 -0700226
Elliott Hughes28c384b2012-06-15 16:46:25 -0700227 Assert.assertEquals(str0.indexOf('a'), -1);
228 Assert.assertEquals(str3.indexOf('a'), 0);
229 Assert.assertEquals(str3.indexOf('b'), 1);
230 Assert.assertEquals(str3.indexOf('c'), 2);
231 Assert.assertEquals(str10.indexOf('j'), 9);
232 Assert.assertEquals(str40.indexOf('a'), 0);
233 Assert.assertEquals(str40.indexOf('b'), 38);
234 Assert.assertEquals(str40.indexOf('c'), 39);
235 Assert.assertEquals(str0.indexOf('a',20), -1);
236 Assert.assertEquals(str0.indexOf('a',0), -1);
237 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700238 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700239 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700240 Assert.assertEquals(str3.indexOf('a',0), 0);
241 Assert.assertEquals(str3.indexOf('a',1), -1);
242 Assert.assertEquals(str3.indexOf('a',1234), -1);
243 Assert.assertEquals(str3.indexOf('b',0), 1);
244 Assert.assertEquals(str3.indexOf('b',1), 1);
245 Assert.assertEquals(str3.indexOf('c',2), 2);
246 Assert.assertEquals(str10.indexOf('j',5), 9);
247 Assert.assertEquals(str10.indexOf('j',9), 9);
248 Assert.assertEquals(str40.indexOf('a',10), 10);
249 Assert.assertEquals(str40.indexOf('b',40), -1);
250
251 String strNull = null;
252 try {
253 strNull.indexOf('a');
254 Assert.fail();
255 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700256 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700257 try {
258 strNull.indexOf('a', 0);
259 Assert.fail();
260 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700261 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700262 try {
263 strNull.indexOf('a', -1);
264 Assert.fail();
265 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700266 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700267 }
jeffhao5d1ac922011-09-29 17:41:15 -0700268
Elliott Hughes28c384b2012-06-15 16:46:25 -0700269 public static void test_String_compareTo() {
270 String test = "0123456789";
271 String test1 = new String("0123456789"); // different object
272 String test2 = new String("0123456780"); // different value
273 String offset = new String("xxx0123456789yyy");
274 String sub = offset.substring(3, 13);
275 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
276 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
277 String lc = "abcdefg";
278 String uc = "ABCDEFG";
279 Object blah = new Object();
280
281 Assert.assertTrue(lc.toUpperCase().equals(uc));
282
283 Assert.assertEquals(str32.compareTo(str33), -1);
284 Assert.assertEquals(str33.compareTo(str32), 1);
285
286 Assert.assertTrue(test.equals(test));
287 Assert.assertTrue(test.equals(test1));
288 Assert.assertFalse(test.equals(test2));
289
290 Assert.assertEquals(test.compareTo(test1), 0);
291 Assert.assertTrue(test1.compareTo(test2) > 0);
292 Assert.assertTrue(test2.compareTo(test1) < 0);
293
294 // Compare string with a nonzero offset, in left/right side.
295 Assert.assertEquals(test.compareTo(sub), 0);
296 Assert.assertEquals(sub.compareTo(test), 0);
297 Assert.assertTrue(test.equals(sub));
298 Assert.assertTrue(sub.equals(test));
299 // Same base, one is a substring.
300 Assert.assertFalse(offset.equals(sub));
301 Assert.assertFalse(sub.equals(offset));
302 // Wrong class.
303 Assert.assertFalse(test.equals(blah));
304
305 // Null lhs - throw.
306 try {
307 test.compareTo(null);
308 Assert.fail("didn't get expected npe");
309 } catch (NullPointerException npe) {
310 }
311 // Null rhs - okay.
312 Assert.assertFalse(test.equals(null));
313
314 test = test.substring(1);
315 Assert.assertTrue(test.equals("123456789"));
316 Assert.assertFalse(test.equals(test1));
317
318 test = test.substring(1);
319 Assert.assertTrue(test.equals("23456789"));
320
321 test = test.substring(1);
322 Assert.assertTrue(test.equals("3456789"));
323
324 test = test.substring(1);
325 Assert.assertTrue(test.equals("456789"));
326
327 test = test.substring(3,5);
328 Assert.assertTrue(test.equals("78"));
329
330 test = "this/is/a/path";
331 String[] strings = test.split("/");
332 Assert.assertEquals(4, strings.length);
333
334 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
335 Assert.assertEquals("this is a path", test.replace("/", " "));
336 }
337
338 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800339 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700340 Assert.assertEquals(Math.abs(0), 0);
341 Assert.assertEquals(Math.abs(123), 123);
342 Assert.assertEquals(Math.abs(-123), 123);
343 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
344 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
345 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100346 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700347 }
348
349 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800350 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700351 Assert.assertEquals(Math.abs(0L), 0L);
352 Assert.assertEquals(Math.abs(123L), 123L);
353 Assert.assertEquals(Math.abs(-123L), 123L);
354 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
355 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
356 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
357 }
358
Serban Constantinescu23abec92014-07-02 16:13:38 +0100359 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800360 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700361 Assert.assertEquals(Math.min(0, 0), 0);
362 Assert.assertEquals(Math.min(1, 0), 0);
363 Assert.assertEquals(Math.min(0, 1), 0);
364 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
365 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
366 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
367 }
368
Serban Constantinescu23abec92014-07-02 16:13:38 +0100369 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800370 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700371 Assert.assertEquals(Math.max(0, 0), 0);
372 Assert.assertEquals(Math.max(1, 0), 1);
373 Assert.assertEquals(Math.max(0, 1), 1);
374 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
375 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
376 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
377 }
378
Serban Constantinescu23abec92014-07-02 16:13:38 +0100379 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800380 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100381 Assert.assertEquals(Math.min(0L, 0L), 0L);
382 Assert.assertEquals(Math.min(1L, 0L), 0L);
383 Assert.assertEquals(Math.min(0L, 1L), 0L);
384 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
385 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
386 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
387 }
388
389 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800390 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100391 Assert.assertEquals(Math.max(0L, 0L), 0L);
392 Assert.assertEquals(Math.max(1L, 0L), 1L);
393 Assert.assertEquals(Math.max(0L, 1L), 1L);
394 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
395 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
396 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
397 }
398
399 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800400 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700401 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
402 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
403 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
404 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
405 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
406 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
407 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
408 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
409 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
410 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
411 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100412 }
413
414 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800415 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700416 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
417 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
418 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
419 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
420 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
421 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
422 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
423 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
424 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
425 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
426 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100427 }
428
429 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800430 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700431 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
432 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
433 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
434 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
435 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
436 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
437 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
438 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
439 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
440 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
441 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100442 }
443
444 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800445 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700446 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
447 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
448 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
449 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
450 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
451 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
452 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
453 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
454 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
455 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
456 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100457 }
458
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800459 public static void test_Math_sqrt() {
460 Math.sqrt(+4.0);
461 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
462 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
463 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
464 }
465
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100466 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800467 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100468 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
469 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
470 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
471 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
472 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
473 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
474 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
475 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
476 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
477 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
478 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
479 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
480 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
481 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
482 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
483 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
484 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
485 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
486 }
487
488 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800489 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100490 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
491 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
492 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
493 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
494 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
495 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
496 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
497 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
498 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
499 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
500 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
501 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
502 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
503 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
504 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
505 }
506
507 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800508 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100509 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
510 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
511 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
512 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
513 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
514 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
515 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
516 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
517 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
518 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
519 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
520 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
521 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
522 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
523 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
524 }
525
526 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800527 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100528 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
529 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
530 Assert.assertEquals(Math.round(2.0d), 2l);
531 Assert.assertEquals(Math.round(2.1d), 2l);
532 Assert.assertEquals(Math.round(2.5d), 3l);
533 Assert.assertEquals(Math.round(2.9d), 3l);
534 Assert.assertEquals(Math.round(3.0d), 3l);
535 Assert.assertEquals(Math.round(-2.0d), -2l);
536 Assert.assertEquals(Math.round(-2.1d), -2l);
537 Assert.assertEquals(Math.round(-2.5d), -2l);
538 Assert.assertEquals(Math.round(-2.9d), -3l);
539 Assert.assertEquals(Math.round(-3.0d), -3l);
540 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
541 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
542 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
543 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
544 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
545 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
546 }
547
548 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800549 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100550 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
551 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
552 Assert.assertEquals(Math.round(2.0f), 2);
553 Assert.assertEquals(Math.round(2.1f), 2);
554 Assert.assertEquals(Math.round(2.5f), 3);
555 Assert.assertEquals(Math.round(2.9f), 3);
556 Assert.assertEquals(Math.round(3.0f), 3);
557 Assert.assertEquals(Math.round(-2.0f), -2);
558 Assert.assertEquals(Math.round(-2.1f), -2);
559 Assert.assertEquals(Math.round(-2.5f), -2);
560 Assert.assertEquals(Math.round(-2.9f), -3);
561 Assert.assertEquals(Math.round(-3.0f), -3);
562 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
563 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
564 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
565 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
566 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
567 }
568
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100569 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800570 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100571 Assert.assertEquals(StrictMath.abs(0), 0);
572 Assert.assertEquals(StrictMath.abs(123), 123);
573 Assert.assertEquals(StrictMath.abs(-123), 123);
574 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
575 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
576 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
577 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
578 }
579
580 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800581 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100582 Assert.assertEquals(StrictMath.abs(0L), 0L);
583 Assert.assertEquals(StrictMath.abs(123L), 123L);
584 Assert.assertEquals(StrictMath.abs(-123L), 123L);
585 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
586 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
587 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
588 }
589
Serban Constantinescu23abec92014-07-02 16:13:38 +0100590 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800591 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100592 Assert.assertEquals(StrictMath.min(0, 0), 0);
593 Assert.assertEquals(StrictMath.min(1, 0), 0);
594 Assert.assertEquals(StrictMath.min(0, 1), 0);
595 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
596 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
597 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
598 }
599
Serban Constantinescu23abec92014-07-02 16:13:38 +0100600 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800601 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100602 Assert.assertEquals(StrictMath.max(0, 0), 0);
603 Assert.assertEquals(StrictMath.max(1, 0), 1);
604 Assert.assertEquals(StrictMath.max(0, 1), 1);
605 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
606 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
607 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
608 }
609
Serban Constantinescu23abec92014-07-02 16:13:38 +0100610 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800611 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100612 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
613 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
614 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
615 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
616 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
617 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
618 }
619
620 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800621 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100622 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
623 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
624 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
625 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
626 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
627 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
628 }
629
630 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800631 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700632 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
633 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
634 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
635 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
636 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
637 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
638 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
639 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
640 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
641 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
642 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100643 }
644
645 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800646 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700647 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
648 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
649 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
650 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
651 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
652 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
653 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
654 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
655 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
656 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
657 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100658 }
659
660 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800661 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700662 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
663 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
664 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
665 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
666 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
667 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
668 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
669 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
670 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
671 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
672 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100673 }
674
675 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800676 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700677 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
678 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
679 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
680 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
681 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
682 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
683 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
684 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
685 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
686 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
687 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100688 }
689
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800690 public static void test_StrictMath_sqrt() {
691 StrictMath.sqrt(+4.0);
692 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
693 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
694 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
695 }
696
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100697 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800698 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100699 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
700 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
701 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
702 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
703 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
704 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
705 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
706 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
707 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
708 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
709 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
710 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
711 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
712 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
713 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
714 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
715 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
716 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
717 }
718
719 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800720 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100721 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
722 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
723 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
724 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
725 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
726 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
727 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
728 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
729 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
730 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
731 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
732 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
733 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
734 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
735 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
736 }
737
738 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800739 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100740 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
741 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
742 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
743 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
744 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
745 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
746 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
747 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
748 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
749 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
750 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
751 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
752 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
753 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
754 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
755 }
756
757 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800758 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100759 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
760 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
761 Assert.assertEquals(StrictMath.round(2.0d), 2l);
762 Assert.assertEquals(StrictMath.round(2.1d), 2l);
763 Assert.assertEquals(StrictMath.round(2.5d), 3l);
764 Assert.assertEquals(StrictMath.round(2.9d), 3l);
765 Assert.assertEquals(StrictMath.round(3.0d), 3l);
766 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
767 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
768 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
769 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
770 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
771 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
772 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
773 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
774 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
775 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
776 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
777 }
778
779 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800780 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100781 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
782 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
783 Assert.assertEquals(StrictMath.round(2.0f), 2);
784 Assert.assertEquals(StrictMath.round(2.1f), 2);
785 Assert.assertEquals(StrictMath.round(2.5f), 3);
786 Assert.assertEquals(StrictMath.round(2.9f), 3);
787 Assert.assertEquals(StrictMath.round(3.0f), 3);
788 Assert.assertEquals(StrictMath.round(-2.0f), -2);
789 Assert.assertEquals(StrictMath.round(-2.1f), -2);
790 Assert.assertEquals(StrictMath.round(-2.5f), -2);
791 Assert.assertEquals(StrictMath.round(-2.9f), -3);
792 Assert.assertEquals(StrictMath.round(-3.0f), -3);
793 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
794 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
795 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
796 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
797 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
798 }
799
Elliott Hughes28c384b2012-06-15 16:46:25 -0700800 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800801 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700802 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
803 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
804 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
805 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
806 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
807 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
808 }
809
810 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800811 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700812 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
813 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
814 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
815 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
816 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
817 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
818 }
819
820 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800821 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700822 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
823 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
824 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
825 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
826 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
827 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
828 }
829
830 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800831 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700832 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
833 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
834 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
835 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
836 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
837 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
838 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100839
Zheng Xua3fe7422014-07-09 14:03:15 +0800840 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800841 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800842 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
843 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
844 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
845 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
846 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
847 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
848 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
849 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
850 }
851
852 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800853 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800854 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
855 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
856 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
857 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
858 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
859 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
860 }
861
862 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800863 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800864 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
865 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
866 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
867 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
868 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
869 }
870
Serban Constantinescu23abec92014-07-02 16:13:38 +0100871 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800872 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100873 Assert.assertEquals(Integer.reverse(1), 0x80000000);
874 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
875 Assert.assertEquals(Integer.reverse(0), 0);
876 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
877 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
878 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
879 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
880 }
881
882 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800883 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100884 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
885 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
886 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800887 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
888 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
889 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100890 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
891 }
892
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700893 static Object runtime;
894 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700895 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700896 static Method peek_byte;
897 static Method peek_short;
898 static Method peek_int;
899 static Method peek_long;
900 static Method poke_byte;
901 static Method poke_short;
902 static Method poke_int;
903 static Method poke_long;
904
905 public static void initSupportMethodsForPeekPoke() throws Exception {
906 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
907 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
908 runtime = get_runtime.invoke(null);
909 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700910 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700911
912 Class<?> io_memory = Class.forName("libcore.io.Memory");
913 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
914 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
915 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
916 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
917 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
918 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
919 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
920 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
921 }
922
923 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700924 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700925 b[0] = 0x12;
926 b[1] = 0x11;
927 long address = (long)address_of.invoke(runtime, b);
928 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
929 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
930 }
931
932 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700933 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700934 b[0] = 0x13;
935 b[1] = 0x12;
936 b[2] = 0x11;
937 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800938 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700939 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
940 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
941 }
942
943 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700944 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700945 b[0] = 0x15;
946 b[1] = 0x14;
947 b[2] = 0x13;
948 b[3] = 0x12;
949 b[4] = 0x11;
950 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800951 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700952 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
953 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
954 }
955
956 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700957 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700958 b[0] = 0x19;
959 b[1] = 0x18;
960 b[2] = 0x17;
961 b[3] = 0x16;
962 b[4] = 0x15;
963 b[5] = 0x14;
964 b[6] = 0x13;
965 b[7] = 0x12;
966 b[8] = 0x11;
967 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800968 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700969 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
970 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
971 }
972
973 public static void test_Memory_pokeByte() throws Exception {
974 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700975 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700976 long address = (long)address_of.invoke(runtime, b);
977 poke_byte.invoke(null, address, (byte)0x11);
978 poke_byte.invoke(null, address + 1, (byte)0x12);
979 Assert.assertTrue(Arrays.equals(r, b));
980 }
981
982 public static void test_Memory_pokeShort() throws Exception {
983 byte[] ra = {0x12, 0x11, 0x13};
984 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700985 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700986 long address = (long)address_of.invoke(runtime, b);
987
988 // Aligned write
989 b[2] = 0x13;
990 poke_short.invoke(null, address, (short)0x1112, false);
991 Assert.assertTrue(Arrays.equals(ra, b));
992
993 // Unaligned write
994 poke_short.invoke(null, address + 1, (short)0x2122, false);
995 Assert.assertTrue(Arrays.equals(ru, b));
996 }
997
998 public static void test_Memory_pokeInt() throws Exception {
999 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1000 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001001 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001002 long address = (long)address_of.invoke(runtime, b);
1003
1004 b[4] = 0x15;
1005 poke_int.invoke(null, address, (int)0x11121314, false);
1006 Assert.assertTrue(Arrays.equals(ra, b));
1007
1008 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1009 Assert.assertTrue(Arrays.equals(ru, b));
1010 }
1011
1012 public static void test_Memory_pokeLong() throws Exception {
1013 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1014 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001015 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001016 long address = (long)address_of.invoke(runtime, b);
1017
1018 b[8] = 0x19;
1019 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1020 Assert.assertTrue(Arrays.equals(ra, b));
1021
1022 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1023 Assert.assertTrue(Arrays.equals(ru, b));
1024 }
jeffhao5d1ac922011-09-29 17:41:15 -07001025}