blob: abd6cb88d444d2119bb0aa3d10e44baa15954a43 [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() {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800128 String testStr = "Now is the time to test some stuff";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700129
Andreas Gampe878d58c2015-01-15 23:24:00 -0800130 Assert.assertEquals(testStr.length() - 1, 33); // 33 = testStr.length()-1 as a constant.
131 Assert.assertEquals('f', testStr.charAt(33));
Elliott Hughes28c384b2012-06-15 16:46:25 -0700132
Andreas Gampe878d58c2015-01-15 23:24:00 -0800133 test_String_charAt(testStr, 'N', 'o', ' ', 'f');
134 test_String_charAt(testStr.substring(3,15), ' ', 'i', 'm', 'e');
135 }
136 public static void test_String_charAt(String testStr, char a, char b, char c, char d) {
137 Assert.assertEquals(a, testStr.charAt(0));
138 Assert.assertEquals(b, testStr.charAt(1));
139 Assert.assertEquals(c, testStr.charAt(10));
140 Assert.assertEquals(d, testStr.charAt(testStr.length()-1));
141
142 test_String_charAtExc(testStr);
143 test_String_charAtExc2(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800144 }
145
Andreas Gampe878d58c2015-01-15 23:24:00 -0800146 private static void test_String_charAtExc(String testStr) {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700147 try {
148 testStr.charAt(-1);
149 Assert.fail();
150 } catch (StringIndexOutOfBoundsException expected) {
151 }
152 try {
153 testStr.charAt(80);
154 Assert.fail();
155 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700156 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000157 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800158 if (testStr.length() == 34) {
159 testStr.charAt(34); // 34 = "Now is the time to test some stuff".length()
160 } else {
161 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
162 testStr.charAt(12);
163 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000164 Assert.fail();
165 } catch (StringIndexOutOfBoundsException expected) {
166 }
167 try {
168 test_String_charAt_inner(testStr, -1);
169 Assert.fail();
170 } catch (StringIndexOutOfBoundsException expected) {
171 }
172 try {
173 test_String_charAt_inner(testStr, 80);
174 Assert.fail();
175 } catch (StringIndexOutOfBoundsException expected) {
176 }
177 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800178 if (testStr.length() == 34) {
179 // 34 = "Now is the time to test some stuff".length()
180 test_String_charAt_inner(testStr, 34);
181 } else {
182 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
183 test_String_charAt_inner(testStr, 12);
184 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000185 Assert.fail();
186 } catch (StringIndexOutOfBoundsException expected) {
187 }
188
189 String strEmpty = "";
190 try {
191 strEmpty.charAt(0);
192 Assert.fail();
193 } catch (StringIndexOutOfBoundsException expected) {
194 }
jeffhao5d1ac922011-09-29 17:41:15 -0700195
Elliott Hughes28c384b2012-06-15 16:46:25 -0700196 String strNull = null;
197 try {
198 strNull.charAt(0);
199 Assert.fail();
200 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700201 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700202 }
jeffhao5d1ac922011-09-29 17:41:15 -0700203
Vladimir Marko00ca8472015-01-26 14:06:46 +0000204 private static char test_String_charAt_inner(String s, int index) {
205 // Using non-constant index here (assuming that this method wasn't inlined).
206 return s.charAt(index);
207 }
208
Andreas Gampe878d58c2015-01-15 23:24:00 -0800209 private static void test_String_charAtExc2(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800210 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800211 test_String_charAtExc3(testStr);
212 Assert.fail();
213 } catch (StringIndexOutOfBoundsException expected) {
214 }
215 try {
216 test_String_charAtExc4(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800217 Assert.fail();
218 } catch (StringIndexOutOfBoundsException expected) {
219 }
220 }
221
Andreas Gampe878d58c2015-01-15 23:24:00 -0800222 private static void test_String_charAtExc3(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800223 Assert.assertEquals('N', testStr.charAt(-1));
224 }
225
Andreas Gampe878d58c2015-01-15 23:24:00 -0800226 private static void test_String_charAtExc4(String testStr) {
227 Assert.assertEquals('N', testStr.charAt(100));
228 }
229
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700230 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700231 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700232 public static void test_String_indexOf() {
233 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700234 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700235 String str3 = "abc";
236 String str10 = "abcdefghij";
237 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700238
Elliott Hughes28c384b2012-06-15 16:46:25 -0700239 Assert.assertEquals(str0.indexOf('a'), -1);
240 Assert.assertEquals(str3.indexOf('a'), 0);
241 Assert.assertEquals(str3.indexOf('b'), 1);
242 Assert.assertEquals(str3.indexOf('c'), 2);
243 Assert.assertEquals(str10.indexOf('j'), 9);
244 Assert.assertEquals(str40.indexOf('a'), 0);
245 Assert.assertEquals(str40.indexOf('b'), 38);
246 Assert.assertEquals(str40.indexOf('c'), 39);
247 Assert.assertEquals(str0.indexOf('a',20), -1);
248 Assert.assertEquals(str0.indexOf('a',0), -1);
249 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700250 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700251 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700252 Assert.assertEquals(str3.indexOf('a',0), 0);
253 Assert.assertEquals(str3.indexOf('a',1), -1);
254 Assert.assertEquals(str3.indexOf('a',1234), -1);
255 Assert.assertEquals(str3.indexOf('b',0), 1);
256 Assert.assertEquals(str3.indexOf('b',1), 1);
257 Assert.assertEquals(str3.indexOf('c',2), 2);
258 Assert.assertEquals(str10.indexOf('j',5), 9);
259 Assert.assertEquals(str10.indexOf('j',9), 9);
260 Assert.assertEquals(str40.indexOf('a',10), 10);
261 Assert.assertEquals(str40.indexOf('b',40), -1);
262
Andreas Gampe678e6952015-05-07 16:44:58 -0700263 testIndexOfNull();
264
265 testSurrogateIndexOf();
266 }
267
268 private static void testSurrogateIndexOf() {
269 int supplementaryChar = 0x20b9f;
270 String surrogatePair = "\ud842\udf9f";
271 String stringWithSurrogates = "hello " + surrogatePair + " world";
272
273 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
274 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
275 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
276 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
277 }
278
279 private static void testIndexOfNull() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700280 String strNull = null;
281 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700282 testNullIndex(strNull, 'a');
Elliott Hughes28c384b2012-06-15 16:46:25 -0700283 Assert.fail();
284 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700285 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700286 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700287 testNullIndex(strNull, 'a', 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700288 Assert.fail();
289 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700290 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700291 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700292 testNullIndex(strNull, 'a', -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700293 Assert.fail();
294 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700295 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700296 }
jeffhao5d1ac922011-09-29 17:41:15 -0700297
Andreas Gampe678e6952015-05-07 16:44:58 -0700298 private static int testNullIndex(String strNull, int c) {
299 return strNull.indexOf(c);
300 }
301
302 private static int testNullIndex(String strNull, int c, int startIndex) {
303 return strNull.indexOf(c, startIndex);
304 }
305
Elliott Hughes28c384b2012-06-15 16:46:25 -0700306 public static void test_String_compareTo() {
307 String test = "0123456789";
308 String test1 = new String("0123456789"); // different object
309 String test2 = new String("0123456780"); // different value
310 String offset = new String("xxx0123456789yyy");
311 String sub = offset.substring(3, 13);
312 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
313 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
314 String lc = "abcdefg";
315 String uc = "ABCDEFG";
316 Object blah = new Object();
317
318 Assert.assertTrue(lc.toUpperCase().equals(uc));
319
320 Assert.assertEquals(str32.compareTo(str33), -1);
321 Assert.assertEquals(str33.compareTo(str32), 1);
322
323 Assert.assertTrue(test.equals(test));
324 Assert.assertTrue(test.equals(test1));
325 Assert.assertFalse(test.equals(test2));
326
327 Assert.assertEquals(test.compareTo(test1), 0);
328 Assert.assertTrue(test1.compareTo(test2) > 0);
329 Assert.assertTrue(test2.compareTo(test1) < 0);
330
331 // Compare string with a nonzero offset, in left/right side.
332 Assert.assertEquals(test.compareTo(sub), 0);
333 Assert.assertEquals(sub.compareTo(test), 0);
334 Assert.assertTrue(test.equals(sub));
335 Assert.assertTrue(sub.equals(test));
336 // Same base, one is a substring.
337 Assert.assertFalse(offset.equals(sub));
338 Assert.assertFalse(sub.equals(offset));
339 // Wrong class.
340 Assert.assertFalse(test.equals(blah));
341
342 // Null lhs - throw.
343 try {
344 test.compareTo(null);
345 Assert.fail("didn't get expected npe");
346 } catch (NullPointerException npe) {
347 }
348 // Null rhs - okay.
349 Assert.assertFalse(test.equals(null));
350
351 test = test.substring(1);
352 Assert.assertTrue(test.equals("123456789"));
353 Assert.assertFalse(test.equals(test1));
354
355 test = test.substring(1);
356 Assert.assertTrue(test.equals("23456789"));
357
358 test = test.substring(1);
359 Assert.assertTrue(test.equals("3456789"));
360
361 test = test.substring(1);
362 Assert.assertTrue(test.equals("456789"));
363
364 test = test.substring(3,5);
365 Assert.assertTrue(test.equals("78"));
366
367 test = "this/is/a/path";
368 String[] strings = test.split("/");
369 Assert.assertEquals(4, strings.length);
370
371 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
372 Assert.assertEquals("this is a path", test.replace("/", " "));
373 }
374
375 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800376 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700377 Assert.assertEquals(Math.abs(0), 0);
378 Assert.assertEquals(Math.abs(123), 123);
379 Assert.assertEquals(Math.abs(-123), 123);
380 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
381 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
382 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100383 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700384 }
385
386 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800387 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700388 Assert.assertEquals(Math.abs(0L), 0L);
389 Assert.assertEquals(Math.abs(123L), 123L);
390 Assert.assertEquals(Math.abs(-123L), 123L);
391 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
392 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
393 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800394 Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700395 }
396
Serban Constantinescu23abec92014-07-02 16:13:38 +0100397 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800398 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700399 Assert.assertEquals(Math.min(0, 0), 0);
400 Assert.assertEquals(Math.min(1, 0), 0);
401 Assert.assertEquals(Math.min(0, 1), 0);
402 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
403 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
404 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
405 }
406
Serban Constantinescu23abec92014-07-02 16:13:38 +0100407 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800408 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700409 Assert.assertEquals(Math.max(0, 0), 0);
410 Assert.assertEquals(Math.max(1, 0), 1);
411 Assert.assertEquals(Math.max(0, 1), 1);
412 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
413 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
414 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
415 }
416
Serban Constantinescu23abec92014-07-02 16:13:38 +0100417 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800418 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100419 Assert.assertEquals(Math.min(0L, 0L), 0L);
420 Assert.assertEquals(Math.min(1L, 0L), 0L);
421 Assert.assertEquals(Math.min(0L, 1L), 0L);
422 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
423 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
424 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
425 }
426
427 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800428 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100429 Assert.assertEquals(Math.max(0L, 0L), 0L);
430 Assert.assertEquals(Math.max(1L, 0L), 1L);
431 Assert.assertEquals(Math.max(0L, 1L), 1L);
432 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
433 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
434 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
435 }
436
437 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800438 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700439 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
440 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
441 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
442 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
443 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
444 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
445 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
446 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
447 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
448 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
449 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100450 }
451
452 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800453 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700454 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
455 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
456 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
457 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
458 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
459 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
460 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
461 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
462 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
463 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
464 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100465 }
466
467 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800468 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700469 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
470 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
471 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
472 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
473 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
474 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
475 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
476 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
477 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
478 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
479 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100480 }
481
482 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800483 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700484 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
485 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
486 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
487 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
488 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
489 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
490 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
491 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
492 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
493 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
494 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100495 }
496
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800497 public static void test_Math_sqrt() {
498 Math.sqrt(+4.0);
499 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
500 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
501 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
502 }
503
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100504 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800505 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100506 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
507 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
508 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
509 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
510 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
511 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
512 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
513 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
514 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
515 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
516 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
517 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
518 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
519 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
520 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
521 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
522 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
523 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
524 }
525
526 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800527 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100528 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
529 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
530 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
531 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
532 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
533 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
534 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
535 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
536 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
537 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
538 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
539 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
540 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
541 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
542 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
543 }
544
545 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800546 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100547 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
548 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
549 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
550 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
551 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
552 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
553 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
554 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
555 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
556 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
557 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
558 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
559 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
560 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
561 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
562 }
563
564 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800565 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100566 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
567 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
568 Assert.assertEquals(Math.round(2.0d), 2l);
569 Assert.assertEquals(Math.round(2.1d), 2l);
570 Assert.assertEquals(Math.round(2.5d), 3l);
571 Assert.assertEquals(Math.round(2.9d), 3l);
572 Assert.assertEquals(Math.round(3.0d), 3l);
573 Assert.assertEquals(Math.round(-2.0d), -2l);
574 Assert.assertEquals(Math.round(-2.1d), -2l);
575 Assert.assertEquals(Math.round(-2.5d), -2l);
576 Assert.assertEquals(Math.round(-2.9d), -3l);
577 Assert.assertEquals(Math.round(-3.0d), -3l);
578 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
579 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
580 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
581 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
582 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
583 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
584 }
585
586 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800587 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100588 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
589 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
590 Assert.assertEquals(Math.round(2.0f), 2);
591 Assert.assertEquals(Math.round(2.1f), 2);
592 Assert.assertEquals(Math.round(2.5f), 3);
593 Assert.assertEquals(Math.round(2.9f), 3);
594 Assert.assertEquals(Math.round(3.0f), 3);
595 Assert.assertEquals(Math.round(-2.0f), -2);
596 Assert.assertEquals(Math.round(-2.1f), -2);
597 Assert.assertEquals(Math.round(-2.5f), -2);
598 Assert.assertEquals(Math.round(-2.9f), -3);
599 Assert.assertEquals(Math.round(-3.0f), -3);
600 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
601 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
602 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
603 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
604 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
605 }
606
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100607 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800608 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100609 Assert.assertEquals(StrictMath.abs(0), 0);
610 Assert.assertEquals(StrictMath.abs(123), 123);
611 Assert.assertEquals(StrictMath.abs(-123), 123);
612 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
613 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
614 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
615 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
616 }
617
618 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800619 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100620 Assert.assertEquals(StrictMath.abs(0L), 0L);
621 Assert.assertEquals(StrictMath.abs(123L), 123L);
622 Assert.assertEquals(StrictMath.abs(-123L), 123L);
623 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
624 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
625 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
626 }
627
Serban Constantinescu23abec92014-07-02 16:13:38 +0100628 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800629 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100630 Assert.assertEquals(StrictMath.min(0, 0), 0);
631 Assert.assertEquals(StrictMath.min(1, 0), 0);
632 Assert.assertEquals(StrictMath.min(0, 1), 0);
633 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
634 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
635 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
636 }
637
Serban Constantinescu23abec92014-07-02 16:13:38 +0100638 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800639 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100640 Assert.assertEquals(StrictMath.max(0, 0), 0);
641 Assert.assertEquals(StrictMath.max(1, 0), 1);
642 Assert.assertEquals(StrictMath.max(0, 1), 1);
643 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
644 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
645 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
646 }
647
Serban Constantinescu23abec92014-07-02 16:13:38 +0100648 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800649 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100650 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
651 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
652 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
653 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
654 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
655 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
656 }
657
658 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800659 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100660 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
661 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
662 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
663 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
664 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
665 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
666 }
667
668 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800669 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700670 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
671 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
672 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
673 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
674 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
675 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
676 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
677 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
678 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
679 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
680 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100681 }
682
683 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800684 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700685 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
686 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
687 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
688 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
689 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
690 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
691 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
692 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
693 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
694 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
695 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100696 }
697
698 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800699 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700700 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
701 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
702 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
703 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
704 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
705 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
706 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
707 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
708 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
709 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
710 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100711 }
712
713 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800714 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700715 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
716 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
717 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
718 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
719 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
720 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
721 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
722 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
723 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
724 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
725 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100726 }
727
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800728 public static void test_StrictMath_sqrt() {
729 StrictMath.sqrt(+4.0);
730 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
731 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
732 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
733 }
734
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100735 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800736 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100737 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
738 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
739 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
740 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
741 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
742 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
743 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
744 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
745 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
746 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
747 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
748 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
749 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
750 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
751 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
752 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
753 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
754 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
755 }
756
757 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800758 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100759 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
760 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
761 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
762 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
763 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
764 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
765 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
766 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
767 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
768 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
769 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
770 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
771 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
772 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
773 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
774 }
775
776 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800777 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100778 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
779 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
780 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
781 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
782 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
783 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
784 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
785 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
786 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
787 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
788 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
789 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
790 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
791 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
792 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
793 }
794
795 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800796 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100797 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
798 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
799 Assert.assertEquals(StrictMath.round(2.0d), 2l);
800 Assert.assertEquals(StrictMath.round(2.1d), 2l);
801 Assert.assertEquals(StrictMath.round(2.5d), 3l);
802 Assert.assertEquals(StrictMath.round(2.9d), 3l);
803 Assert.assertEquals(StrictMath.round(3.0d), 3l);
804 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
805 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
806 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
807 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
808 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
809 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
810 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
811 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
812 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
813 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
814 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
815 }
816
817 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800818 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100819 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
820 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
821 Assert.assertEquals(StrictMath.round(2.0f), 2);
822 Assert.assertEquals(StrictMath.round(2.1f), 2);
823 Assert.assertEquals(StrictMath.round(2.5f), 3);
824 Assert.assertEquals(StrictMath.round(2.9f), 3);
825 Assert.assertEquals(StrictMath.round(3.0f), 3);
826 Assert.assertEquals(StrictMath.round(-2.0f), -2);
827 Assert.assertEquals(StrictMath.round(-2.1f), -2);
828 Assert.assertEquals(StrictMath.round(-2.5f), -2);
829 Assert.assertEquals(StrictMath.round(-2.9f), -3);
830 Assert.assertEquals(StrictMath.round(-3.0f), -3);
831 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
832 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
833 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
834 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
835 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
836 }
837
Elliott Hughes28c384b2012-06-15 16:46:25 -0700838 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800839 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700840 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
841 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
842 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
843 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
844 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
845 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
846 }
847
848 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800849 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700850 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
851 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
852 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
853 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
854 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
855 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
856 }
857
858 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800859 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700860 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
861 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
862 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
863 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
864 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
865 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
866 }
867
868 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800869 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700870 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
871 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
872 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
873 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
874 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
875 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
876 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100877
Zheng Xua3fe7422014-07-09 14:03:15 +0800878 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800879 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800880 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
881 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
882 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
883 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
884 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
885 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
886 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
887 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
888 }
889
890 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800891 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800892 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
893 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
894 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
895 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
896 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
897 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
898 }
899
900 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800901 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800902 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
903 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
904 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
905 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
906 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
907 }
908
Serban Constantinescu23abec92014-07-02 16:13:38 +0100909 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800910 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100911 Assert.assertEquals(Integer.reverse(1), 0x80000000);
912 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
913 Assert.assertEquals(Integer.reverse(0), 0);
914 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
915 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
916 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
917 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
918 }
919
920 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800921 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100922 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
923 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
924 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800925 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
926 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
927 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100928 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
929 }
930
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700931 static Object runtime;
932 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700933 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700934 static Method peek_byte;
935 static Method peek_short;
936 static Method peek_int;
937 static Method peek_long;
938 static Method poke_byte;
939 static Method poke_short;
940 static Method poke_int;
941 static Method poke_long;
942
943 public static void initSupportMethodsForPeekPoke() throws Exception {
944 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
945 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
946 runtime = get_runtime.invoke(null);
947 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700948 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700949
950 Class<?> io_memory = Class.forName("libcore.io.Memory");
951 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
952 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
953 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
954 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
955 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
956 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
957 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
958 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
959 }
960
961 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700962 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700963 b[0] = 0x12;
964 b[1] = 0x11;
965 long address = (long)address_of.invoke(runtime, b);
966 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
967 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
968 }
969
970 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700971 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700972 b[0] = 0x13;
973 b[1] = 0x12;
974 b[2] = 0x11;
975 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800976 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700977 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
978 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
979 }
980
981 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700982 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700983 b[0] = 0x15;
984 b[1] = 0x14;
985 b[2] = 0x13;
986 b[3] = 0x12;
987 b[4] = 0x11;
988 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800989 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700990 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
991 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
992 }
993
994 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700995 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700996 b[0] = 0x19;
997 b[1] = 0x18;
998 b[2] = 0x17;
999 b[3] = 0x16;
1000 b[4] = 0x15;
1001 b[5] = 0x14;
1002 b[6] = 0x13;
1003 b[7] = 0x12;
1004 b[8] = 0x11;
1005 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001006 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001007 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
1008 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
1009 }
1010
1011 public static void test_Memory_pokeByte() throws Exception {
1012 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001013 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001014 long address = (long)address_of.invoke(runtime, b);
1015 poke_byte.invoke(null, address, (byte)0x11);
1016 poke_byte.invoke(null, address + 1, (byte)0x12);
1017 Assert.assertTrue(Arrays.equals(r, b));
1018 }
1019
1020 public static void test_Memory_pokeShort() throws Exception {
1021 byte[] ra = {0x12, 0x11, 0x13};
1022 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001023 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001024 long address = (long)address_of.invoke(runtime, b);
1025
1026 // Aligned write
1027 b[2] = 0x13;
1028 poke_short.invoke(null, address, (short)0x1112, false);
1029 Assert.assertTrue(Arrays.equals(ra, b));
1030
1031 // Unaligned write
1032 poke_short.invoke(null, address + 1, (short)0x2122, false);
1033 Assert.assertTrue(Arrays.equals(ru, b));
1034 }
1035
1036 public static void test_Memory_pokeInt() throws Exception {
1037 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1038 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001039 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001040 long address = (long)address_of.invoke(runtime, b);
1041
1042 b[4] = 0x15;
1043 poke_int.invoke(null, address, (int)0x11121314, false);
1044 Assert.assertTrue(Arrays.equals(ra, b));
1045
1046 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1047 Assert.assertTrue(Arrays.equals(ru, b));
1048 }
1049
1050 public static void test_Memory_pokeLong() throws Exception {
1051 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1052 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001053 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001054 long address = (long)address_of.invoke(runtime, b);
1055
1056 b[8] = 0x19;
1057 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1058 Assert.assertTrue(Arrays.equals(ra, b));
1059
1060 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1061 Assert.assertTrue(Arrays.equals(ru, b));
1062 }
jeffhao5d1ac922011-09-29 17:41:15 -07001063}