blob: a737ccdb791ee40e68bee5c3b33c960045182750 [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));
133 Assert.assertEquals('e', testStr.charAt(testStr.length()-1));
134
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800135 test_String_charAtExc();
136 test_String_charAtExc2();
137 }
138
139 private static void test_String_charAtExc() {
140 String testStr = "Now is the time";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700141 try {
142 testStr.charAt(-1);
143 Assert.fail();
144 } catch (StringIndexOutOfBoundsException expected) {
145 }
146 try {
147 testStr.charAt(80);
148 Assert.fail();
149 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700150 }
151
Elliott Hughes28c384b2012-06-15 16:46:25 -0700152 String strNull = null;
153 try {
154 strNull.charAt(0);
155 Assert.fail();
156 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700157 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700158 }
jeffhao5d1ac922011-09-29 17:41:15 -0700159
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800160 private static void test_String_charAtExc2() {
161 try {
162 test_String_charAtExc3();
163 Assert.fail();
164 } catch (StringIndexOutOfBoundsException expected) {
165 }
166 }
167
168 private static void test_String_charAtExc3() {
169 String testStr = "Now is the time";
170 Assert.assertEquals('N', testStr.charAt(-1));
171 }
172
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700173 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700174 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700175 public static void test_String_indexOf() {
176 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700177 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700178 String str3 = "abc";
179 String str10 = "abcdefghij";
180 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700181
Elliott Hughes28c384b2012-06-15 16:46:25 -0700182 int supplementaryChar = 0x20b9f;
183 String surrogatePair = "\ud842\udf9f";
184 String stringWithSurrogates = "hello " + surrogatePair + " world";
jeffhao5d1ac922011-09-29 17:41:15 -0700185
Elliott Hughes28c384b2012-06-15 16:46:25 -0700186 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
187 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
188 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
189 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
jeffhao5d1ac922011-09-29 17:41:15 -0700190
Elliott Hughes28c384b2012-06-15 16:46:25 -0700191 Assert.assertEquals(str0.indexOf('a'), -1);
192 Assert.assertEquals(str3.indexOf('a'), 0);
193 Assert.assertEquals(str3.indexOf('b'), 1);
194 Assert.assertEquals(str3.indexOf('c'), 2);
195 Assert.assertEquals(str10.indexOf('j'), 9);
196 Assert.assertEquals(str40.indexOf('a'), 0);
197 Assert.assertEquals(str40.indexOf('b'), 38);
198 Assert.assertEquals(str40.indexOf('c'), 39);
199 Assert.assertEquals(str0.indexOf('a',20), -1);
200 Assert.assertEquals(str0.indexOf('a',0), -1);
201 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700202 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700203 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700204 Assert.assertEquals(str3.indexOf('a',0), 0);
205 Assert.assertEquals(str3.indexOf('a',1), -1);
206 Assert.assertEquals(str3.indexOf('a',1234), -1);
207 Assert.assertEquals(str3.indexOf('b',0), 1);
208 Assert.assertEquals(str3.indexOf('b',1), 1);
209 Assert.assertEquals(str3.indexOf('c',2), 2);
210 Assert.assertEquals(str10.indexOf('j',5), 9);
211 Assert.assertEquals(str10.indexOf('j',9), 9);
212 Assert.assertEquals(str40.indexOf('a',10), 10);
213 Assert.assertEquals(str40.indexOf('b',40), -1);
214
215 String strNull = null;
216 try {
217 strNull.indexOf('a');
218 Assert.fail();
219 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700220 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700221 try {
222 strNull.indexOf('a', 0);
223 Assert.fail();
224 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700225 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700226 try {
227 strNull.indexOf('a', -1);
228 Assert.fail();
229 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700230 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700231 }
jeffhao5d1ac922011-09-29 17:41:15 -0700232
Elliott Hughes28c384b2012-06-15 16:46:25 -0700233 public static void test_String_compareTo() {
234 String test = "0123456789";
235 String test1 = new String("0123456789"); // different object
236 String test2 = new String("0123456780"); // different value
237 String offset = new String("xxx0123456789yyy");
238 String sub = offset.substring(3, 13);
239 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
240 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
241 String lc = "abcdefg";
242 String uc = "ABCDEFG";
243 Object blah = new Object();
244
245 Assert.assertTrue(lc.toUpperCase().equals(uc));
246
247 Assert.assertEquals(str32.compareTo(str33), -1);
248 Assert.assertEquals(str33.compareTo(str32), 1);
249
250 Assert.assertTrue(test.equals(test));
251 Assert.assertTrue(test.equals(test1));
252 Assert.assertFalse(test.equals(test2));
253
254 Assert.assertEquals(test.compareTo(test1), 0);
255 Assert.assertTrue(test1.compareTo(test2) > 0);
256 Assert.assertTrue(test2.compareTo(test1) < 0);
257
258 // Compare string with a nonzero offset, in left/right side.
259 Assert.assertEquals(test.compareTo(sub), 0);
260 Assert.assertEquals(sub.compareTo(test), 0);
261 Assert.assertTrue(test.equals(sub));
262 Assert.assertTrue(sub.equals(test));
263 // Same base, one is a substring.
264 Assert.assertFalse(offset.equals(sub));
265 Assert.assertFalse(sub.equals(offset));
266 // Wrong class.
267 Assert.assertFalse(test.equals(blah));
268
269 // Null lhs - throw.
270 try {
271 test.compareTo(null);
272 Assert.fail("didn't get expected npe");
273 } catch (NullPointerException npe) {
274 }
275 // Null rhs - okay.
276 Assert.assertFalse(test.equals(null));
277
278 test = test.substring(1);
279 Assert.assertTrue(test.equals("123456789"));
280 Assert.assertFalse(test.equals(test1));
281
282 test = test.substring(1);
283 Assert.assertTrue(test.equals("23456789"));
284
285 test = test.substring(1);
286 Assert.assertTrue(test.equals("3456789"));
287
288 test = test.substring(1);
289 Assert.assertTrue(test.equals("456789"));
290
291 test = test.substring(3,5);
292 Assert.assertTrue(test.equals("78"));
293
294 test = "this/is/a/path";
295 String[] strings = test.split("/");
296 Assert.assertEquals(4, strings.length);
297
298 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
299 Assert.assertEquals("this is a path", test.replace("/", " "));
300 }
301
302 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800303 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700304 Assert.assertEquals(Math.abs(0), 0);
305 Assert.assertEquals(Math.abs(123), 123);
306 Assert.assertEquals(Math.abs(-123), 123);
307 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
308 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
309 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100310 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700311 }
312
313 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800314 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700315 Assert.assertEquals(Math.abs(0L), 0L);
316 Assert.assertEquals(Math.abs(123L), 123L);
317 Assert.assertEquals(Math.abs(-123L), 123L);
318 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
319 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
320 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
321 }
322
Serban Constantinescu23abec92014-07-02 16:13:38 +0100323 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800324 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700325 Assert.assertEquals(Math.min(0, 0), 0);
326 Assert.assertEquals(Math.min(1, 0), 0);
327 Assert.assertEquals(Math.min(0, 1), 0);
328 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
329 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
330 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
331 }
332
Serban Constantinescu23abec92014-07-02 16:13:38 +0100333 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800334 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700335 Assert.assertEquals(Math.max(0, 0), 0);
336 Assert.assertEquals(Math.max(1, 0), 1);
337 Assert.assertEquals(Math.max(0, 1), 1);
338 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
339 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
340 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
341 }
342
Serban Constantinescu23abec92014-07-02 16:13:38 +0100343 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800344 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100345 Assert.assertEquals(Math.min(0L, 0L), 0L);
346 Assert.assertEquals(Math.min(1L, 0L), 0L);
347 Assert.assertEquals(Math.min(0L, 1L), 0L);
348 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
349 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
350 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
351 }
352
353 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800354 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100355 Assert.assertEquals(Math.max(0L, 0L), 0L);
356 Assert.assertEquals(Math.max(1L, 0L), 1L);
357 Assert.assertEquals(Math.max(0L, 1L), 1L);
358 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
359 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
360 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
361 }
362
363 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800364 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700365 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
366 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
367 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
368 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
369 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
370 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
371 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
372 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
373 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
374 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
375 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100376 }
377
378 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800379 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700380 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
381 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
382 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
383 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
384 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
385 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
386 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
387 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
388 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
389 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
390 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100391 }
392
393 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800394 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700395 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
396 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
397 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
398 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
399 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
400 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
401 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
402 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
403 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
404 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
405 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100406 }
407
408 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800409 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700410 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
411 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
412 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
413 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
414 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
415 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
416 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
417 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
418 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
419 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
420 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100421 }
422
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800423 public static void test_Math_sqrt() {
424 Math.sqrt(+4.0);
425 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
426 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
427 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
428 }
429
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100430 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800431 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100432 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
433 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
434 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
435 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
436 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
437 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
438 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
439 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
440 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
441 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
442 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
443 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
444 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
445 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
446 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
447 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
448 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
449 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
450 }
451
452 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800453 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100454 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
455 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
456 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
457 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
458 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
459 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
460 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
461 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
462 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
463 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
464 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
465 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
466 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
467 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
468 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
469 }
470
471 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800472 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100473 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
474 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
475 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
476 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
477 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
478 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
479 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
480 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
481 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
482 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
483 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
484 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
485 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
486 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
487 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
488 }
489
490 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800491 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100492 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
493 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
494 Assert.assertEquals(Math.round(2.0d), 2l);
495 Assert.assertEquals(Math.round(2.1d), 2l);
496 Assert.assertEquals(Math.round(2.5d), 3l);
497 Assert.assertEquals(Math.round(2.9d), 3l);
498 Assert.assertEquals(Math.round(3.0d), 3l);
499 Assert.assertEquals(Math.round(-2.0d), -2l);
500 Assert.assertEquals(Math.round(-2.1d), -2l);
501 Assert.assertEquals(Math.round(-2.5d), -2l);
502 Assert.assertEquals(Math.round(-2.9d), -3l);
503 Assert.assertEquals(Math.round(-3.0d), -3l);
504 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
505 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
506 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
507 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
508 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
509 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
510 }
511
512 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800513 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100514 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
515 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
516 Assert.assertEquals(Math.round(2.0f), 2);
517 Assert.assertEquals(Math.round(2.1f), 2);
518 Assert.assertEquals(Math.round(2.5f), 3);
519 Assert.assertEquals(Math.round(2.9f), 3);
520 Assert.assertEquals(Math.round(3.0f), 3);
521 Assert.assertEquals(Math.round(-2.0f), -2);
522 Assert.assertEquals(Math.round(-2.1f), -2);
523 Assert.assertEquals(Math.round(-2.5f), -2);
524 Assert.assertEquals(Math.round(-2.9f), -3);
525 Assert.assertEquals(Math.round(-3.0f), -3);
526 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
527 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
528 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
529 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
530 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
531 }
532
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100533 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800534 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100535 Assert.assertEquals(StrictMath.abs(0), 0);
536 Assert.assertEquals(StrictMath.abs(123), 123);
537 Assert.assertEquals(StrictMath.abs(-123), 123);
538 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
539 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
540 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
541 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
542 }
543
544 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800545 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100546 Assert.assertEquals(StrictMath.abs(0L), 0L);
547 Assert.assertEquals(StrictMath.abs(123L), 123L);
548 Assert.assertEquals(StrictMath.abs(-123L), 123L);
549 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
550 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
551 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
552 }
553
Serban Constantinescu23abec92014-07-02 16:13:38 +0100554 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800555 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100556 Assert.assertEquals(StrictMath.min(0, 0), 0);
557 Assert.assertEquals(StrictMath.min(1, 0), 0);
558 Assert.assertEquals(StrictMath.min(0, 1), 0);
559 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
560 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
561 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
562 }
563
Serban Constantinescu23abec92014-07-02 16:13:38 +0100564 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800565 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100566 Assert.assertEquals(StrictMath.max(0, 0), 0);
567 Assert.assertEquals(StrictMath.max(1, 0), 1);
568 Assert.assertEquals(StrictMath.max(0, 1), 1);
569 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
570 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
571 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
572 }
573
Serban Constantinescu23abec92014-07-02 16:13:38 +0100574 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800575 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100576 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
577 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
578 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
579 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
580 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
581 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
582 }
583
584 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800585 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100586 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
587 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
588 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
589 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
590 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
591 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
592 }
593
594 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800595 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700596 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
597 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
598 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
599 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
600 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
601 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
602 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
603 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
604 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
605 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
606 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100607 }
608
609 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800610 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700611 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
612 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
613 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
614 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
615 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
616 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
617 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
618 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
619 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
620 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
621 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100622 }
623
624 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800625 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700626 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
627 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
628 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
629 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
630 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
631 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
632 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
633 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
634 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
635 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
636 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100637 }
638
639 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800640 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700641 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
642 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
643 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
644 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
645 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
646 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
647 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
648 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
649 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
650 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
651 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100652 }
653
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800654 public static void test_StrictMath_sqrt() {
655 StrictMath.sqrt(+4.0);
656 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
657 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
658 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
659 }
660
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100661 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800662 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100663 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
664 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
665 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
666 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
667 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
668 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
669 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
670 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
671 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
672 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
673 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
674 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
675 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
676 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
677 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
678 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
679 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
680 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
681 }
682
683 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800684 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100685 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
686 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
687 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
688 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
689 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
690 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
691 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
692 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
693 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
694 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
695 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
696 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
697 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
698 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
699 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
700 }
701
702 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800703 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100704 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
705 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
706 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
707 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
708 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
709 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
710 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
711 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
712 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
713 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
714 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
715 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
716 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
717 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
718 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
719 }
720
721 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800722 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100723 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
724 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
725 Assert.assertEquals(StrictMath.round(2.0d), 2l);
726 Assert.assertEquals(StrictMath.round(2.1d), 2l);
727 Assert.assertEquals(StrictMath.round(2.5d), 3l);
728 Assert.assertEquals(StrictMath.round(2.9d), 3l);
729 Assert.assertEquals(StrictMath.round(3.0d), 3l);
730 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
731 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
732 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
733 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
734 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
735 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
736 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
737 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
738 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
739 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
740 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
741 }
742
743 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800744 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100745 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
746 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
747 Assert.assertEquals(StrictMath.round(2.0f), 2);
748 Assert.assertEquals(StrictMath.round(2.1f), 2);
749 Assert.assertEquals(StrictMath.round(2.5f), 3);
750 Assert.assertEquals(StrictMath.round(2.9f), 3);
751 Assert.assertEquals(StrictMath.round(3.0f), 3);
752 Assert.assertEquals(StrictMath.round(-2.0f), -2);
753 Assert.assertEquals(StrictMath.round(-2.1f), -2);
754 Assert.assertEquals(StrictMath.round(-2.5f), -2);
755 Assert.assertEquals(StrictMath.round(-2.9f), -3);
756 Assert.assertEquals(StrictMath.round(-3.0f), -3);
757 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
758 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
759 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
760 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
761 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
762 }
763
Elliott Hughes28c384b2012-06-15 16:46:25 -0700764 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800765 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700766 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
767 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
768 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
769 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
770 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
771 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
772 }
773
774 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800775 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700776 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
777 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
778 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
779 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
780 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
781 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
782 }
783
784 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800785 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700786 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
787 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
788 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
789 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
790 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
791 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
792 }
793
794 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800795 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700796 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
797 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
798 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
799 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
800 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
801 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
802 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100803
Zheng Xua3fe7422014-07-09 14:03:15 +0800804 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800805 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800806 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
807 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
808 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
809 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
810 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
811 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
812 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
813 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
814 }
815
816 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800817 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800818 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
819 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
820 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
821 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
822 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
823 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
824 }
825
826 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800827 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800828 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
829 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
830 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
831 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
832 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
833 }
834
Serban Constantinescu23abec92014-07-02 16:13:38 +0100835 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800836 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100837 Assert.assertEquals(Integer.reverse(1), 0x80000000);
838 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
839 Assert.assertEquals(Integer.reverse(0), 0);
840 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
841 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
842 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
843 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
844 }
845
846 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800847 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100848 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
849 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
850 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800851 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
852 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
853 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100854 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
855 }
856
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700857 static Object runtime;
858 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700859 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700860 static Method peek_byte;
861 static Method peek_short;
862 static Method peek_int;
863 static Method peek_long;
864 static Method poke_byte;
865 static Method poke_short;
866 static Method poke_int;
867 static Method poke_long;
868
869 public static void initSupportMethodsForPeekPoke() throws Exception {
870 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
871 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
872 runtime = get_runtime.invoke(null);
873 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700874 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700875
876 Class<?> io_memory = Class.forName("libcore.io.Memory");
877 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
878 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
879 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
880 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
881 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
882 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
883 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
884 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
885 }
886
887 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700888 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700889 b[0] = 0x12;
890 b[1] = 0x11;
891 long address = (long)address_of.invoke(runtime, b);
892 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
893 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
894 }
895
896 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700897 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700898 b[0] = 0x13;
899 b[1] = 0x12;
900 b[2] = 0x11;
901 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800902 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700903 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
904 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
905 }
906
907 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700908 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700909 b[0] = 0x15;
910 b[1] = 0x14;
911 b[2] = 0x13;
912 b[3] = 0x12;
913 b[4] = 0x11;
914 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800915 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700916 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
917 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
918 }
919
920 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700921 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700922 b[0] = 0x19;
923 b[1] = 0x18;
924 b[2] = 0x17;
925 b[3] = 0x16;
926 b[4] = 0x15;
927 b[5] = 0x14;
928 b[6] = 0x13;
929 b[7] = 0x12;
930 b[8] = 0x11;
931 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800932 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700933 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
934 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
935 }
936
937 public static void test_Memory_pokeByte() throws Exception {
938 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700939 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700940 long address = (long)address_of.invoke(runtime, b);
941 poke_byte.invoke(null, address, (byte)0x11);
942 poke_byte.invoke(null, address + 1, (byte)0x12);
943 Assert.assertTrue(Arrays.equals(r, b));
944 }
945
946 public static void test_Memory_pokeShort() throws Exception {
947 byte[] ra = {0x12, 0x11, 0x13};
948 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700949 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700950 long address = (long)address_of.invoke(runtime, b);
951
952 // Aligned write
953 b[2] = 0x13;
954 poke_short.invoke(null, address, (short)0x1112, false);
955 Assert.assertTrue(Arrays.equals(ra, b));
956
957 // Unaligned write
958 poke_short.invoke(null, address + 1, (short)0x2122, false);
959 Assert.assertTrue(Arrays.equals(ru, b));
960 }
961
962 public static void test_Memory_pokeInt() throws Exception {
963 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
964 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700965 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700966 long address = (long)address_of.invoke(runtime, b);
967
968 b[4] = 0x15;
969 poke_int.invoke(null, address, (int)0x11121314, false);
970 Assert.assertTrue(Arrays.equals(ra, b));
971
972 poke_int.invoke(null, address + 1, (int)0x21222324, false);
973 Assert.assertTrue(Arrays.equals(ru, b));
974 }
975
976 public static void test_Memory_pokeLong() throws Exception {
977 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
978 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700979 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700980 long address = (long)address_of.invoke(runtime, b);
981
982 b[8] = 0x19;
983 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
984 Assert.assertTrue(Arrays.equals(ra, b));
985
986 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
987 Assert.assertTrue(Arrays.equals(ru, b));
988 }
jeffhao5d1ac922011-09-29 17:41:15 -0700989}