jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 17 | import junit.framework.Assert; |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 18 | import java.util.Arrays; |
| 19 | import java.lang.reflect.Method; |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 20 | |
| 21 | public class Main { |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 22 | public static void main(String args[]) throws Exception { |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 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(); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 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(); |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 37 | test_Math_sqrt(); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 38 | test_Math_ceil(); |
| 39 | test_Math_floor(); |
| 40 | test_Math_rint(); |
| 41 | test_Math_round_D(); |
| 42 | test_Math_round_F(); |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 43 | test_Short_reverseBytes(); |
| 44 | test_Integer_reverseBytes(); |
| 45 | test_Long_reverseBytes(); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 46 | test_Integer_reverse(); |
| 47 | test_Long_reverse(); |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 48 | test_Integer_numberOfLeadingZeros(); |
| 49 | test_Long_numberOfLeadingZeros(); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 50 | test_StrictMath_abs_I(); |
| 51 | test_StrictMath_abs_J(); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 52 | test_StrictMath_min_I(); |
| 53 | test_StrictMath_max_I(); |
| 54 | test_StrictMath_min_J(); |
| 55 | test_StrictMath_max_J(); |
| 56 | test_StrictMath_min_F(); |
| 57 | test_StrictMath_max_F(); |
| 58 | test_StrictMath_min_D(); |
| 59 | test_StrictMath_max_D(); |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 60 | test_StrictMath_sqrt(); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 61 | test_StrictMath_ceil(); |
| 62 | test_StrictMath_floor(); |
| 63 | test_StrictMath_rint(); |
| 64 | test_StrictMath_round_D(); |
| 65 | test_StrictMath_round_F(); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 66 | test_String_charAt(); |
| 67 | test_String_compareTo(); |
| 68 | test_String_indexOf(); |
| 69 | test_String_isEmpty(); |
| 70 | test_String_length(); |
Andreas Gampe | 7a94961 | 2014-07-08 11:03:59 -0700 | [diff] [blame] | 71 | test_Thread_currentThread(); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 72 | initSupportMethodsForPeekPoke(); |
| 73 | test_Memory_peekByte(); |
| 74 | test_Memory_peekShort(); |
| 75 | test_Memory_peekInt(); |
| 76 | test_Memory_peekLong(); |
| 77 | test_Memory_pokeByte(); |
| 78 | test_Memory_pokeShort(); |
| 79 | test_Memory_pokeInt(); |
| 80 | test_Memory_pokeLong(); |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 81 | test_Integer_numberOfTrailingZeros(); |
| 82 | test_Long_numberOfTrailingZeros(); |
| 83 | test_Integer_rotateRight(); |
| 84 | test_Long_rotateRight(); |
| 85 | test_Integer_rotateLeft(); |
| 86 | test_Long_rotateLeft(); |
| 87 | test_Integer_rotateRightLeft(); |
| 88 | test_Long_rotateRightLeft(); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Andreas Gampe | 7a94961 | 2014-07-08 11:03:59 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Will test inlining Thread.currentThread(). |
| 93 | */ |
| 94 | public static void test_Thread_currentThread() { |
| 95 | // 1. Do not use result. |
| 96 | Thread.currentThread(); |
| 97 | |
| 98 | // 2. Result should not be null. |
| 99 | Assert.assertNotNull(Thread.currentThread()); |
| 100 | } |
| 101 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 102 | public static void test_String_length() { |
| 103 | String str0 = ""; |
| 104 | String str1 = "x"; |
| 105 | String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789"; |
| 106 | |
| 107 | Assert.assertEquals(str0.length(), 0); |
| 108 | Assert.assertEquals(str1.length(), 1); |
| 109 | Assert.assertEquals(str80.length(), 80); |
| 110 | |
| 111 | String strNull = null; |
| 112 | try { |
| 113 | strNull.length(); |
| 114 | Assert.fail(); |
| 115 | } catch (NullPointerException expected) { |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | public static void test_String_isEmpty() { |
| 120 | String str0 = ""; |
| 121 | String str1 = "x"; |
| 122 | |
| 123 | Assert.assertTrue(str0.isEmpty()); |
| 124 | Assert.assertFalse(str1.isEmpty()); |
| 125 | |
| 126 | String strNull = null; |
| 127 | try { |
| 128 | strNull.isEmpty(); |
| 129 | Assert.fail(); |
| 130 | } catch (NullPointerException expected) { |
| 131 | } |
| 132 | } |
| 133 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 134 | // Break up the charAt tests. The optimizing compiler doesn't optimize methods with try-catch yet, |
| 135 | // so we need to separate out the tests that are expected to throw exception |
| 136 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 137 | public static void test_String_charAt() { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 138 | String testStr = "Now is the time to test some stuff"; |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 139 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 140 | Assert.assertEquals(testStr.length() - 1, 33); // 33 = testStr.length()-1 as a constant. |
| 141 | Assert.assertEquals('f', testStr.charAt(33)); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 142 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 143 | test_String_charAt(testStr, 'N', 'o', ' ', 'f'); |
| 144 | test_String_charAt(testStr.substring(3,15), ' ', 'i', 'm', 'e'); |
| 145 | } |
| 146 | public static void test_String_charAt(String testStr, char a, char b, char c, char d) { |
| 147 | Assert.assertEquals(a, testStr.charAt(0)); |
| 148 | Assert.assertEquals(b, testStr.charAt(1)); |
| 149 | Assert.assertEquals(c, testStr.charAt(10)); |
| 150 | Assert.assertEquals(d, testStr.charAt(testStr.length()-1)); |
| 151 | |
| 152 | test_String_charAtExc(testStr); |
| 153 | test_String_charAtExc2(testStr); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 154 | } |
| 155 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 156 | private static void test_String_charAtExc(String testStr) { |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 157 | try { |
| 158 | testStr.charAt(-1); |
| 159 | Assert.fail(); |
| 160 | } catch (StringIndexOutOfBoundsException expected) { |
| 161 | } |
| 162 | try { |
| 163 | testStr.charAt(80); |
| 164 | Assert.fail(); |
| 165 | } catch (StringIndexOutOfBoundsException expected) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 166 | } |
Vladimir Marko | 00ca847 | 2015-01-26 14:06:46 +0000 | [diff] [blame] | 167 | try { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 168 | if (testStr.length() == 34) { |
| 169 | testStr.charAt(34); // 34 = "Now is the time to test some stuff".length() |
| 170 | } else { |
| 171 | Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length() |
| 172 | testStr.charAt(12); |
| 173 | } |
Vladimir Marko | 00ca847 | 2015-01-26 14:06:46 +0000 | [diff] [blame] | 174 | Assert.fail(); |
| 175 | } catch (StringIndexOutOfBoundsException expected) { |
| 176 | } |
| 177 | try { |
| 178 | test_String_charAt_inner(testStr, -1); |
| 179 | Assert.fail(); |
| 180 | } catch (StringIndexOutOfBoundsException expected) { |
| 181 | } |
| 182 | try { |
| 183 | test_String_charAt_inner(testStr, 80); |
| 184 | Assert.fail(); |
| 185 | } catch (StringIndexOutOfBoundsException expected) { |
| 186 | } |
| 187 | try { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 188 | if (testStr.length() == 34) { |
| 189 | // 34 = "Now is the time to test some stuff".length() |
| 190 | test_String_charAt_inner(testStr, 34); |
| 191 | } else { |
| 192 | Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length() |
| 193 | test_String_charAt_inner(testStr, 12); |
| 194 | } |
Vladimir Marko | 00ca847 | 2015-01-26 14:06:46 +0000 | [diff] [blame] | 195 | Assert.fail(); |
| 196 | } catch (StringIndexOutOfBoundsException expected) { |
| 197 | } |
| 198 | |
| 199 | String strEmpty = ""; |
| 200 | try { |
| 201 | strEmpty.charAt(0); |
| 202 | Assert.fail(); |
| 203 | } catch (StringIndexOutOfBoundsException expected) { |
| 204 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 205 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 206 | String strNull = null; |
| 207 | try { |
| 208 | strNull.charAt(0); |
| 209 | Assert.fail(); |
| 210 | } catch (NullPointerException expected) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 211 | } |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 212 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 213 | |
Vladimir Marko | 00ca847 | 2015-01-26 14:06:46 +0000 | [diff] [blame] | 214 | private static char test_String_charAt_inner(String s, int index) { |
| 215 | // Using non-constant index here (assuming that this method wasn't inlined). |
| 216 | return s.charAt(index); |
| 217 | } |
| 218 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 219 | private static void test_String_charAtExc2(String testStr) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 220 | try { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 221 | test_String_charAtExc3(testStr); |
| 222 | Assert.fail(); |
| 223 | } catch (StringIndexOutOfBoundsException expected) { |
| 224 | } |
| 225 | try { |
| 226 | test_String_charAtExc4(testStr); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 227 | Assert.fail(); |
| 228 | } catch (StringIndexOutOfBoundsException expected) { |
| 229 | } |
| 230 | } |
| 231 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 232 | private static void test_String_charAtExc3(String testStr) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 233 | Assert.assertEquals('N', testStr.charAt(-1)); |
| 234 | } |
| 235 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 236 | private static void test_String_charAtExc4(String testStr) { |
| 237 | Assert.assertEquals('N', testStr.charAt(100)); |
| 238 | } |
| 239 | |
Yevgeny Rouban | 34fa0d9 | 2014-03-13 12:15:58 +0700 | [diff] [blame] | 240 | static int start; |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 241 | private static int[] negIndex = { -100000 }; |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 242 | public static void test_String_indexOf() { |
| 243 | String str0 = ""; |
Yevgeny Rouban | 34fa0d9 | 2014-03-13 12:15:58 +0700 | [diff] [blame] | 244 | String str1 = "/"; |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 245 | String str3 = "abc"; |
| 246 | String str10 = "abcdefghij"; |
| 247 | String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc"; |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 248 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 249 | Assert.assertEquals(str0.indexOf('a'), -1); |
| 250 | Assert.assertEquals(str3.indexOf('a'), 0); |
| 251 | Assert.assertEquals(str3.indexOf('b'), 1); |
| 252 | Assert.assertEquals(str3.indexOf('c'), 2); |
| 253 | Assert.assertEquals(str10.indexOf('j'), 9); |
| 254 | Assert.assertEquals(str40.indexOf('a'), 0); |
| 255 | Assert.assertEquals(str40.indexOf('b'), 38); |
| 256 | Assert.assertEquals(str40.indexOf('c'), 39); |
| 257 | Assert.assertEquals(str0.indexOf('a',20), -1); |
| 258 | Assert.assertEquals(str0.indexOf('a',0), -1); |
| 259 | Assert.assertEquals(str0.indexOf('a',-1), -1); |
Yevgeny Rouban | 34fa0d9 | 2014-03-13 12:15:58 +0700 | [diff] [blame] | 260 | Assert.assertEquals(str1.indexOf('/',++start), -1); |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 261 | Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 262 | Assert.assertEquals(str3.indexOf('a',0), 0); |
| 263 | Assert.assertEquals(str3.indexOf('a',1), -1); |
| 264 | Assert.assertEquals(str3.indexOf('a',1234), -1); |
| 265 | Assert.assertEquals(str3.indexOf('b',0), 1); |
| 266 | Assert.assertEquals(str3.indexOf('b',1), 1); |
| 267 | Assert.assertEquals(str3.indexOf('c',2), 2); |
| 268 | Assert.assertEquals(str10.indexOf('j',5), 9); |
| 269 | Assert.assertEquals(str10.indexOf('j',9), 9); |
| 270 | Assert.assertEquals(str40.indexOf('a',10), 10); |
| 271 | Assert.assertEquals(str40.indexOf('b',40), -1); |
| 272 | |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 273 | testIndexOfNull(); |
| 274 | |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 275 | // Same data as above, but stored so it's not a literal in the next test. -2 stands for |
| 276 | // indexOf(I) instead of indexOf(II). |
| 277 | start--; |
| 278 | int[][] searchData = { |
| 279 | { 'a', -2, -1 }, |
| 280 | { 'a', -2, 0 }, |
| 281 | { 'b', -2, 1 }, |
| 282 | { 'c', -2, 2 }, |
| 283 | { 'j', -2, 9 }, |
| 284 | { 'a', -2, 0 }, |
| 285 | { 'b', -2, 38 }, |
| 286 | { 'c', -2, 39 }, |
| 287 | { 'a', 20, -1 }, |
| 288 | { 'a', 0, -1 }, |
| 289 | { 'a', -1, -1 }, |
| 290 | { '/', ++start, -1 }, |
| 291 | { 'a', negIndex[0], -1 }, |
| 292 | { 'a', 0, 0 }, |
| 293 | { 'a', 1, -1 }, |
| 294 | { 'a', 1234, -1 }, |
| 295 | { 'b', 0, 1 }, |
| 296 | { 'b', 1, 1 }, |
| 297 | { 'c', 2, 2 }, |
| 298 | { 'j', 5, 9 }, |
| 299 | { 'j', 9, 9 }, |
| 300 | { 'a', 10, 10 }, |
| 301 | { 'b', 40, -1 }, |
| 302 | }; |
| 303 | testStringIndexOfChars(searchData); |
| 304 | |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 305 | testSurrogateIndexOf(); |
| 306 | } |
| 307 | |
Andreas Gampe | 21030dd | 2015-05-07 14:46:15 -0700 | [diff] [blame] | 308 | private static void testStringIndexOfChars(int[][] searchData) { |
| 309 | // Use a try-catch to avoid inlining. |
| 310 | try { |
| 311 | testStringIndexOfCharsImpl(searchData); |
| 312 | } catch (Exception e) { |
| 313 | System.out.println("Unexpected exception"); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | private static void testStringIndexOfCharsImpl(int[][] searchData) { |
| 318 | String str0 = ""; |
| 319 | String str1 = "/"; |
| 320 | String str3 = "abc"; |
| 321 | String str10 = "abcdefghij"; |
| 322 | String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc"; |
| 323 | |
| 324 | Assert.assertEquals(str0.indexOf(searchData[0][0]), searchData[0][2]); |
| 325 | Assert.assertEquals(str3.indexOf(searchData[1][0]), searchData[1][2]); |
| 326 | Assert.assertEquals(str3.indexOf(searchData[2][0]), searchData[2][2]); |
| 327 | Assert.assertEquals(str3.indexOf(searchData[3][0]), searchData[3][2]); |
| 328 | Assert.assertEquals(str10.indexOf(searchData[4][0]), searchData[4][2]); |
| 329 | Assert.assertEquals(str40.indexOf(searchData[5][0]), searchData[5][2]); |
| 330 | Assert.assertEquals(str40.indexOf(searchData[6][0]), searchData[6][2]); |
| 331 | Assert.assertEquals(str40.indexOf(searchData[7][0]), searchData[7][2]); |
| 332 | Assert.assertEquals(str0.indexOf(searchData[8][0], searchData[8][1]), searchData[8][2]); |
| 333 | Assert.assertEquals(str0.indexOf(searchData[9][0], searchData[9][1]), searchData[9][2]); |
| 334 | Assert.assertEquals(str0.indexOf(searchData[10][0], searchData[10][1]), searchData[10][2]); |
| 335 | Assert.assertEquals(str1.indexOf(searchData[11][0], searchData[11][1]), searchData[11][2]); |
| 336 | Assert.assertEquals(str1.indexOf(searchData[12][0], searchData[12][1]), searchData[12][2]); |
| 337 | Assert.assertEquals(str3.indexOf(searchData[13][0], searchData[13][1]), searchData[13][2]); |
| 338 | Assert.assertEquals(str3.indexOf(searchData[14][0], searchData[14][1]), searchData[14][2]); |
| 339 | Assert.assertEquals(str3.indexOf(searchData[15][0], searchData[15][1]), searchData[15][2]); |
| 340 | Assert.assertEquals(str3.indexOf(searchData[16][0], searchData[16][1]), searchData[16][2]); |
| 341 | Assert.assertEquals(str3.indexOf(searchData[17][0], searchData[17][1]), searchData[17][2]); |
| 342 | Assert.assertEquals(str3.indexOf(searchData[18][0], searchData[18][1]), searchData[18][2]); |
| 343 | Assert.assertEquals(str10.indexOf(searchData[19][0], searchData[19][1]), searchData[19][2]); |
| 344 | Assert.assertEquals(str10.indexOf(searchData[20][0], searchData[20][1]), searchData[20][2]); |
| 345 | Assert.assertEquals(str40.indexOf(searchData[21][0], searchData[21][1]), searchData[21][2]); |
| 346 | Assert.assertEquals(str40.indexOf(searchData[22][0], searchData[22][1]), searchData[22][2]); |
| 347 | } |
| 348 | |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 349 | private static void testSurrogateIndexOf() { |
| 350 | int supplementaryChar = 0x20b9f; |
| 351 | String surrogatePair = "\ud842\udf9f"; |
| 352 | String stringWithSurrogates = "hello " + surrogatePair + " world"; |
| 353 | |
| 354 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length()); |
| 355 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length()); |
| 356 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6); |
| 357 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 358 | |
| 359 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar - 0x10000), -1); |
| 360 | Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar | 0x80000000), -1); |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | private static void testIndexOfNull() { |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 364 | String strNull = null; |
| 365 | try { |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 366 | testNullIndex(strNull, 'a'); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 367 | Assert.fail(); |
| 368 | } catch (NullPointerException expected) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 369 | } |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 370 | try { |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 371 | testNullIndex(strNull, 'a', 0); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 372 | Assert.fail(); |
| 373 | } catch (NullPointerException expected) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 374 | } |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 375 | try { |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 376 | testNullIndex(strNull, 'a', -1); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 377 | Assert.fail(); |
| 378 | } catch (NullPointerException expected) { |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 379 | } |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 380 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 381 | |
Andreas Gampe | 678e695 | 2015-05-07 16:44:58 -0700 | [diff] [blame] | 382 | private static int testNullIndex(String strNull, int c) { |
| 383 | return strNull.indexOf(c); |
| 384 | } |
| 385 | |
| 386 | private static int testNullIndex(String strNull, int c, int startIndex) { |
| 387 | return strNull.indexOf(c, startIndex); |
| 388 | } |
| 389 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 390 | public static void test_String_compareTo() { |
| 391 | String test = "0123456789"; |
| 392 | String test1 = new String("0123456789"); // different object |
| 393 | String test2 = new String("0123456780"); // different value |
| 394 | String offset = new String("xxx0123456789yyy"); |
| 395 | String sub = offset.substring(3, 13); |
| 396 | String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; |
| 397 | String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy"; |
| 398 | String lc = "abcdefg"; |
| 399 | String uc = "ABCDEFG"; |
| 400 | Object blah = new Object(); |
| 401 | |
| 402 | Assert.assertTrue(lc.toUpperCase().equals(uc)); |
| 403 | |
| 404 | Assert.assertEquals(str32.compareTo(str33), -1); |
| 405 | Assert.assertEquals(str33.compareTo(str32), 1); |
| 406 | |
| 407 | Assert.assertTrue(test.equals(test)); |
| 408 | Assert.assertTrue(test.equals(test1)); |
| 409 | Assert.assertFalse(test.equals(test2)); |
| 410 | |
| 411 | Assert.assertEquals(test.compareTo(test1), 0); |
| 412 | Assert.assertTrue(test1.compareTo(test2) > 0); |
| 413 | Assert.assertTrue(test2.compareTo(test1) < 0); |
| 414 | |
| 415 | // Compare string with a nonzero offset, in left/right side. |
| 416 | Assert.assertEquals(test.compareTo(sub), 0); |
| 417 | Assert.assertEquals(sub.compareTo(test), 0); |
| 418 | Assert.assertTrue(test.equals(sub)); |
| 419 | Assert.assertTrue(sub.equals(test)); |
| 420 | // Same base, one is a substring. |
| 421 | Assert.assertFalse(offset.equals(sub)); |
| 422 | Assert.assertFalse(sub.equals(offset)); |
| 423 | // Wrong class. |
| 424 | Assert.assertFalse(test.equals(blah)); |
| 425 | |
| 426 | // Null lhs - throw. |
| 427 | try { |
| 428 | test.compareTo(null); |
| 429 | Assert.fail("didn't get expected npe"); |
| 430 | } catch (NullPointerException npe) { |
| 431 | } |
| 432 | // Null rhs - okay. |
| 433 | Assert.assertFalse(test.equals(null)); |
| 434 | |
| 435 | test = test.substring(1); |
| 436 | Assert.assertTrue(test.equals("123456789")); |
| 437 | Assert.assertFalse(test.equals(test1)); |
| 438 | |
| 439 | test = test.substring(1); |
| 440 | Assert.assertTrue(test.equals("23456789")); |
| 441 | |
| 442 | test = test.substring(1); |
| 443 | Assert.assertTrue(test.equals("3456789")); |
| 444 | |
| 445 | test = test.substring(1); |
| 446 | Assert.assertTrue(test.equals("456789")); |
| 447 | |
| 448 | test = test.substring(3,5); |
| 449 | Assert.assertTrue(test.equals("78")); |
| 450 | |
| 451 | test = "this/is/a/path"; |
| 452 | String[] strings = test.split("/"); |
| 453 | Assert.assertEquals(4, strings.length); |
| 454 | |
| 455 | Assert.assertEquals("this is a path", test.replaceAll("/", " ")); |
| 456 | Assert.assertEquals("this is a path", test.replace("/", " ")); |
| 457 | } |
| 458 | |
| 459 | public static void test_Math_abs_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 460 | Math.abs(-1); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 461 | Assert.assertEquals(Math.abs(0), 0); |
| 462 | Assert.assertEquals(Math.abs(123), 123); |
| 463 | Assert.assertEquals(Math.abs(-123), 123); |
| 464 | Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 465 | Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE); |
| 466 | Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 467 | Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | public static void test_Math_abs_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 471 | Math.abs(-1L); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 472 | Assert.assertEquals(Math.abs(0L), 0L); |
| 473 | Assert.assertEquals(Math.abs(123L), 123L); |
| 474 | Assert.assertEquals(Math.abs(-123L), 123L); |
| 475 | Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE); |
| 476 | Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE); |
| 477 | Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 478 | Assert.assertEquals(Math.abs(2147483648L), 2147483648L); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 481 | public static void test_Math_min_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 482 | Math.min(1, 0); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 483 | Assert.assertEquals(Math.min(0, 0), 0); |
| 484 | Assert.assertEquals(Math.min(1, 0), 0); |
| 485 | Assert.assertEquals(Math.min(0, 1), 0); |
| 486 | Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0); |
| 487 | Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE); |
| 488 | Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE); |
| 489 | } |
| 490 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 491 | public static void test_Math_max_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 492 | Math.max(1, 0); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 493 | Assert.assertEquals(Math.max(0, 0), 0); |
| 494 | Assert.assertEquals(Math.max(1, 0), 1); |
| 495 | Assert.assertEquals(Math.max(0, 1), 1); |
| 496 | Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 497 | Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0); |
| 498 | Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 499 | } |
| 500 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 501 | public static void test_Math_min_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 502 | Math.min(1L, 0L); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 503 | Assert.assertEquals(Math.min(0L, 0L), 0L); |
| 504 | Assert.assertEquals(Math.min(1L, 0L), 0L); |
| 505 | Assert.assertEquals(Math.min(0L, 1L), 0L); |
| 506 | Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L); |
| 507 | Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE); |
| 508 | Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE); |
| 509 | } |
| 510 | |
| 511 | public static void test_Math_max_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 512 | Math.max(1L, 0L); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 513 | Assert.assertEquals(Math.max(0L, 0L), 0L); |
| 514 | Assert.assertEquals(Math.max(1L, 0L), 1L); |
| 515 | Assert.assertEquals(Math.max(0L, 1L), 1L); |
| 516 | Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE); |
| 517 | Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L); |
| 518 | Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE); |
| 519 | } |
| 520 | |
| 521 | public static void test_Math_min_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 522 | Math.min(1.0f, Float.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 523 | Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN))); |
| 524 | Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f))); |
| 525 | Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f); |
| 526 | Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f); |
| 527 | Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f); |
| 528 | Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f); |
| 529 | Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f); |
| 530 | Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f); |
| 531 | Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f); |
| 532 | Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f); |
| 533 | Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | public static void test_Math_max_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 537 | Math.max(1.0f, Float.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 538 | Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN))); |
| 539 | Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f))); |
| 540 | Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f); |
| 541 | Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f); |
| 542 | Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f); |
| 543 | Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f); |
| 544 | Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f); |
| 545 | Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f); |
| 546 | Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE); |
| 547 | Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE); |
| 548 | Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | public static void test_Math_min_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 552 | Math.min(1.0d, Double.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 553 | Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN))); |
| 554 | Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d))); |
| 555 | Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d); |
| 556 | Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d); |
| 557 | Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d); |
| 558 | Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d); |
| 559 | Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d); |
| 560 | Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d); |
| 561 | Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d); |
| 562 | Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d); |
| 563 | Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | public static void test_Math_max_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 567 | Math.max(1.0d, Double.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 568 | Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN))); |
| 569 | Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d))); |
| 570 | Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d); |
| 571 | Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d); |
| 572 | Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d); |
| 573 | Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d); |
| 574 | Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d); |
| 575 | Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d); |
| 576 | Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE); |
| 577 | Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE); |
| 578 | Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 581 | public static void test_Math_sqrt() { |
| 582 | Math.sqrt(+4.0); |
| 583 | Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0); |
| 584 | Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0); |
| 585 | Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0); |
| 586 | } |
| 587 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 588 | public static void test_Math_ceil() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 589 | Math.ceil(-0.9); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 590 | Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0); |
| 591 | Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0); |
| 592 | Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0); |
| 593 | Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0); |
| 594 | Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0); |
| 595 | Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0); |
| 596 | Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0); |
| 597 | Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0); |
| 598 | Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0); |
| 599 | Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0); |
| 600 | Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0); |
| 601 | Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0); |
| 602 | Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0); |
| 603 | Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0); |
| 604 | Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0); |
Chris Larsen | 8283109 | 2015-08-25 09:06:58 -0700 | [diff] [blame] | 605 | // 2^52 - 1.5 |
| 606 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)), |
| 607 | Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0); |
| 608 | // 2^52 - 0.5 |
| 609 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)), |
| 610 | Double.longBitsToDouble(0x4330000000000000l), 0.0); |
| 611 | // 2^52 |
| 612 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4330000000000000l)), |
| 613 | Double.longBitsToDouble(0x4330000000000000l), 0.0); |
| 614 | // 2^53 - 1 |
| 615 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)), |
| 616 | Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0); |
| 617 | // 2^53 |
| 618 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4340000000000000l)), |
| 619 | Double.longBitsToDouble(0x4340000000000000l), 0.0); |
| 620 | // 2^63 - 2^10 |
| 621 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)), |
| 622 | Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0); |
| 623 | // 2^63 |
| 624 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43E0000000000000l)), |
| 625 | Double.longBitsToDouble(0x43E0000000000000l), 0.0); |
| 626 | // 2^64 |
| 627 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43F0000000000000l)), |
| 628 | Double.longBitsToDouble(0x43F0000000000000l), 0.0); |
| 629 | // -(2^52 - 1.5) |
| 630 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)), |
| 631 | Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0); |
| 632 | // -(2^52 - 0.5) |
| 633 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)), |
| 634 | Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0); |
| 635 | // -2^52 |
| 636 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC330000000000000l)), |
| 637 | Double.longBitsToDouble(0xC330000000000000l), 0.0); |
| 638 | // -(2^53 - 1) |
| 639 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)), |
| 640 | Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0); |
| 641 | // -2^53 |
| 642 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC340000000000000l)), |
| 643 | Double.longBitsToDouble(0xC340000000000000l), 0.0); |
| 644 | // -(2^63 - 2^10) |
| 645 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)), |
| 646 | Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0); |
| 647 | // -2^63 |
| 648 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3E0000000000000l)), |
| 649 | Double.longBitsToDouble(0xC3E0000000000000l), 0.0); |
| 650 | // -2^64 |
| 651 | Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3F0000000000000l)), |
| 652 | Double.longBitsToDouble(0xC3F0000000000000l), 0.0); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 653 | Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0); |
| 654 | Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 655 | Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 656 | } |
| 657 | |
| 658 | public static void test_Math_floor() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 659 | Math.floor(+2.1); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 660 | Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0); |
| 661 | Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0); |
| 662 | Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0); |
| 663 | Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0); |
| 664 | Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0); |
| 665 | Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0); |
| 666 | Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0); |
| 667 | Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0); |
| 668 | Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0); |
| 669 | Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0); |
| 670 | Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0); |
| 671 | Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0); |
Chris Larsen | 8283109 | 2015-08-25 09:06:58 -0700 | [diff] [blame] | 672 | // 2^52 - 1.5 |
| 673 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)), |
| 674 | Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0); |
| 675 | // 2^52 - 0.5 |
| 676 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)), |
| 677 | Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0); |
| 678 | // 2^52 |
| 679 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4330000000000000l)), |
| 680 | Double.longBitsToDouble(0x4330000000000000l), 0.0); |
| 681 | // 2^53 - 1 |
| 682 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)), |
| 683 | Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0); |
| 684 | // 2^53 |
| 685 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4340000000000000l)), |
| 686 | Double.longBitsToDouble(0x4340000000000000l), 0.0); |
| 687 | // 2^63 - 2^10 |
| 688 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)), |
| 689 | Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0); |
| 690 | // 2^63 |
| 691 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43E0000000000000l)), |
| 692 | Double.longBitsToDouble(0x43E0000000000000l), 0.0); |
| 693 | // 2^64 |
| 694 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43F0000000000000l)), |
| 695 | Double.longBitsToDouble(0x43F0000000000000l), 0.0); |
| 696 | // -(2^52 - 1.5) |
| 697 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)), |
| 698 | Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0); |
| 699 | // -(2^52 - 0.5) |
| 700 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)), |
| 701 | Double.longBitsToDouble(0xC330000000000000l), 0.0); |
| 702 | // -2^52 |
| 703 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC330000000000000l)), |
| 704 | Double.longBitsToDouble(0xC330000000000000l), 0.0); |
| 705 | // -(2^53 - 1) |
| 706 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)), |
| 707 | Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0); |
| 708 | // -2^53 |
| 709 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC340000000000000l)), |
| 710 | Double.longBitsToDouble(0xC340000000000000l), 0.0); |
| 711 | // -(2^63 - 2^10) |
| 712 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)), |
| 713 | Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0); |
| 714 | // -2^63 |
| 715 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3E0000000000000l)), |
| 716 | Double.longBitsToDouble(0xC3E0000000000000l), 0.0); |
| 717 | // -2^64 |
| 718 | Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3F0000000000000l)), |
| 719 | Double.longBitsToDouble(0xC3F0000000000000l), 0.0); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 720 | Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0); |
| 721 | Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 722 | Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 723 | } |
| 724 | |
| 725 | public static void test_Math_rint() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 726 | Math.rint(+2.1); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 727 | Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0); |
| 728 | Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0); |
| 729 | Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0); |
| 730 | Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0); |
| 731 | Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0); |
| 732 | Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0); |
| 733 | Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0); |
| 734 | Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0); |
| 735 | Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0); |
| 736 | Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0); |
| 737 | Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0); |
| 738 | Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0); |
Chris Larsen | 8283109 | 2015-08-25 09:06:58 -0700 | [diff] [blame] | 739 | // 2^52 - 1.5 |
| 740 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)), |
| 741 | Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0); |
| 742 | // 2^52 - 0.5 |
| 743 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)), |
| 744 | Double.longBitsToDouble(0x4330000000000000l), 0.0); |
| 745 | // 2^52 |
| 746 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4330000000000000l)), |
| 747 | Double.longBitsToDouble(0x4330000000000000l), 0.0); |
| 748 | // 2^53 - 1 |
| 749 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)), |
| 750 | Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0); |
| 751 | // 2^53 |
| 752 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4340000000000000l)), |
| 753 | Double.longBitsToDouble(0x4340000000000000l), 0.0); |
| 754 | // 2^63 - 2^10 |
| 755 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)), |
| 756 | Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0); |
| 757 | // 2^63 |
| 758 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43E0000000000000l)), |
| 759 | Double.longBitsToDouble(0x43E0000000000000l), 0.0); |
| 760 | // 2^64 |
| 761 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43F0000000000000l)), |
| 762 | Double.longBitsToDouble(0x43F0000000000000l), 0.0); |
| 763 | // -(2^52 - 1.5) |
| 764 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)), |
| 765 | Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0); |
| 766 | // -(2^52 - 0.5) |
| 767 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)), |
| 768 | Double.longBitsToDouble(0xC330000000000000l), 0.0); |
| 769 | // -2^52 |
| 770 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC330000000000000l)), |
| 771 | Double.longBitsToDouble(0xC330000000000000l), 0.0); |
| 772 | // -(2^53 - 1) |
| 773 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)), |
| 774 | Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0); |
| 775 | // -2^53 |
| 776 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC340000000000000l)), |
| 777 | Double.longBitsToDouble(0xC340000000000000l), 0.0); |
| 778 | // -(2^63 - 2^10) |
| 779 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)), |
| 780 | Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0); |
| 781 | // -2^63 |
| 782 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3E0000000000000l)), |
| 783 | Double.longBitsToDouble(0xC3E0000000000000l), 0.0); |
| 784 | // -2^64 |
| 785 | Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3F0000000000000l)), |
| 786 | Double.longBitsToDouble(0xC3F0000000000000l), 0.0); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 787 | Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0); |
| 788 | Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 789 | Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 790 | } |
| 791 | |
| 792 | public static void test_Math_round_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 793 | Math.round(2.1d); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 794 | Assert.assertEquals(Math.round(+0.0d), (long)+0.0); |
| 795 | Assert.assertEquals(Math.round(-0.0d), (long)+0.0); |
| 796 | Assert.assertEquals(Math.round(2.0d), 2l); |
| 797 | Assert.assertEquals(Math.round(2.1d), 2l); |
| 798 | Assert.assertEquals(Math.round(2.5d), 3l); |
| 799 | Assert.assertEquals(Math.round(2.9d), 3l); |
| 800 | Assert.assertEquals(Math.round(3.0d), 3l); |
| 801 | Assert.assertEquals(Math.round(-2.0d), -2l); |
| 802 | Assert.assertEquals(Math.round(-2.1d), -2l); |
| 803 | Assert.assertEquals(Math.round(-2.5d), -2l); |
| 804 | Assert.assertEquals(Math.round(-2.9d), -3l); |
| 805 | Assert.assertEquals(Math.round(-3.0d), -3l); |
Yi Kong | 879ca67 | 2015-11-18 14:11:44 +0000 | [diff] [blame] | 806 | Assert.assertEquals(Math.round(0.49999999999999994d), 0l); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 807 | Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d); |
| 808 | Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE); |
| 809 | Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE); |
| 810 | Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE); |
| 811 | Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE); |
| 812 | } |
| 813 | |
| 814 | public static void test_Math_round_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 815 | Math.round(2.1f); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 816 | Assert.assertEquals(Math.round(+0.0f), (int)+0.0); |
| 817 | Assert.assertEquals(Math.round(-0.0f), (int)+0.0); |
| 818 | Assert.assertEquals(Math.round(2.0f), 2); |
| 819 | Assert.assertEquals(Math.round(2.1f), 2); |
| 820 | Assert.assertEquals(Math.round(2.5f), 3); |
| 821 | Assert.assertEquals(Math.round(2.9f), 3); |
| 822 | Assert.assertEquals(Math.round(3.0f), 3); |
| 823 | Assert.assertEquals(Math.round(-2.0f), -2); |
| 824 | Assert.assertEquals(Math.round(-2.1f), -2); |
| 825 | Assert.assertEquals(Math.round(-2.5f), -2); |
| 826 | Assert.assertEquals(Math.round(-2.9f), -3); |
| 827 | Assert.assertEquals(Math.round(-3.0f), -3); |
| 828 | Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f); |
| 829 | Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE); |
| 830 | Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE); |
| 831 | Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE); |
| 832 | Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE); |
| 833 | } |
| 834 | |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 835 | public static void test_StrictMath_abs_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 836 | StrictMath.abs(-1); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 837 | Assert.assertEquals(StrictMath.abs(0), 0); |
| 838 | Assert.assertEquals(StrictMath.abs(123), 123); |
| 839 | Assert.assertEquals(StrictMath.abs(-123), 123); |
| 840 | Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 841 | Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE); |
| 842 | Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE); |
| 843 | Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE); |
| 844 | } |
| 845 | |
| 846 | public static void test_StrictMath_abs_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 847 | StrictMath.abs(-1L); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 848 | Assert.assertEquals(StrictMath.abs(0L), 0L); |
| 849 | Assert.assertEquals(StrictMath.abs(123L), 123L); |
| 850 | Assert.assertEquals(StrictMath.abs(-123L), 123L); |
| 851 | Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE); |
| 852 | Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE); |
| 853 | Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE); |
| 854 | } |
| 855 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 856 | public static void test_StrictMath_min_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 857 | StrictMath.min(1, 0); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 858 | Assert.assertEquals(StrictMath.min(0, 0), 0); |
| 859 | Assert.assertEquals(StrictMath.min(1, 0), 0); |
| 860 | Assert.assertEquals(StrictMath.min(0, 1), 0); |
| 861 | Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0); |
| 862 | Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE); |
| 863 | Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE); |
| 864 | } |
| 865 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 866 | public static void test_StrictMath_max_I() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 867 | StrictMath.max(1, 0); |
Sebastien Hertz | bf1442d | 2013-03-05 15:12:40 +0100 | [diff] [blame] | 868 | Assert.assertEquals(StrictMath.max(0, 0), 0); |
| 869 | Assert.assertEquals(StrictMath.max(1, 0), 1); |
| 870 | Assert.assertEquals(StrictMath.max(0, 1), 1); |
| 871 | Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 872 | Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0); |
| 873 | Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE); |
| 874 | } |
| 875 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 876 | public static void test_StrictMath_min_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 877 | StrictMath.min(1L, 0L); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 878 | Assert.assertEquals(StrictMath.min(0L, 0L), 0L); |
| 879 | Assert.assertEquals(StrictMath.min(1L, 0L), 0L); |
| 880 | Assert.assertEquals(StrictMath.min(0L, 1L), 0L); |
| 881 | Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L); |
| 882 | Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE); |
| 883 | Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE); |
| 884 | } |
| 885 | |
| 886 | public static void test_StrictMath_max_J() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 887 | StrictMath.max(1L, 0L); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 888 | Assert.assertEquals(StrictMath.max(0L, 0L), 0L); |
| 889 | Assert.assertEquals(StrictMath.max(1L, 0L), 1L); |
| 890 | Assert.assertEquals(StrictMath.max(0L, 1L), 1L); |
| 891 | Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE); |
| 892 | Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L); |
| 893 | Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE); |
| 894 | } |
| 895 | |
| 896 | public static void test_StrictMath_min_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 897 | StrictMath.min(1.0f, Float.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 898 | Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN))); |
| 899 | Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f))); |
| 900 | Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f); |
| 901 | Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f); |
| 902 | Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f); |
| 903 | Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f); |
| 904 | Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f); |
| 905 | Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f); |
| 906 | Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f); |
| 907 | Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f); |
| 908 | Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | public static void test_StrictMath_max_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 912 | StrictMath.max(1.0f, Float.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 913 | Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN))); |
| 914 | Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f))); |
| 915 | Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f); |
| 916 | Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f); |
| 917 | Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f); |
| 918 | Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f); |
| 919 | Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f); |
| 920 | Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f); |
| 921 | Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE); |
| 922 | Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE); |
| 923 | Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | public static void test_StrictMath_min_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 927 | StrictMath.min(1.0d, Double.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 928 | Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN))); |
| 929 | Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d))); |
| 930 | Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d); |
| 931 | Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d); |
| 932 | Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d); |
| 933 | Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d); |
| 934 | Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d); |
| 935 | Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d); |
| 936 | Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d); |
| 937 | Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d); |
| 938 | Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | public static void test_StrictMath_max_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 942 | StrictMath.max(1.0d, Double.NaN); |
Alexei Zavjalov | 1222c96 | 2014-07-16 00:54:13 +0700 | [diff] [blame] | 943 | Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN))); |
| 944 | Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d))); |
| 945 | Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d); |
| 946 | Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d); |
| 947 | Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d); |
| 948 | Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d); |
| 949 | Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d); |
| 950 | Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d); |
| 951 | Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE); |
| 952 | Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE); |
| 953 | Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 954 | } |
| 955 | |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 956 | public static void test_StrictMath_sqrt() { |
| 957 | StrictMath.sqrt(+4.0); |
| 958 | Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0); |
| 959 | Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0); |
| 960 | Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0); |
| 961 | } |
| 962 | |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 963 | public static void test_StrictMath_ceil() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 964 | StrictMath.ceil(-0.9); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 965 | Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0); |
| 966 | Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0); |
| 967 | Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0); |
| 968 | Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0); |
| 969 | Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0); |
| 970 | Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0); |
| 971 | Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0); |
| 972 | Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0); |
| 973 | Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0); |
| 974 | Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0); |
| 975 | Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0); |
| 976 | Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0); |
| 977 | Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0); |
| 978 | Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0); |
| 979 | Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0); |
| 980 | Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0); |
| 981 | Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 982 | Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 983 | } |
| 984 | |
| 985 | public static void test_StrictMath_floor() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 986 | StrictMath.floor(+2.1); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 987 | Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0); |
| 988 | Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0); |
| 989 | Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0); |
| 990 | Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0); |
| 991 | Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0); |
| 992 | Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0); |
| 993 | Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0); |
| 994 | Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0); |
| 995 | Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0); |
| 996 | Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0); |
| 997 | Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0); |
| 998 | Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0); |
| 999 | Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0); |
| 1000 | Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 1001 | Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 1002 | } |
| 1003 | |
| 1004 | public static void test_StrictMath_rint() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1005 | StrictMath.rint(+2.1); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 1006 | Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0); |
| 1007 | Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0); |
| 1008 | Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0); |
| 1009 | Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0); |
| 1010 | Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0); |
| 1011 | Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0); |
| 1012 | Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0); |
| 1013 | Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0); |
| 1014 | Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0); |
| 1015 | Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0); |
| 1016 | Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0); |
| 1017 | Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0); |
| 1018 | Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0); |
| 1019 | Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0); |
| 1020 | Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0); |
| 1021 | } |
| 1022 | |
| 1023 | public static void test_StrictMath_round_D() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1024 | StrictMath.round(2.1d); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 1025 | Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0); |
| 1026 | Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0); |
| 1027 | Assert.assertEquals(StrictMath.round(2.0d), 2l); |
| 1028 | Assert.assertEquals(StrictMath.round(2.1d), 2l); |
| 1029 | Assert.assertEquals(StrictMath.round(2.5d), 3l); |
| 1030 | Assert.assertEquals(StrictMath.round(2.9d), 3l); |
| 1031 | Assert.assertEquals(StrictMath.round(3.0d), 3l); |
| 1032 | Assert.assertEquals(StrictMath.round(-2.0d), -2l); |
| 1033 | Assert.assertEquals(StrictMath.round(-2.1d), -2l); |
| 1034 | Assert.assertEquals(StrictMath.round(-2.5d), -2l); |
| 1035 | Assert.assertEquals(StrictMath.round(-2.9d), -3l); |
| 1036 | Assert.assertEquals(StrictMath.round(-3.0d), -3l); |
Yi Kong | 879ca67 | 2015-11-18 14:11:44 +0000 | [diff] [blame] | 1037 | Assert.assertEquals(StrictMath.round(0.49999999999999994d), 0l); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 1038 | Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d); |
| 1039 | Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE); |
| 1040 | Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE); |
| 1041 | Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE); |
| 1042 | Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE); |
| 1043 | } |
| 1044 | |
| 1045 | public static void test_StrictMath_round_F() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1046 | StrictMath.round(2.1f); |
Serban Constantinescu | 2eba1fa | 2014-07-31 19:07:17 +0100 | [diff] [blame] | 1047 | Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0); |
| 1048 | Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0); |
| 1049 | Assert.assertEquals(StrictMath.round(2.0f), 2); |
| 1050 | Assert.assertEquals(StrictMath.round(2.1f), 2); |
| 1051 | Assert.assertEquals(StrictMath.round(2.5f), 3); |
| 1052 | Assert.assertEquals(StrictMath.round(2.9f), 3); |
| 1053 | Assert.assertEquals(StrictMath.round(3.0f), 3); |
| 1054 | Assert.assertEquals(StrictMath.round(-2.0f), -2); |
| 1055 | Assert.assertEquals(StrictMath.round(-2.1f), -2); |
| 1056 | Assert.assertEquals(StrictMath.round(-2.5f), -2); |
| 1057 | Assert.assertEquals(StrictMath.round(-2.9f), -3); |
| 1058 | Assert.assertEquals(StrictMath.round(-3.0f), -3); |
| 1059 | Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f); |
| 1060 | Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE); |
| 1061 | Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE); |
| 1062 | Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE); |
| 1063 | Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE); |
| 1064 | } |
| 1065 | |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 1066 | public static void test_Float_floatToRawIntBits() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1067 | Float.floatToRawIntBits(-1.0f); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 1068 | Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000); |
| 1069 | Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0); |
| 1070 | Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000); |
| 1071 | Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000); |
| 1072 | Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000); |
| 1073 | Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000); |
| 1074 | } |
| 1075 | |
| 1076 | public static void test_Float_intBitsToFloat() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1077 | Float.intBitsToFloat(0xbf800000); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 1078 | Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f); |
| 1079 | Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f); |
| 1080 | Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f); |
| 1081 | Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN); |
| 1082 | Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY); |
| 1083 | Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY); |
| 1084 | } |
| 1085 | |
| 1086 | public static void test_Double_doubleToRawLongBits() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1087 | Double.doubleToRawLongBits(-1.0); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 1088 | Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L); |
| 1089 | Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L); |
| 1090 | Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L); |
| 1091 | Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L); |
| 1092 | Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L); |
| 1093 | Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L); |
| 1094 | } |
| 1095 | |
| 1096 | public static void test_Double_longBitsToDouble() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1097 | Double.longBitsToDouble(0xbff0000000000000L); |
Elliott Hughes | 28c384b | 2012-06-15 16:46:25 -0700 | [diff] [blame] | 1098 | Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0); |
| 1099 | Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0); |
| 1100 | Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0); |
| 1101 | Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN); |
| 1102 | Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY); |
| 1103 | Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY); |
| 1104 | } |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1105 | |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 1106 | public static void test_Short_reverseBytes() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1107 | Short.reverseBytes((short)0x1357); |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 1108 | Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000); |
| 1109 | Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff); |
| 1110 | Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080); |
| 1111 | Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000); |
| 1112 | Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301); |
| 1113 | Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745); |
| 1114 | Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89); |
| 1115 | Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd); |
| 1116 | } |
| 1117 | |
| 1118 | public static void test_Integer_reverseBytes() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1119 | Integer.reverseBytes(0x13579bdf); |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 1120 | Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000); |
| 1121 | Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff); |
| 1122 | Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080); |
| 1123 | Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000); |
| 1124 | Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301); |
| 1125 | Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89); |
| 1126 | } |
| 1127 | |
| 1128 | public static void test_Long_reverseBytes() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1129 | Long.reverseBytes(0x13579bdf2468ace0L); |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 1130 | Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L); |
| 1131 | Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL); |
| 1132 | Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L); |
| 1133 | Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L); |
| 1134 | Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L); |
| 1135 | } |
| 1136 | |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1137 | public static void test_Integer_reverse() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1138 | Integer.reverse(0x12345678); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1139 | Assert.assertEquals(Integer.reverse(1), 0x80000000); |
| 1140 | Assert.assertEquals(Integer.reverse(-1), 0xffffffff); |
| 1141 | Assert.assertEquals(Integer.reverse(0), 0); |
| 1142 | Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48); |
| 1143 | Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1); |
| 1144 | Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe); |
| 1145 | Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1); |
| 1146 | } |
| 1147 | |
| 1148 | public static void test_Long_reverse() { |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1149 | Long.reverse(0x1234567812345678L); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1150 | Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L); |
| 1151 | Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL); |
| 1152 | Assert.assertEquals(Long.reverse(0L), 0L); |
Zheng Xu | a3fe742 | 2014-07-09 14:03:15 +0800 | [diff] [blame] | 1153 | Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L); |
| 1154 | Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L); |
| 1155 | Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL); |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1156 | Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L); |
Andreas Gampe | 575422f | 2015-07-07 13:25:58 -0700 | [diff] [blame] | 1157 | |
| 1158 | Assert.assertEquals(test_Long_reverse_b22324327(0xaaaaaaaaaaaaaaaaL, 0x5555555555555555L), |
| 1159 | 157472205507277347L); |
| 1160 | } |
| 1161 | |
| 1162 | // A bit more complicated than the above. Use local variables to stress register allocation. |
| 1163 | private static long test_Long_reverse_b22324327(long l1, long l2) { |
| 1164 | // A couple of local integers. Use them in a loop, so they get promoted. |
| 1165 | int i1 = 0, i2 = 1, i3 = 2, i4 = 3, i5 = 4, i6 = 5, i7 = 6, i8 = 7; |
| 1166 | for (int k = 0; k < 10; k++) { |
| 1167 | i1 += 1; |
| 1168 | i2 += 2; |
| 1169 | i3 += 3; |
| 1170 | i4 += 4; |
| 1171 | i5 += 5; |
| 1172 | i6 += 6; |
| 1173 | i7 += 7; |
| 1174 | i8 += 8; |
| 1175 | } |
| 1176 | |
| 1177 | // Do the Long.reverse() calls, save the results. |
| 1178 | long r1 = Long.reverse(l1); |
| 1179 | long r2 = Long.reverse(l2); |
| 1180 | |
| 1181 | // Some more looping with the ints. |
| 1182 | for (int k = 0; k < 10; k++) { |
| 1183 | i1 += 1; |
| 1184 | i2 += 2; |
| 1185 | i3 += 3; |
| 1186 | i4 += 4; |
| 1187 | i5 += 5; |
| 1188 | i6 += 6; |
| 1189 | i7 += 7; |
| 1190 | i8 += 8; |
| 1191 | } |
| 1192 | |
| 1193 | // Include everything in the result, so things are kept live. Try to be a little bit clever to |
| 1194 | // avoid things being folded somewhere. |
| 1195 | return (r1 / i1) + (r2 / i2) + i3 + i4 + i5 + i6 + i7 + i8; |
Serban Constantinescu | 23abec9 | 2014-07-02 16:13:38 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 1198 | public static boolean doThrow = false; |
| 1199 | |
| 1200 | public static int $noinline$return_int_zero() { |
| 1201 | if (doThrow) { |
| 1202 | throw new Error(); |
| 1203 | } |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 1207 | public static void test_Integer_numberOfLeadingZeros() { |
| 1208 | Assert.assertEquals(Integer.numberOfLeadingZeros(0), Integer.SIZE); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 1209 | Assert.assertEquals(Integer.numberOfLeadingZeros(1), Integer.SIZE - 1); |
| 1210 | Assert.assertEquals(Integer.numberOfLeadingZeros(1 << (Integer.SIZE-1)), 0); |
| 1211 | Assert.assertEquals(Integer.numberOfLeadingZeros($noinline$return_int_zero()), Integer.SIZE); |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 1212 | for (int i = 0; i < Integer.SIZE; i++) { |
| 1213 | Assert.assertEquals(Integer.numberOfLeadingZeros(1 << i), Integer.SIZE - 1 - i); |
| 1214 | Assert.assertEquals(Integer.numberOfLeadingZeros((1 << i) | 1), Integer.SIZE - 1 - i); |
| 1215 | Assert.assertEquals(Integer.numberOfLeadingZeros(0xFFFFFFFF >>> i), i); |
| 1216 | } |
| 1217 | } |
| 1218 | |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 1219 | public static long $noinline$return_long_zero() { |
| 1220 | if (doThrow) { |
| 1221 | throw new Error(); |
| 1222 | } |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 1226 | public static void test_Long_numberOfLeadingZeros() { |
| 1227 | Assert.assertEquals(Long.numberOfLeadingZeros(0L), Long.SIZE); |
Mark Mendell | d589767 | 2015-08-12 21:16:41 -0400 | [diff] [blame] | 1228 | Assert.assertEquals(Long.numberOfLeadingZeros(1L), Long.SIZE - 1); |
| 1229 | Assert.assertEquals(Long.numberOfLeadingZeros(1L << ((Long.SIZE/2)-1)), Long.SIZE/2); |
| 1230 | Assert.assertEquals(Long.numberOfLeadingZeros(1L << (Long.SIZE-1)), 0); |
| 1231 | Assert.assertEquals(Long.numberOfLeadingZeros($noinline$return_long_zero()), Long.SIZE); |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 1232 | for (int i = 0; i < Long.SIZE; i++) { |
| 1233 | Assert.assertEquals(Long.numberOfLeadingZeros(1L << i), Long.SIZE - 1 - i); |
| 1234 | Assert.assertEquals(Long.numberOfLeadingZeros((1L << i) | 1L), Long.SIZE - 1 - i); |
| 1235 | Assert.assertEquals(Long.numberOfLeadingZeros(0xFFFFFFFFFFFFFFFFL >>> i), i); |
| 1236 | } |
| 1237 | } |
| 1238 | |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1239 | static Object runtime; |
| 1240 | static Method address_of; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1241 | static Method new_non_movable_array; |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1242 | static Method peek_byte; |
| 1243 | static Method peek_short; |
| 1244 | static Method peek_int; |
| 1245 | static Method peek_long; |
| 1246 | static Method poke_byte; |
| 1247 | static Method poke_short; |
| 1248 | static Method poke_int; |
| 1249 | static Method poke_long; |
| 1250 | |
| 1251 | public static void initSupportMethodsForPeekPoke() throws Exception { |
| 1252 | Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime"); |
| 1253 | Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime"); |
| 1254 | runtime = get_runtime.invoke(null); |
| 1255 | address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class); |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1256 | new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1257 | |
| 1258 | Class<?> io_memory = Class.forName("libcore.io.Memory"); |
| 1259 | peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE); |
| 1260 | peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE); |
| 1261 | peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE); |
| 1262 | peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE); |
| 1263 | poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE); |
| 1264 | poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE); |
| 1265 | poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE); |
| 1266 | poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE); |
| 1267 | } |
| 1268 | |
| 1269 | public static void test_Memory_peekByte() throws Exception { |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1270 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1271 | b[0] = 0x12; |
| 1272 | b[1] = 0x11; |
| 1273 | long address = (long)address_of.invoke(runtime, b); |
| 1274 | Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12); |
| 1275 | Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11); |
| 1276 | } |
| 1277 | |
| 1278 | public static void test_Memory_peekShort() throws Exception { |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1279 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1280 | b[0] = 0x13; |
| 1281 | b[1] = 0x12; |
| 1282 | b[2] = 0x11; |
| 1283 | long address = (long)address_of.invoke(runtime, b); |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1284 | peek_short.invoke(null, address, false); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1285 | Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read |
| 1286 | Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read |
| 1287 | } |
| 1288 | |
| 1289 | public static void test_Memory_peekInt() throws Exception { |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1290 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1291 | b[0] = 0x15; |
| 1292 | b[1] = 0x14; |
| 1293 | b[2] = 0x13; |
| 1294 | b[3] = 0x12; |
| 1295 | b[4] = 0x11; |
| 1296 | long address = (long)address_of.invoke(runtime, b); |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1297 | peek_int.invoke(null, address, false); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1298 | Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415); |
| 1299 | Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314); |
| 1300 | } |
| 1301 | |
| 1302 | public static void test_Memory_peekLong() throws Exception { |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1303 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1304 | b[0] = 0x19; |
| 1305 | b[1] = 0x18; |
| 1306 | b[2] = 0x17; |
| 1307 | b[3] = 0x16; |
| 1308 | b[4] = 0x15; |
| 1309 | b[5] = 0x14; |
| 1310 | b[6] = 0x13; |
| 1311 | b[7] = 0x12; |
| 1312 | b[8] = 0x11; |
| 1313 | long address = (long)address_of.invoke(runtime, b); |
Chao-ying Fu | ff87d7b | 2015-01-19 15:51:57 -0800 | [diff] [blame] | 1314 | peek_long.invoke(null, address, false); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1315 | Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L); |
| 1316 | Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L); |
| 1317 | } |
| 1318 | |
| 1319 | public static void test_Memory_pokeByte() throws Exception { |
| 1320 | byte[] r = {0x11, 0x12}; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1321 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1322 | long address = (long)address_of.invoke(runtime, b); |
| 1323 | poke_byte.invoke(null, address, (byte)0x11); |
| 1324 | poke_byte.invoke(null, address + 1, (byte)0x12); |
| 1325 | Assert.assertTrue(Arrays.equals(r, b)); |
| 1326 | } |
| 1327 | |
| 1328 | public static void test_Memory_pokeShort() throws Exception { |
| 1329 | byte[] ra = {0x12, 0x11, 0x13}; |
| 1330 | byte[] ru = {0x12, 0x22, 0x21}; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1331 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1332 | long address = (long)address_of.invoke(runtime, b); |
| 1333 | |
| 1334 | // Aligned write |
| 1335 | b[2] = 0x13; |
| 1336 | poke_short.invoke(null, address, (short)0x1112, false); |
| 1337 | Assert.assertTrue(Arrays.equals(ra, b)); |
| 1338 | |
| 1339 | // Unaligned write |
| 1340 | poke_short.invoke(null, address + 1, (short)0x2122, false); |
| 1341 | Assert.assertTrue(Arrays.equals(ru, b)); |
| 1342 | } |
| 1343 | |
| 1344 | public static void test_Memory_pokeInt() throws Exception { |
| 1345 | byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15}; |
| 1346 | byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21}; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1347 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1348 | long address = (long)address_of.invoke(runtime, b); |
| 1349 | |
| 1350 | b[4] = 0x15; |
| 1351 | poke_int.invoke(null, address, (int)0x11121314, false); |
| 1352 | Assert.assertTrue(Arrays.equals(ra, b)); |
| 1353 | |
| 1354 | poke_int.invoke(null, address + 1, (int)0x21222324, false); |
| 1355 | Assert.assertTrue(Arrays.equals(ru, b)); |
| 1356 | } |
| 1357 | |
| 1358 | public static void test_Memory_pokeLong() throws Exception { |
| 1359 | byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19}; |
| 1360 | byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21}; |
Zuo Wang | f37a88b | 2014-07-10 04:26:41 -0700 | [diff] [blame] | 1361 | byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9); |
Alexei Zavjalov | eb24bae | 2014-07-08 16:27:17 +0700 | [diff] [blame] | 1362 | long address = (long)address_of.invoke(runtime, b); |
| 1363 | |
| 1364 | b[8] = 0x19; |
| 1365 | poke_long.invoke(null, address, (long)0x1112131415161718L, false); |
| 1366 | Assert.assertTrue(Arrays.equals(ra, b)); |
| 1367 | |
| 1368 | poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false); |
| 1369 | Assert.assertTrue(Arrays.equals(ru, b)); |
| 1370 | } |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 1371 | |
| 1372 | public static void test_Integer_numberOfTrailingZeros() { |
| 1373 | Assert.assertEquals(Integer.numberOfTrailingZeros(0), Integer.SIZE); |
| 1374 | for (int i = 0; i < Integer.SIZE; i++) { |
| 1375 | Assert.assertEquals( |
| 1376 | Integer.numberOfTrailingZeros(0x80000000 >> i), |
| 1377 | Integer.SIZE - 1 - i); |
| 1378 | Assert.assertEquals( |
| 1379 | Integer.numberOfTrailingZeros((0x80000000 >> i) | 0x80000000), |
| 1380 | Integer.SIZE - 1 - i); |
| 1381 | Assert.assertEquals(Integer.numberOfTrailingZeros(1 << i), i); |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | public static void test_Long_numberOfTrailingZeros() { |
| 1386 | Assert.assertEquals(Long.numberOfTrailingZeros(0), Long.SIZE); |
| 1387 | for (int i = 0; i < Long.SIZE; i++) { |
| 1388 | Assert.assertEquals( |
| 1389 | Long.numberOfTrailingZeros(0x8000000000000000L >> i), |
| 1390 | Long.SIZE - 1 - i); |
| 1391 | Assert.assertEquals( |
| 1392 | Long.numberOfTrailingZeros((0x8000000000000000L >> i) | 0x8000000000000000L), |
| 1393 | Long.SIZE - 1 - i); |
| 1394 | Assert.assertEquals(Long.numberOfTrailingZeros(1L << i), i); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | public static void test_Integer_rotateRight() throws Exception { |
| 1399 | Assert.assertEquals(Integer.rotateRight(0x11, 0), 0x11); |
| 1400 | |
| 1401 | Assert.assertEquals(Integer.rotateRight(0x11, 1), 0x80000008); |
| 1402 | Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE - 1), 0x22); |
| 1403 | Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE), 0x11); |
| 1404 | Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE + 1), 0x80000008); |
| 1405 | |
| 1406 | Assert.assertEquals(Integer.rotateRight(0x11, -1), 0x22); |
| 1407 | Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE - 1)), 0x80000008); |
| 1408 | Assert.assertEquals(Integer.rotateRight(0x11, -Integer.SIZE), 0x11); |
| 1409 | Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE + 1)), 0x22); |
| 1410 | |
| 1411 | Assert.assertEquals(Integer.rotateRight(0x80000000, 1), 0x40000000); |
| 1412 | |
| 1413 | for (int i = 0; i < Integer.SIZE; i++) { |
| 1414 | Assert.assertEquals( |
| 1415 | Integer.rotateRight(0xBBAAAADD, i), |
| 1416 | (0xBBAAAADD >>> i) | (0xBBAAAADD << (Integer.SIZE - i))); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | public static void test_Long_rotateRight() throws Exception { |
| 1421 | Assert.assertEquals(Long.rotateRight(0x11, 0), 0x11); |
| 1422 | |
| 1423 | Assert.assertEquals(Long.rotateRight(0x11, 1), 0x8000000000000008L); |
| 1424 | Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE - 1), 0x22); |
| 1425 | Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE), 0x11); |
| 1426 | Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE + 1), 0x8000000000000008L); |
| 1427 | |
| 1428 | Assert.assertEquals(Long.rotateRight(0x11, -1), 0x22); |
| 1429 | Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE - 1)), 0x8000000000000008L); |
| 1430 | Assert.assertEquals(Long.rotateRight(0x11, -Long.SIZE), 0x11); |
| 1431 | Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE + 1)), 0x22); |
| 1432 | |
| 1433 | Assert.assertEquals(Long.rotateRight(0x8000000000000000L, 1), 0x4000000000000000L); |
| 1434 | |
| 1435 | for (int i = 0; i < Long.SIZE; i++) { |
| 1436 | Assert.assertEquals( |
| 1437 | Long.rotateRight(0xBBAAAADDFF0000DDL, i), |
| 1438 | (0xBBAAAADDFF0000DDL >>> i) | (0xBBAAAADDFF0000DDL << (Long.SIZE - i))); |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | public static void test_Integer_rotateLeft() throws Exception { |
| 1443 | Assert.assertEquals(Integer.rotateLeft(0x11, 0), 0x11); |
| 1444 | |
| 1445 | Assert.assertEquals(Integer.rotateLeft(0x11, 1), 0x22); |
| 1446 | Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE - 1), 0x80000008); |
| 1447 | Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE), 0x11); |
| 1448 | Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE + 1), 0x22); |
| 1449 | |
| 1450 | Assert.assertEquals(Integer.rotateLeft(0x11, -1), 0x80000008); |
| 1451 | Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE - 1)), 0x22); |
| 1452 | Assert.assertEquals(Integer.rotateLeft(0x11, -Integer.SIZE), 0x11); |
| 1453 | Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE + 1)), 0x80000008); |
| 1454 | |
| 1455 | Assert.assertEquals(Integer.rotateLeft(0xC0000000, 1), 0x80000001); |
| 1456 | |
| 1457 | for (int i = 0; i < Integer.SIZE; i++) { |
| 1458 | Assert.assertEquals( |
| 1459 | Integer.rotateLeft(0xBBAAAADD, i), |
| 1460 | (0xBBAAAADD << i) | (0xBBAAAADD >>> (Integer.SIZE - i))); |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | public static void test_Long_rotateLeft() throws Exception { |
| 1465 | Assert.assertEquals(Long.rotateLeft(0x11, 0), 0x11); |
| 1466 | |
| 1467 | Assert.assertEquals(Long.rotateLeft(0x11, 1), 0x22); |
| 1468 | Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE - 1), 0x8000000000000008L); |
| 1469 | Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE), 0x11); |
| 1470 | Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE + 1), 0x22); |
| 1471 | |
| 1472 | Assert.assertEquals(Long.rotateLeft(0x11, -1), 0x8000000000000008L); |
| 1473 | Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE - 1)), 0x22); |
| 1474 | Assert.assertEquals(Long.rotateLeft(0x11, -Long.SIZE), 0x11); |
| 1475 | Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE + 1)), 0x8000000000000008L); |
| 1476 | |
| 1477 | Assert.assertEquals(Long.rotateLeft(0xC000000000000000L, 1), 0x8000000000000001L); |
| 1478 | |
| 1479 | for (int i = 0; i < Long.SIZE; i++) { |
| 1480 | Assert.assertEquals( |
| 1481 | Long.rotateLeft(0xBBAAAADDFF0000DDL, i), |
| 1482 | (0xBBAAAADDFF0000DDL << i) | (0xBBAAAADDFF0000DDL >>> (Long.SIZE - i))); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | public static void test_Integer_rotateRightLeft() throws Exception { |
| 1487 | for (int i = 0; i < Integer.SIZE * 2; i++) { |
| 1488 | Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, i), |
| 1489 | Integer.rotateRight(0xBBAAAADD, -i)); |
| 1490 | Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, -i), |
| 1491 | Integer.rotateRight(0xBBAAAADD, i)); |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | public static void test_Long_rotateRightLeft() throws Exception { |
| 1496 | for (int i = 0; i < Long.SIZE * 2; i++) { |
| 1497 | Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, i), |
| 1498 | Long.rotateRight(0xBBAAAADDFF0000DDL, -i)); |
| 1499 | Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, -i), |
| 1500 | Long.rotateRight(0xBBAAAADDFF0000DDL, i)); |
| 1501 | } |
| 1502 | } |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1503 | } |