1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package libcore.java.lang; 19 20 import junit.framework.TestCase; 21 22 public class OldAndroidStrictMathTest extends TestCase { 23 24 private final double HYP = StrictMath.sqrt(2.0); 25 26 private final double OPP = 1.0; 27 28 private final double ADJ = 1.0; 29 30 /* Required to make previous preprocessor flags work - do not remove */ 31 int unused = 0; 32 testAbsD()33 public void testAbsD() { 34 // Test for method double java.lang.StrictMath.abs(double) 35 36 assertTrue("Incorrect double abs value", 37 (StrictMath.abs(-1908.8976) == 1908.8976)); 38 assertTrue("Incorrect double abs value", 39 (StrictMath.abs(1908.8976) == 1908.8976)); 40 } 41 testAbsF()42 public void testAbsF() { 43 // Test for method float java.lang.StrictMath.abs(float) 44 assertTrue("Incorrect float abs value", 45 (StrictMath.abs(-1908.8976f) == 1908.8976f)); 46 assertTrue("Incorrect float abs value", 47 (StrictMath.abs(1908.8976f) == 1908.8976f)); 48 } 49 testAbsI()50 public void testAbsI() { 51 // Test for method int java.lang.StrictMath.abs(int) 52 assertTrue("Incorrect int abs value", 53 (StrictMath.abs(-1908897) == 1908897)); 54 assertTrue("Incorrect int abs value", 55 (StrictMath.abs(1908897) == 1908897)); 56 } 57 testAbsJ()58 public void testAbsJ() { 59 // Test for method long java.lang.StrictMath.abs(long) 60 assertTrue("Incorrect long abs value", (StrictMath 61 .abs(-19088976000089L) == 19088976000089L)); 62 assertTrue("Incorrect long abs value", 63 (StrictMath.abs(19088976000089L) == 19088976000089L)); 64 } 65 testAcosD()66 public void testAcosD() { 67 // Test for method double java.lang.StrictMath.acos(double) 68 assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath 69 .acos(ADJ / HYP)) == ADJ / HYP); 70 } 71 testAsinD()72 public void testAsinD() { 73 // Test for method double java.lang.StrictMath.asin(double) 74 assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath 75 .asin(OPP / HYP)) == OPP / HYP); 76 } 77 testAtanD()78 public void testAtanD() { 79 // Test for method double java.lang.StrictMath.atan(double) 80 double answer = StrictMath.tan(StrictMath.atan(1.0)); 81 assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 82 && answer >= 9.9999999999999983E-1); 83 } 84 testAtan2DD()85 public void testAtan2DD() { 86 // Test for method double java.lang.StrictMath.atan2(double, double) 87 double answer = StrictMath.atan(StrictMath.tan(1.0)); 88 assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 89 && answer >= 9.9999999999999983E-1); 90 } 91 92 @SuppressWarnings("boxing") testCbrtD()93 public void testCbrtD() { 94 // Test for special situations 95 assertTrue("Should return Double.NaN", Double.isNaN(StrictMath 96 .cbrt(Double.NaN))); 97 assertEquals("Should return Double.POSITIVE_INFINITY", 98 Double.POSITIVE_INFINITY, StrictMath 99 .cbrt(Double.POSITIVE_INFINITY)); 100 assertEquals("Should return Double.NEGATIVE_INFINITY", 101 Double.NEGATIVE_INFINITY, StrictMath 102 .cbrt(Double.NEGATIVE_INFINITY)); 103 assertEquals(Double.doubleToLongBits(0.0), Double 104 .doubleToLongBits(StrictMath.cbrt(0.0))); 105 assertEquals(Double.doubleToLongBits(+0.0), Double 106 .doubleToLongBits(StrictMath.cbrt(+0.0))); 107 assertEquals(Double.doubleToLongBits(-0.0), Double 108 .doubleToLongBits(StrictMath.cbrt(-0.0))); 109 110 assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0)); 111 assertEquals("Should return 23.111993172558684", 23.111993172558684, 112 StrictMath.cbrt(12345.6)); 113 assertEquals("Should return 5.643803094122362E102", 114 5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE)); 115 assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001)); 116 117 assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0)); 118 assertEquals("Should return -23.111993172558684", -23.111993172558684, 119 StrictMath.cbrt(-12345.6)); 120 assertEquals("Should return 1.7031839360032603E-108", 121 1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE)); 122 assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001)); 123 124 try { 125 StrictMath.cbrt((Double) null); 126 fail("Should throw NullPointerException"); 127 } catch (NullPointerException e) { 128 //expected 129 } 130 } 131 testCeilD()132 public void testCeilD() { 133 // Test for method double java.lang.StrictMath.ceil(double) 134 assertEquals("Incorrect ceiling for double", 135 79, StrictMath.ceil(78.89), 0.0); 136 assertEquals("Incorrect ceiling for double", 137 -78, StrictMath.ceil(-78.89), 0.0); 138 } 139 testCosD()140 public void testCosD() { 141 // Test for method double java.lang.StrictMath.cos(double) 142 143 assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath 144 .acos(ADJ / HYP)) == ADJ / HYP); 145 } 146 147 @SuppressWarnings("boxing") testCosh_D()148 public void testCosh_D() { 149 // Test for special situations 150 assertTrue("Should return NaN", Double.isNaN(StrictMath 151 .cosh(Double.NaN))); 152 assertEquals("Should return POSITIVE_INFINITY", 153 Double.POSITIVE_INFINITY, StrictMath 154 .cosh(Double.POSITIVE_INFINITY)); 155 assertEquals("Should return POSITIVE_INFINITY", 156 Double.POSITIVE_INFINITY, StrictMath 157 .cosh(Double.NEGATIVE_INFINITY)); 158 assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0)); 159 assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0)); 160 161 assertEquals("Should return POSITIVE_INFINITY", 162 Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56)); 163 assertEquals("Should return POSITIVE_INFINITY", 164 Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56)); 165 assertEquals("Should return 1.0000000000005", 1.0000000000005, 166 StrictMath.cosh(0.000001)); 167 assertEquals("Should return 1.0000000000005", 1.0000000000005, 168 StrictMath.cosh(-0.000001)); 169 assertEquals("Should return 5.212214351945598", 5.212214351945598, 170 StrictMath.cosh(2.33482)); 171 172 assertEquals("Should return POSITIVE_INFINITY", 173 Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE)); 174 assertEquals("Should return 1.0", 1.0, StrictMath 175 .cosh(Double.MIN_VALUE)); 176 } 177 testExpD()178 public void testExpD() { 179 // Test for method double java.lang.StrictMath.exp(double) 180 assertTrue("Incorrect answer returned for simple power", StrictMath 181 .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E 182 * StrictMath.E * StrictMath.E) < 0.1D); 183 assertTrue("Incorrect answer returned for larger power", StrictMath 184 .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D); 185 } 186 187 @SuppressWarnings("boxing") testExpm1D()188 public void testExpm1D() { 189 //Test for special cases 190 assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN))); 191 assertEquals("Should return POSITIVE_INFINITY", 192 Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY)); 193 assertEquals("Should return -1.0", -1.0, StrictMath 194 .expm1(Double.NEGATIVE_INFINITY)); 195 assertEquals(Double.doubleToLongBits(0.0), Double 196 .doubleToLongBits(StrictMath.expm1(0.0))); 197 assertEquals(Double.doubleToLongBits(+0.0), Double 198 .doubleToLongBits(StrictMath.expm1(+0.0))); 199 assertEquals(Double.doubleToLongBits(-0.0), Double 200 .doubleToLongBits(StrictMath.expm1(-0.0))); 201 202 assertEquals("Should return -9.999950000166666E-6", 203 -9.999950000166666E-6, StrictMath.expm1(-0.00001)); 204 assertEquals("Should return 1.0145103074469635E60", 205 1.0145103074469635E60, StrictMath.expm1(138.16951162)); 206 assertEquals("Should return POSITIVE_INFINITY", 207 Double.POSITIVE_INFINITY, StrictMath 208 .expm1(123456789123456789123456789.4521584223)); 209 assertEquals("Should return POSITIVE_INFINITY", 210 Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE)); 211 assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath 212 .expm1(Double.MIN_VALUE)); 213 214 } 215 testFloorD()216 public void testFloorD() { 217 // Test for method double java.lang.StrictMath.floor(double) 218 assertEquals("Incorrect floor for double", 219 78, StrictMath.floor(78.89), 0.0); 220 assertEquals("Incorrect floor for double", 221 -79, StrictMath.floor(-78.89), 0.0); 222 } 223 224 @SuppressWarnings("boxing") testHypotDD()225 public void testHypotDD() { 226 // Test for special cases 227 assertEquals("Should return POSITIVE_INFINITY", 228 Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY, 229 1.0)); 230 assertEquals("Should return POSITIVE_INFINITY", 231 Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY, 232 123.324)); 233 assertEquals("Should return POSITIVE_INFINITY", 234 Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587, 235 Double.POSITIVE_INFINITY)); 236 assertEquals("Should return POSITIVE_INFINITY", 237 Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21, 238 Double.NEGATIVE_INFINITY)); 239 assertEquals("Should return POSITIVE_INFINITY", 240 Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY, 241 Double.NEGATIVE_INFINITY)); 242 assertEquals("Should return POSITIVE_INFINITY", 243 Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY, 244 Double.POSITIVE_INFINITY)); 245 assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(Double.NaN, 246 2342301.89843))); 247 assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(-345.2680, 248 Double.NaN))); 249 250 assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath 251 .hypot(12322.12, -2396393.2258)); 252 assertEquals("Should return 138.16958070558556", 138.16958070558556, 253 StrictMath.hypot(-138.16951162, 0.13817035864)); 254 assertEquals("Should return 1.7976931348623157E308", 255 1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35)); 256 assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot( 257 -5413.7185, Double.MIN_VALUE)); 258 259 } 260 testIEEEremainderDD()261 public void testIEEEremainderDD() { 262 // Test for method double java.lang.StrictMath.IEEEremainder(double, 263 // double) 264 assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder( 265 1.0, 1.0), 0.0); 266 assertTrue( 267 "Incorrect remainder returned", 268 StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2 269 || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2); 270 } 271 testLogD()272 public void testLogD() { 273 // Test for method double java.lang.StrictMath.log(double) 274 for (double d = 10; d >= -10; d -= 0.5) { 275 double answer = StrictMath.log(StrictMath.exp(d)); 276 assertTrue("Answer does not equal expected answer for d = " + d 277 + " answer = " + answer, 278 StrictMath.abs(answer - d) <= StrictMath 279 .abs(d * 0.00000001)); 280 } 281 } 282 283 @SuppressWarnings("boxing") testLog10D()284 public void testLog10D() { 285 // Test for special cases 286 assertTrue("Should return NaN", Double.isNaN(StrictMath 287 .log10(Double.NaN))); 288 assertTrue("Should return NaN", Double.isNaN(StrictMath 289 .log10(-2541.05745687234187532))); 290 assertEquals("Should return POSITIVE_INFINITY", 291 Double.POSITIVE_INFINITY, StrictMath 292 .log10(Double.POSITIVE_INFINITY)); 293 assertEquals("Should return NEGATIVE_INFINITY", 294 Double.NEGATIVE_INFINITY, StrictMath.log10(0.0)); 295 assertEquals("Should return NEGATIVE_INFINITY", 296 Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0)); 297 assertEquals("Should return NEGATIVE_INFINITY", 298 Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0)); 299 assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath 300 .pow(10, 14))); 301 302 assertEquals("Should return 3.7389561269540406", 3.7389561269540406, 303 StrictMath.log10(5482.2158)); 304 assertEquals("Should return 14.661551142893833", 14.661551142893833, 305 StrictMath.log10(458723662312872.125782332587)); 306 assertEquals("Should return -0.9083828622192334", -0.9083828622192334, 307 StrictMath.log10(0.12348583358871)); 308 assertEquals("Should return 308.25471555991675", 308.25471555991675, 309 StrictMath.log10(Double.MAX_VALUE)); 310 assertEquals("Should return -323.3062153431158", -323.3062153431158, 311 StrictMath.log10(Double.MIN_VALUE)); 312 } 313 314 @SuppressWarnings("boxing") testLog1pD()315 public void testLog1pD() { 316 // Test for special cases 317 assertTrue("Should return NaN", Double.isNaN(StrictMath 318 .log1p(Double.NaN))); 319 assertTrue("Should return NaN", Double.isNaN(StrictMath 320 .log1p(-32.0482175))); 321 assertEquals("Should return POSITIVE_INFINITY", 322 Double.POSITIVE_INFINITY, StrictMath 323 .log1p(Double.POSITIVE_INFINITY)); 324 assertEquals(Double.doubleToLongBits(0.0), Double 325 .doubleToLongBits(StrictMath.log1p(0.0))); 326 assertEquals(Double.doubleToLongBits(+0.0), Double 327 .doubleToLongBits(StrictMath.log1p(+0.0))); 328 assertEquals(Double.doubleToLongBits(-0.0), Double 329 .doubleToLongBits(StrictMath.log1p(-0.0))); 330 331 assertEquals("Should return -0.2941782295312541", -0.2941782295312541, 332 StrictMath.log1p(-0.254856327)); 333 assertEquals("Should return 7.368050685564151", 7.368050685564151, 334 StrictMath.log1p(1583.542)); 335 assertEquals("Should return 0.4633708685409921", 0.4633708685409921, 336 StrictMath.log1p(0.5894227)); 337 assertEquals("Should return 709.782712893384", 709.782712893384, 338 StrictMath.log1p(Double.MAX_VALUE)); 339 assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, 340 StrictMath.log1p(Double.MIN_VALUE)); 341 } 342 testMaxDD()343 public void testMaxDD() { 344 // Test for method double java.lang.StrictMath.max(double, double) 345 assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max( 346 -1908897.6000089, 1908897.6000089), 0D); 347 assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0, 348 1908897.6000089), 0D); 349 assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0, 350 -1908897.6000089), 0D); 351 352 } 353 testMaxFF()354 public void testMaxFF() { 355 // Test for method float java.lang.StrictMath.max(float, float) 356 assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f, 357 1908897.600f) == 1908897.600f); 358 assertTrue("Incorrect float max value", StrictMath.max(2.0f, 359 1908897.600f) == 1908897.600f); 360 assertTrue("Incorrect float max value", StrictMath.max(-2.0f, 361 -1908897.600f) == -2.0f); 362 } 363 testMaxII()364 public void testMaxII() { 365 // Test for method int java.lang.StrictMath.max(int, int) 366 assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976, 367 19088976)); 368 assertEquals("Incorrect int max value", 369 19088976, StrictMath.max(20, 19088976)); 370 assertEquals("Incorrect int max value", 371 -20, StrictMath.max(-20, -19088976)); 372 } 373 testMaxJJ()374 public void testMaxJJ() { 375 // Test for method long java.lang.StrictMath.max(long, long) 376 assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L, 377 19088976000089L)); 378 assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20, 379 19088976000089L)); 380 assertEquals("Incorrect long max value", -20, StrictMath.max(-20, 381 -19088976000089L)); 382 } 383 testMinDD()384 public void testMinDD() { 385 // Test for method double java.lang.StrictMath.min(double, double) 386 assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min( 387 -1908897.6000089, 1908897.6000089), 0D); 388 assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0, 389 1908897.6000089), 0D); 390 assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0, 391 -1908897.6000089), 0D); 392 } 393 testMinFF()394 public void testMinFF() { 395 // Test for method float java.lang.StrictMath.min(float, float) 396 assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f, 397 1908897.600f) == -1908897.600f); 398 assertTrue("Incorrect float min value", StrictMath.min(2.0f, 399 1908897.600f) == 2.0f); 400 assertTrue("Incorrect float min value", StrictMath.min(-2.0f, 401 -1908897.600f) == -1908897.600f); 402 } 403 testMinII()404 public void testMinII() { 405 // Test for method int java.lang.StrictMath.min(int, int) 406 assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976, 407 19088976)); 408 assertEquals("Incorrect int min value", 409 20, StrictMath.min(20, 19088976)); 410 assertEquals("Incorrect int min value", 411 -19088976, StrictMath.min(-20, -19088976)); 412 413 } 414 testMinJJ()415 public void testMinJJ() { 416 // Test for method long java.lang.StrictMath.min(long, long) 417 assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L, 418 19088976000089L)); 419 assertEquals("Incorrect long min value", 20, StrictMath.min(20, 420 19088976000089L)); 421 assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20, 422 -19088976000089L)); 423 } 424 testPowDD()425 public void testPowDD() { 426 // Test for method double java.lang.StrictMath.pow(double, double) 427 assertTrue("pow returned incorrect value", 428 (long) StrictMath.pow(2, 8) == 256l); 429 assertTrue("pow returned incorrect value", 430 StrictMath.pow(2, -8) == 0.00390625d); 431 } 432 testRintD()433 public void testRintD() { 434 // Test for method double java.lang.StrictMath.rint(double) 435 assertEquals("Failed to round properly - up to odd", 436 3.0, StrictMath.rint(2.9), 0D); 437 assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath 438 .rint(Double.NaN))); 439 assertEquals("Failed to round properly down to even", 2.0, StrictMath 440 .rint(2.1), 0D); 441 assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath 442 .rint(2.5) == 2.0); 443 } 444 testRoundD()445 public void testRoundD() { 446 // Test for method long java.lang.StrictMath.round(double) 447 assertEquals("Incorrect rounding of a float", 448 -91, StrictMath.round(-90.89d)); 449 } 450 testRoundF()451 public void testRoundF() { 452 // Test for method int java.lang.StrictMath.round(float) 453 assertEquals("Incorrect rounding of a float", 454 -91, StrictMath.round(-90.89f)); 455 } 456 testSignumD()457 public void testSignumD() { 458 assertTrue(Double.isNaN(StrictMath.signum(Double.NaN))); 459 assertEquals(Double.doubleToLongBits(0.0), Double 460 .doubleToLongBits(StrictMath.signum(0.0))); 461 assertEquals(Double.doubleToLongBits(+0.0), Double 462 .doubleToLongBits(StrictMath.signum(+0.0))); 463 assertEquals(Double.doubleToLongBits(-0.0), Double 464 .doubleToLongBits(StrictMath.signum(-0.0))); 465 466 assertEquals(1.0, StrictMath.signum(253681.2187962), 0D); 467 assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D); 468 assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D); 469 assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D); 470 471 assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D); 472 assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D); 473 assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D); 474 assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D); 475 assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D); 476 assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D); 477 478 } 479 testSignumF()480 public void testSignumF() { 481 assertTrue(Float.isNaN(StrictMath.signum(Float.NaN))); 482 assertEquals(Float.floatToIntBits(0.0f), Float 483 .floatToIntBits(StrictMath.signum(0.0f))); 484 assertEquals(Float.floatToIntBits(+0.0f), Float 485 .floatToIntBits(StrictMath.signum(+0.0f))); 486 assertEquals(Float.floatToIntBits(-0.0f), Float 487 .floatToIntBits(StrictMath.signum(-0.0f))); 488 489 assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f); 490 assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f); 491 assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f); 492 assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f); 493 494 assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f); 495 assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f); 496 assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f); 497 assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f); 498 assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f); 499 assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f); 500 } 501 testSinD()502 public void testSinD() { 503 // Test for method double java.lang.StrictMath.sin(double) 504 assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath 505 .asin(OPP / HYP)) == OPP / HYP); 506 } 507 testSinhD()508 public void testSinhD() { 509 // Test for special situations 510 assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN))); 511 assertEquals("Should return POSITIVE_INFINITY", 512 Double.POSITIVE_INFINITY, StrictMath 513 .sinh(Double.POSITIVE_INFINITY), 0D); 514 assertEquals("Should return NEGATIVE_INFINITY", 515 Double.NEGATIVE_INFINITY, StrictMath 516 .sinh(Double.NEGATIVE_INFINITY), 0D); 517 assertEquals(Double.doubleToLongBits(0.0), Double 518 .doubleToLongBits(StrictMath.sinh(0.0))); 519 assertEquals(Double.doubleToLongBits(+0.0), Double 520 .doubleToLongBits(StrictMath.sinh(+0.0))); 521 assertEquals(Double.doubleToLongBits(-0.0), Double 522 .doubleToLongBits(StrictMath.sinh(-0.0))); 523 524 assertEquals("Should return POSITIVE_INFINITY", 525 Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D); 526 assertEquals("Should return NEGATIVE_INFINITY", 527 Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D); 528 assertEquals("Should return 1.0000000000001666E-6", 529 1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D); 530 assertEquals("Should return -1.0000000000001666E-6", 531 -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D); 532 assertEquals("Should return 5.115386441963859", 5.115386441963859, 533 StrictMath.sinh(2.33482), 0D); 534 assertEquals("Should return POSITIVE_INFINITY", 535 Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D); 536 assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath 537 .sinh(Double.MIN_VALUE), 0D); 538 } 539 testSqrtD()540 public void testSqrtD() { 541 // Test for method double java.lang.StrictMath.sqrt(double) 542 assertEquals("Incorrect root returned1", 543 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0); 544 assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0); 545 } 546 testTanD()547 public void testTanD() { 548 // Test for method double java.lang.StrictMath.tan(double) 549 assertTrue( 550 "Returned incorrect tangent: ", 551 StrictMath.tan(StrictMath.atan(1.0)) <= 1.0 552 || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1); 553 } 554 testTanhD()555 public void testTanhD() { 556 // Test for special situations 557 assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN))); 558 assertEquals("Should return +1.0", +1.0, StrictMath 559 .tanh(Double.POSITIVE_INFINITY), 0D); 560 assertEquals("Should return -1.0", -1.0, StrictMath 561 .tanh(Double.NEGATIVE_INFINITY), 0D); 562 assertEquals(Double.doubleToLongBits(0.0), Double 563 .doubleToLongBits(StrictMath.tanh(0.0))); 564 assertEquals(Double.doubleToLongBits(+0.0), Double 565 .doubleToLongBits(StrictMath.tanh(+0.0))); 566 assertEquals(Double.doubleToLongBits(-0.0), Double 567 .doubleToLongBits(StrictMath.tanh(-0.0))); 568 569 assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D); 570 assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D); 571 assertEquals("Should return 9.999999999996666E-7", 572 9.999999999996666E-7, StrictMath.tanh(0.000001), 0D); 573 assertEquals("Should return 0.981422884124941", 0.981422884124941, 574 StrictMath.tanh(2.33482), 0D); 575 assertEquals("Should return 1.0", 1.0, StrictMath 576 .tanh(Double.MAX_VALUE), 0D); 577 assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath 578 .tanh(Double.MIN_VALUE), 0D); 579 } 580 testRandom()581 public void testRandom() { 582 // There isn't a place for these tests so just stick them here 583 assertEquals("Wrong value E", 584 4613303445314885481L, Double.doubleToLongBits(StrictMath.E)); 585 assertEquals("Wrong value PI", 586 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI)); 587 588 for (int i = 500; i >= 0; i--) { 589 double d = StrictMath.random(); 590 assertTrue("Generated number is out of range: " + d, d >= 0.0 591 && d < 1.0); 592 } 593 } 594 testToRadiansD()595 public void testToRadiansD() { 596 for (double d = 500; d >= 0; d -= 1.0) { 597 double converted = StrictMath.toDegrees(StrictMath.toRadians(d)); 598 assertTrue("Converted number not equal to original. d = " + d, 599 converted >= d * 0.99999999 && converted <= d * 1.00000001); 600 } 601 } 602 testToDegreesD()603 public void testToDegreesD() { 604 for (double d = 500; d >= 0; d -= 1.0) { 605 double converted = StrictMath.toRadians(StrictMath.toDegrees(d)); 606 assertTrue("Converted number not equal to original. d = " + d, 607 converted >= d * 0.99999999 && converted <= d * 1.00000001); 608 } 609 } 610 611 @SuppressWarnings("boxing") testUlp_D()612 public void testUlp_D() { 613 // Test for special cases 614 assertTrue("Should return NaN", Double 615 .isNaN(StrictMath.ulp(Double.NaN))); 616 assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, 617 StrictMath.ulp(Double.POSITIVE_INFINITY), 0D); 618 assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, 619 StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D); 620 assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 621 .ulp(0.0), 0D); 622 assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 623 .ulp(+0.0), 0D); 624 assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 625 .ulp(-0.0), 0D); 626 assertEquals("Returned incorrect value", StrictMath.pow(2, 971), 627 StrictMath.ulp(Double.MAX_VALUE), 0D); 628 assertEquals("Returned incorrect value", StrictMath.pow(2, 971), 629 StrictMath.ulp(-Double.MAX_VALUE), 0D); 630 631 assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 632 .ulp(Double.MIN_VALUE), 0D); 633 assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath 634 .ulp(-Double.MIN_VALUE), 0D); 635 636 assertEquals("Returned incorrect value", 2.220446049250313E-16, 637 StrictMath.ulp(1.0), 0D); 638 assertEquals("Returned incorrect value", 2.220446049250313E-16, 639 StrictMath.ulp(-1.0), 0D); 640 assertEquals("Returned incorrect value", 2.2737367544323206E-13, 641 StrictMath.ulp(1153.0), 0D); 642 } 643 644 @SuppressWarnings("boxing") testUlpF()645 public void testUlpF() { 646 // Test for special cases 647 assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN))); 648 assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, 649 StrictMath.ulp(Float.POSITIVE_INFINITY), 0f); 650 assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, 651 StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f); 652 assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 653 .ulp(0.0f), 0f); 654 assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 655 .ulp(+0.0f), 0f); 656 assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath 657 .ulp(-0.0f), 0f); 658 assertEquals("Returned incorrect value", 2.028241E31f, StrictMath 659 .ulp(Float.MAX_VALUE), 0f); 660 assertEquals("Returned incorrect value", 2.028241E31f, StrictMath 661 .ulp(-Float.MAX_VALUE), 0f); 662 663 assertEquals("Returned incorrect value", 1.4E-45f, StrictMath 664 .ulp(Float.MIN_VALUE), 0f); 665 assertEquals("Returned incorrect value", 1.4E-45f, StrictMath 666 .ulp(-Float.MIN_VALUE), 0f); 667 668 assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath 669 .ulp(1.0f), 0f); 670 assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath 671 .ulp(-1.0f), 0f); 672 assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath 673 .ulp(1153.0f), 0f); 674 assertEquals("Returned incorrect value", 5.6E-45f, Math 675 .ulp(9.403954E-38f), 0f); 676 } 677 } 678