1/*
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
17import junit.framework.Assert;
18import java.util.Arrays;
19import java.lang.reflect.Method;
20
21public class Main {
22  public static void main(String args[]) throws Exception {
23    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();
29    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();
37    test_Math_sqrt();
38    test_Math_ceil();
39    test_Math_floor();
40    test_Math_rint();
41    test_Math_round_D();
42    test_Math_round_F();
43    test_Short_reverseBytes();
44    test_Integer_reverseBytes();
45    test_Long_reverseBytes();
46    test_Integer_reverse();
47    test_Long_reverse();
48    test_StrictMath_abs_I();
49    test_StrictMath_abs_J();
50    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();
58    test_StrictMath_sqrt();
59    test_StrictMath_ceil();
60    test_StrictMath_floor();
61    test_StrictMath_rint();
62    test_StrictMath_round_D();
63    test_StrictMath_round_F();
64    test_String_charAt();
65    test_String_compareTo();
66    test_String_indexOf();
67    test_String_isEmpty();
68    test_String_length();
69    test_Thread_currentThread();
70    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();
79  }
80
81  /**
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
92  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
124  // 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
127  public static void test_String_charAt() {
128    String testStr = "Now is the time to test some stuff";
129
130    Assert.assertEquals(testStr.length() - 1, 33);  // 33 = testStr.length()-1 as a constant.
131    Assert.assertEquals('f', testStr.charAt(33));
132
133    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);
144  }
145
146  private static void test_String_charAtExc(String testStr) {
147    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) {
156    }
157    try {
158      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      }
164      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 {
178      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      }
185      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    }
195
196    String strNull = null;
197    try {
198      strNull.charAt(0);
199      Assert.fail();
200    } catch (NullPointerException expected) {
201    }
202  }
203
204  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
209  private static void test_String_charAtExc2(String testStr) {
210    try {
211      test_String_charAtExc3(testStr);
212      Assert.fail();
213    } catch (StringIndexOutOfBoundsException expected) {
214    }
215    try {
216      test_String_charAtExc4(testStr);
217      Assert.fail();
218    } catch (StringIndexOutOfBoundsException expected) {
219    }
220  }
221
222  private static void test_String_charAtExc3(String testStr) {
223    Assert.assertEquals('N', testStr.charAt(-1));
224  }
225
226  private static void test_String_charAtExc4(String testStr) {
227    Assert.assertEquals('N', testStr.charAt(100));
228  }
229
230  static int start;
231  private static int[] negIndex = { -100000 };
232  public static void test_String_indexOf() {
233    String str0 = "";
234    String str1 = "/";
235    String str3 = "abc";
236    String str10 = "abcdefghij";
237    String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
238
239    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);
250    Assert.assertEquals(str1.indexOf('/',++start), -1);
251    Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
252    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
263    testIndexOfNull();
264
265    // Same data as above, but stored so it's not a literal in the next test. -2 stands for
266    // indexOf(I) instead of indexOf(II).
267    start--;
268    int[][] searchData = {
269        { 'a', -2, -1 },
270        { 'a', -2, 0 },
271        { 'b', -2, 1 },
272        { 'c', -2, 2 },
273        { 'j', -2, 9 },
274        { 'a', -2, 0 },
275        { 'b', -2, 38 },
276        { 'c', -2, 39 },
277        { 'a', 20, -1 },
278        { 'a', 0, -1 },
279        { 'a', -1, -1 },
280        { '/', ++start, -1 },
281        { 'a', negIndex[0], -1 },
282        { 'a', 0, 0 },
283        { 'a', 1, -1 },
284        { 'a', 1234, -1 },
285        { 'b', 0, 1 },
286        { 'b', 1, 1 },
287        { 'c', 2, 2 },
288        { 'j', 5, 9 },
289        { 'j', 9, 9 },
290        { 'a', 10, 10 },
291        { 'b', 40, -1 },
292    };
293    testStringIndexOfChars(searchData);
294
295    testSurrogateIndexOf();
296  }
297
298  private static void testStringIndexOfChars(int[][] searchData) {
299    // Use a try-catch to avoid inlining.
300    try {
301      testStringIndexOfCharsImpl(searchData);
302    } catch (Exception e) {
303      System.out.println("Unexpected exception");
304    }
305  }
306
307  private static void testStringIndexOfCharsImpl(int[][] searchData) {
308    String str0 = "";
309    String str1 = "/";
310    String str3 = "abc";
311    String str10 = "abcdefghij";
312    String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
313
314    Assert.assertEquals(str0.indexOf(searchData[0][0]), searchData[0][2]);
315    Assert.assertEquals(str3.indexOf(searchData[1][0]), searchData[1][2]);
316    Assert.assertEquals(str3.indexOf(searchData[2][0]), searchData[2][2]);
317    Assert.assertEquals(str3.indexOf(searchData[3][0]), searchData[3][2]);
318    Assert.assertEquals(str10.indexOf(searchData[4][0]), searchData[4][2]);
319    Assert.assertEquals(str40.indexOf(searchData[5][0]), searchData[5][2]);
320    Assert.assertEquals(str40.indexOf(searchData[6][0]), searchData[6][2]);
321    Assert.assertEquals(str40.indexOf(searchData[7][0]), searchData[7][2]);
322    Assert.assertEquals(str0.indexOf(searchData[8][0], searchData[8][1]), searchData[8][2]);
323    Assert.assertEquals(str0.indexOf(searchData[9][0], searchData[9][1]), searchData[9][2]);
324    Assert.assertEquals(str0.indexOf(searchData[10][0], searchData[10][1]), searchData[10][2]);
325    Assert.assertEquals(str1.indexOf(searchData[11][0], searchData[11][1]), searchData[11][2]);
326    Assert.assertEquals(str1.indexOf(searchData[12][0], searchData[12][1]), searchData[12][2]);
327    Assert.assertEquals(str3.indexOf(searchData[13][0], searchData[13][1]), searchData[13][2]);
328    Assert.assertEquals(str3.indexOf(searchData[14][0], searchData[14][1]), searchData[14][2]);
329    Assert.assertEquals(str3.indexOf(searchData[15][0], searchData[15][1]), searchData[15][2]);
330    Assert.assertEquals(str3.indexOf(searchData[16][0], searchData[16][1]), searchData[16][2]);
331    Assert.assertEquals(str3.indexOf(searchData[17][0], searchData[17][1]), searchData[17][2]);
332    Assert.assertEquals(str3.indexOf(searchData[18][0], searchData[18][1]), searchData[18][2]);
333    Assert.assertEquals(str10.indexOf(searchData[19][0], searchData[19][1]), searchData[19][2]);
334    Assert.assertEquals(str10.indexOf(searchData[20][0], searchData[20][1]), searchData[20][2]);
335    Assert.assertEquals(str40.indexOf(searchData[21][0], searchData[21][1]), searchData[21][2]);
336    Assert.assertEquals(str40.indexOf(searchData[22][0], searchData[22][1]), searchData[22][2]);
337  }
338
339  private static void testSurrogateIndexOf() {
340    int supplementaryChar = 0x20b9f;
341    String surrogatePair = "\ud842\udf9f";
342    String stringWithSurrogates = "hello " + surrogatePair + " world";
343
344    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
345    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
346    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
347    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
348
349    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar - 0x10000), -1);
350    Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar | 0x80000000), -1);
351  }
352
353  private static void testIndexOfNull() {
354    String strNull = null;
355    try {
356      testNullIndex(strNull, 'a');
357      Assert.fail();
358    } catch (NullPointerException expected) {
359    }
360    try {
361      testNullIndex(strNull, 'a', 0);
362      Assert.fail();
363    } catch (NullPointerException expected) {
364    }
365    try {
366        testNullIndex(strNull, 'a', -1);
367      Assert.fail();
368    } catch (NullPointerException expected) {
369    }
370  }
371
372  private static int testNullIndex(String strNull, int c) {
373    return strNull.indexOf(c);
374  }
375
376  private static int testNullIndex(String strNull, int c, int startIndex) {
377    return strNull.indexOf(c, startIndex);
378  }
379
380  public static void test_String_compareTo() {
381    String test = "0123456789";
382    String test1 = new String("0123456789");    // different object
383    String test2 = new String("0123456780");    // different value
384    String offset = new String("xxx0123456789yyy");
385    String sub = offset.substring(3, 13);
386    String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
387    String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
388    String lc = "abcdefg";
389    String uc = "ABCDEFG";
390    Object blah = new Object();
391
392    Assert.assertTrue(lc.toUpperCase().equals(uc));
393
394    Assert.assertEquals(str32.compareTo(str33), -1);
395    Assert.assertEquals(str33.compareTo(str32), 1);
396
397    Assert.assertTrue(test.equals(test));
398    Assert.assertTrue(test.equals(test1));
399    Assert.assertFalse(test.equals(test2));
400
401    Assert.assertEquals(test.compareTo(test1), 0);
402    Assert.assertTrue(test1.compareTo(test2) > 0);
403    Assert.assertTrue(test2.compareTo(test1) < 0);
404
405    // Compare string with a nonzero offset, in left/right side.
406    Assert.assertEquals(test.compareTo(sub), 0);
407    Assert.assertEquals(sub.compareTo(test), 0);
408    Assert.assertTrue(test.equals(sub));
409    Assert.assertTrue(sub.equals(test));
410    // Same base, one is a substring.
411    Assert.assertFalse(offset.equals(sub));
412    Assert.assertFalse(sub.equals(offset));
413    // Wrong class.
414    Assert.assertFalse(test.equals(blah));
415
416    // Null lhs - throw.
417    try {
418      test.compareTo(null);
419      Assert.fail("didn't get expected npe");
420    } catch (NullPointerException npe) {
421    }
422    // Null rhs - okay.
423    Assert.assertFalse(test.equals(null));
424
425    test = test.substring(1);
426    Assert.assertTrue(test.equals("123456789"));
427    Assert.assertFalse(test.equals(test1));
428
429    test = test.substring(1);
430    Assert.assertTrue(test.equals("23456789"));
431
432    test = test.substring(1);
433    Assert.assertTrue(test.equals("3456789"));
434
435    test = test.substring(1);
436    Assert.assertTrue(test.equals("456789"));
437
438    test = test.substring(3,5);
439    Assert.assertTrue(test.equals("78"));
440
441    test = "this/is/a/path";
442    String[] strings = test.split("/");
443    Assert.assertEquals(4, strings.length);
444
445    Assert.assertEquals("this is a path", test.replaceAll("/", " "));
446    Assert.assertEquals("this is a path", test.replace("/", " "));
447  }
448
449  public static void test_Math_abs_I() {
450    Math.abs(-1);
451    Assert.assertEquals(Math.abs(0), 0);
452    Assert.assertEquals(Math.abs(123), 123);
453    Assert.assertEquals(Math.abs(-123), 123);
454    Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
455    Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
456    Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
457    Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
458  }
459
460  public static void test_Math_abs_J() {
461    Math.abs(-1L);
462    Assert.assertEquals(Math.abs(0L), 0L);
463    Assert.assertEquals(Math.abs(123L), 123L);
464    Assert.assertEquals(Math.abs(-123L), 123L);
465    Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
466    Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
467    Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
468    Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
469  }
470
471  public static void test_Math_min_I() {
472    Math.min(1, 0);
473    Assert.assertEquals(Math.min(0, 0), 0);
474    Assert.assertEquals(Math.min(1, 0), 0);
475    Assert.assertEquals(Math.min(0, 1), 0);
476    Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
477    Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
478    Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
479  }
480
481  public static void test_Math_max_I() {
482    Math.max(1, 0);
483    Assert.assertEquals(Math.max(0, 0), 0);
484    Assert.assertEquals(Math.max(1, 0), 1);
485    Assert.assertEquals(Math.max(0, 1), 1);
486    Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
487    Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
488    Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
489  }
490
491  public static void test_Math_min_J() {
492    Math.min(1L, 0L);
493    Assert.assertEquals(Math.min(0L, 0L), 0L);
494    Assert.assertEquals(Math.min(1L, 0L), 0L);
495    Assert.assertEquals(Math.min(0L, 1L), 0L);
496    Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
497    Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
498    Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
499  }
500
501  public static void test_Math_max_J() {
502    Math.max(1L, 0L);
503    Assert.assertEquals(Math.max(0L, 0L), 0L);
504    Assert.assertEquals(Math.max(1L, 0L), 1L);
505    Assert.assertEquals(Math.max(0L, 1L), 1L);
506    Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
507    Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
508    Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
509  }
510
511  public static void test_Math_min_F() {
512    Math.min(1.0f, Float.NaN);
513    Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
514    Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
515    Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
516    Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
517    Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
518    Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
519    Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
520    Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
521    Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
522    Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
523    Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
524  }
525
526  public static void test_Math_max_F() {
527    Math.max(1.0f, Float.NaN);
528    Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
529    Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
530    Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
531    Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
532    Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
533    Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
534    Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
535    Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
536    Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
537    Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
538    Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
539  }
540
541  public static void test_Math_min_D() {
542    Math.min(1.0d, Double.NaN);
543    Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
544    Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
545    Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
546    Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
547    Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
548    Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
549    Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
550    Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
551    Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
552    Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
553    Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
554  }
555
556  public static void test_Math_max_D() {
557    Math.max(1.0d, Double.NaN);
558    Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
559    Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
560    Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
561    Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
562    Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
563    Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
564    Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
565    Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
566    Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
567    Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
568    Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
569  }
570
571  public static void test_Math_sqrt() {
572    Math.sqrt(+4.0);
573    Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
574    Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
575    Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
576  }
577
578  public static void test_Math_ceil() {
579    Math.ceil(-0.9);
580    Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
581    Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
582    Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
583    Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
584    Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
585    Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
586    Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
587    Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
588    Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
589    Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
590    Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
591    Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
592    Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
593    Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
594    Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
595    Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
596    Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
597    Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
598  }
599
600  public static void test_Math_floor() {
601    Math.floor(+2.1);
602    Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
603    Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
604    Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
605    Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
606    Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
607    Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
608    Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
609    Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
610    Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
611    Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
612    Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
613    Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
614    Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
615    Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
616    Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
617  }
618
619  public static void test_Math_rint() {
620    Math.rint(+2.1);
621    Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
622    Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
623    Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
624    Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
625    Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
626    Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
627    Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
628    Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
629    Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
630    Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
631    Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
632    Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
633    Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
634    Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
635    Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
636  }
637
638  public static void test_Math_round_D() {
639    Math.round(2.1d);
640    Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
641    Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
642    Assert.assertEquals(Math.round(2.0d), 2l);
643    Assert.assertEquals(Math.round(2.1d), 2l);
644    Assert.assertEquals(Math.round(2.5d), 3l);
645    Assert.assertEquals(Math.round(2.9d), 3l);
646    Assert.assertEquals(Math.round(3.0d), 3l);
647    Assert.assertEquals(Math.round(-2.0d), -2l);
648    Assert.assertEquals(Math.round(-2.1d), -2l);
649    Assert.assertEquals(Math.round(-2.5d), -2l);
650    Assert.assertEquals(Math.round(-2.9d), -3l);
651    Assert.assertEquals(Math.round(-3.0d), -3l);
652    Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
653    Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
654    Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
655    Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
656    Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
657    Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
658  }
659
660  public static void test_Math_round_F() {
661    Math.round(2.1f);
662    Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
663    Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
664    Assert.assertEquals(Math.round(2.0f), 2);
665    Assert.assertEquals(Math.round(2.1f), 2);
666    Assert.assertEquals(Math.round(2.5f), 3);
667    Assert.assertEquals(Math.round(2.9f), 3);
668    Assert.assertEquals(Math.round(3.0f), 3);
669    Assert.assertEquals(Math.round(-2.0f), -2);
670    Assert.assertEquals(Math.round(-2.1f), -2);
671    Assert.assertEquals(Math.round(-2.5f), -2);
672    Assert.assertEquals(Math.round(-2.9f), -3);
673    Assert.assertEquals(Math.round(-3.0f), -3);
674    Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
675    Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
676    Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
677    Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
678    Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
679  }
680
681  public static void test_StrictMath_abs_I() {
682    StrictMath.abs(-1);
683    Assert.assertEquals(StrictMath.abs(0), 0);
684    Assert.assertEquals(StrictMath.abs(123), 123);
685    Assert.assertEquals(StrictMath.abs(-123), 123);
686    Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
687    Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
688    Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
689    Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
690  }
691
692  public static void test_StrictMath_abs_J() {
693    StrictMath.abs(-1L);
694    Assert.assertEquals(StrictMath.abs(0L), 0L);
695    Assert.assertEquals(StrictMath.abs(123L), 123L);
696    Assert.assertEquals(StrictMath.abs(-123L), 123L);
697    Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
698    Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
699    Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
700  }
701
702  public static void test_StrictMath_min_I() {
703    StrictMath.min(1, 0);
704    Assert.assertEquals(StrictMath.min(0, 0), 0);
705    Assert.assertEquals(StrictMath.min(1, 0), 0);
706    Assert.assertEquals(StrictMath.min(0, 1), 0);
707    Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
708    Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
709    Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
710  }
711
712  public static void test_StrictMath_max_I() {
713    StrictMath.max(1, 0);
714    Assert.assertEquals(StrictMath.max(0, 0), 0);
715    Assert.assertEquals(StrictMath.max(1, 0), 1);
716    Assert.assertEquals(StrictMath.max(0, 1), 1);
717    Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
718    Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
719    Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
720  }
721
722  public static void test_StrictMath_min_J() {
723    StrictMath.min(1L, 0L);
724    Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
725    Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
726    Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
727    Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
728    Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
729    Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
730  }
731
732  public static void test_StrictMath_max_J() {
733    StrictMath.max(1L, 0L);
734    Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
735    Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
736    Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
737    Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
738    Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
739    Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
740  }
741
742  public static void test_StrictMath_min_F() {
743    StrictMath.min(1.0f, Float.NaN);
744    Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
745    Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
746    Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
747    Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
748    Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
749    Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
750    Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
751    Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
752    Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
753    Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
754    Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
755  }
756
757  public static void test_StrictMath_max_F() {
758    StrictMath.max(1.0f, Float.NaN);
759    Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
760    Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
761    Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
762    Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
763    Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
764    Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
765    Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
766    Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
767    Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
768    Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
769    Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
770  }
771
772  public static void test_StrictMath_min_D() {
773    StrictMath.min(1.0d, Double.NaN);
774    Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
775    Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
776    Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
777    Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
778    Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
779    Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
780    Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
781    Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
782    Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
783    Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
784    Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
785  }
786
787  public static void test_StrictMath_max_D() {
788    StrictMath.max(1.0d, Double.NaN);
789    Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
790    Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
791    Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
792    Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
793    Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
794    Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
795    Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
796    Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
797    Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
798    Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
799    Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
800  }
801
802  public static void test_StrictMath_sqrt() {
803    StrictMath.sqrt(+4.0);
804    Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
805    Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
806    Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
807  }
808
809  public static void test_StrictMath_ceil() {
810    StrictMath.ceil(-0.9);
811    Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
812    Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
813    Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
814    Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
815    Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
816    Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
817    Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
818    Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
819    Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
820    Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
821    Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
822    Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
823    Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
824    Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
825    Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
826    Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
827    Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
828    Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
829  }
830
831  public static void test_StrictMath_floor() {
832    StrictMath.floor(+2.1);
833    Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
834    Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
835    Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
836    Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
837    Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
838    Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
839    Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
840    Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
841    Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
842    Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
843    Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
844    Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
845    Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
846    Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
847    Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
848  }
849
850  public static void test_StrictMath_rint() {
851    StrictMath.rint(+2.1);
852    Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
853    Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
854    Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
855    Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
856    Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
857    Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
858    Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
859    Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
860    Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
861    Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
862    Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
863    Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
864    Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
865    Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
866    Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
867  }
868
869  public static void test_StrictMath_round_D() {
870    StrictMath.round(2.1d);
871    Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
872    Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
873    Assert.assertEquals(StrictMath.round(2.0d), 2l);
874    Assert.assertEquals(StrictMath.round(2.1d), 2l);
875    Assert.assertEquals(StrictMath.round(2.5d), 3l);
876    Assert.assertEquals(StrictMath.round(2.9d), 3l);
877    Assert.assertEquals(StrictMath.round(3.0d), 3l);
878    Assert.assertEquals(StrictMath.round(-2.0d), -2l);
879    Assert.assertEquals(StrictMath.round(-2.1d), -2l);
880    Assert.assertEquals(StrictMath.round(-2.5d), -2l);
881    Assert.assertEquals(StrictMath.round(-2.9d), -3l);
882    Assert.assertEquals(StrictMath.round(-3.0d), -3l);
883    Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
884    Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
885    Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
886    Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
887    Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
888    Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
889  }
890
891  public static void test_StrictMath_round_F() {
892    StrictMath.round(2.1f);
893    Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
894    Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
895    Assert.assertEquals(StrictMath.round(2.0f), 2);
896    Assert.assertEquals(StrictMath.round(2.1f), 2);
897    Assert.assertEquals(StrictMath.round(2.5f), 3);
898    Assert.assertEquals(StrictMath.round(2.9f), 3);
899    Assert.assertEquals(StrictMath.round(3.0f), 3);
900    Assert.assertEquals(StrictMath.round(-2.0f), -2);
901    Assert.assertEquals(StrictMath.round(-2.1f), -2);
902    Assert.assertEquals(StrictMath.round(-2.5f), -2);
903    Assert.assertEquals(StrictMath.round(-2.9f), -3);
904    Assert.assertEquals(StrictMath.round(-3.0f), -3);
905    Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
906    Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
907    Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
908    Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
909    Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
910  }
911
912  public static void test_Float_floatToRawIntBits() {
913    Float.floatToRawIntBits(-1.0f);
914    Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
915    Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
916    Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
917    Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
918    Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
919    Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
920  }
921
922  public static void test_Float_intBitsToFloat() {
923    Float.intBitsToFloat(0xbf800000);
924    Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
925    Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
926    Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
927    Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
928    Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
929    Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
930  }
931
932  public static void test_Double_doubleToRawLongBits() {
933    Double.doubleToRawLongBits(-1.0);
934    Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
935    Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
936    Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
937    Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
938    Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
939    Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
940  }
941
942  public static void test_Double_longBitsToDouble() {
943    Double.longBitsToDouble(0xbff0000000000000L);
944    Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
945    Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
946    Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
947    Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
948    Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
949    Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
950  }
951
952  public static void test_Short_reverseBytes() {
953      Short.reverseBytes((short)0x1357);
954      Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
955      Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
956      Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
957      Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
958      Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
959      Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
960      Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
961      Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
962  }
963
964  public static void test_Integer_reverseBytes() {
965      Integer.reverseBytes(0x13579bdf);
966      Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
967      Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
968      Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
969      Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
970      Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
971      Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
972  }
973
974  public static void test_Long_reverseBytes() {
975      Long.reverseBytes(0x13579bdf2468ace0L);
976      Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
977      Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
978      Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
979      Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
980      Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
981  }
982
983  public static void test_Integer_reverse() {
984    Integer.reverse(0x12345678);
985    Assert.assertEquals(Integer.reverse(1), 0x80000000);
986    Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
987    Assert.assertEquals(Integer.reverse(0), 0);
988    Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
989    Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
990    Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
991    Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
992  }
993
994  public static void test_Long_reverse() {
995    Long.reverse(0x1234567812345678L);
996    Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
997    Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
998    Assert.assertEquals(Long.reverse(0L), 0L);
999    Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
1000    Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
1001    Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
1002    Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
1003
1004    Assert.assertEquals(test_Long_reverse_b22324327(0xaaaaaaaaaaaaaaaaL, 0x5555555555555555L),
1005            157472205507277347L);
1006  }
1007
1008  // A bit more complicated than the above. Use local variables to stress register allocation.
1009  private static long test_Long_reverse_b22324327(long l1, long l2) {
1010    // A couple of local integers. Use them in a loop, so they get promoted.
1011    int i1 = 0, i2 = 1, i3 = 2, i4 = 3, i5 = 4, i6 = 5, i7 = 6, i8 = 7;
1012    for (int k = 0; k < 10; k++) {
1013      i1 += 1;
1014      i2 += 2;
1015      i3 += 3;
1016      i4 += 4;
1017      i5 += 5;
1018      i6 += 6;
1019      i7 += 7;
1020      i8 += 8;
1021    }
1022
1023    // Do the Long.reverse() calls, save the results.
1024    long r1 = Long.reverse(l1);
1025    long r2 = Long.reverse(l2);
1026
1027    // Some more looping with the ints.
1028    for (int k = 0; k < 10; k++) {
1029      i1 += 1;
1030      i2 += 2;
1031      i3 += 3;
1032      i4 += 4;
1033      i5 += 5;
1034      i6 += 6;
1035      i7 += 7;
1036      i8 += 8;
1037    }
1038
1039    // Include everything in the result, so things are kept live. Try to be a little bit clever to
1040    // avoid things being folded somewhere.
1041    return (r1 / i1) + (r2 / i2) + i3 + i4 + i5 + i6 + i7 + i8;
1042  }
1043
1044  static Object runtime;
1045  static Method address_of;
1046  static Method new_non_movable_array;
1047  static Method peek_byte;
1048  static Method peek_short;
1049  static Method peek_int;
1050  static Method peek_long;
1051  static Method poke_byte;
1052  static Method poke_short;
1053  static Method poke_int;
1054  static Method poke_long;
1055
1056  public static void initSupportMethodsForPeekPoke() throws Exception {
1057    Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
1058    Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
1059    runtime = get_runtime.invoke(null);
1060    address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
1061    new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
1062
1063    Class<?> io_memory = Class.forName("libcore.io.Memory");
1064    peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
1065    peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
1066    peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
1067    peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
1068    poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
1069    poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
1070    poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
1071    poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
1072  }
1073
1074  public static void test_Memory_peekByte() throws Exception {
1075    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
1076    b[0] = 0x12;
1077    b[1] = 0x11;
1078    long address = (long)address_of.invoke(runtime, b);
1079    Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
1080    Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
1081  }
1082
1083  public static void test_Memory_peekShort() throws Exception {
1084    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
1085    b[0] = 0x13;
1086    b[1] = 0x12;
1087    b[2] = 0x11;
1088    long address = (long)address_of.invoke(runtime, b);
1089    peek_short.invoke(null, address, false);
1090    Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213);  // Aligned read
1091    Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112);  // Unaligned read
1092  }
1093
1094  public static void test_Memory_peekInt() throws Exception {
1095    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
1096    b[0] = 0x15;
1097    b[1] = 0x14;
1098    b[2] = 0x13;
1099    b[3] = 0x12;
1100    b[4] = 0x11;
1101    long address = (long)address_of.invoke(runtime, b);
1102    peek_int.invoke(null, address, false);
1103    Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
1104    Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
1105  }
1106
1107  public static void test_Memory_peekLong() throws Exception {
1108    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
1109    b[0] = 0x19;
1110    b[1] = 0x18;
1111    b[2] = 0x17;
1112    b[3] = 0x16;
1113    b[4] = 0x15;
1114    b[5] = 0x14;
1115    b[6] = 0x13;
1116    b[7] = 0x12;
1117    b[8] = 0x11;
1118    long address = (long)address_of.invoke(runtime, b);
1119    peek_long.invoke(null, address, false);
1120    Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
1121    Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
1122  }
1123
1124  public static void test_Memory_pokeByte() throws Exception {
1125    byte[] r = {0x11, 0x12};
1126    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
1127    long address = (long)address_of.invoke(runtime, b);
1128    poke_byte.invoke(null, address, (byte)0x11);
1129    poke_byte.invoke(null, address + 1, (byte)0x12);
1130    Assert.assertTrue(Arrays.equals(r, b));
1131  }
1132
1133  public static void test_Memory_pokeShort() throws Exception {
1134    byte[] ra = {0x12, 0x11, 0x13};
1135    byte[] ru = {0x12, 0x22, 0x21};
1136    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
1137    long address = (long)address_of.invoke(runtime, b);
1138
1139    // Aligned write
1140    b[2] = 0x13;
1141    poke_short.invoke(null, address, (short)0x1112, false);
1142    Assert.assertTrue(Arrays.equals(ra, b));
1143
1144    // Unaligned write
1145    poke_short.invoke(null, address + 1, (short)0x2122, false);
1146    Assert.assertTrue(Arrays.equals(ru, b));
1147  }
1148
1149  public static void test_Memory_pokeInt() throws Exception {
1150    byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1151    byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
1152    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
1153    long address = (long)address_of.invoke(runtime, b);
1154
1155    b[4] = 0x15;
1156    poke_int.invoke(null, address, (int)0x11121314, false);
1157    Assert.assertTrue(Arrays.equals(ra, b));
1158
1159    poke_int.invoke(null, address + 1, (int)0x21222324, false);
1160    Assert.assertTrue(Arrays.equals(ru, b));
1161  }
1162
1163  public static void test_Memory_pokeLong() throws Exception {
1164    byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1165    byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
1166    byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
1167    long address = (long)address_of.invoke(runtime, b);
1168
1169    b[8] = 0x19;
1170    poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1171    Assert.assertTrue(Arrays.equals(ra, b));
1172
1173    poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1174    Assert.assertTrue(Arrays.equals(ru, b));
1175  }
1176}
1177