MathTest.java revision f6c387128427e121477c1b32ad35cdcaa5101ba3
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 18package org.apache.harmony.luni.tests.java.lang; 19 20import dalvik.annotation.KnownFailure; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetNew; 24import dalvik.annotation.TestTargetClass; 25 26@TestTargetClass(Math.class) 27public class MathTest extends junit.framework.TestCase { 28 29 double HYP = Math.sqrt(2.0); 30 31 double OPP = 1.0; 32 33 double ADJ = 1.0; 34 35 /* Required to make previous preprocessor flags work - do not remove */ 36 int unused = 0; 37 38 public static void assertEquals(String message, double expected, double actual, double delta) { 39 if (delta == 0D) 40 junit.framework.Assert.assertEquals(message, expected, actual, Math.ulp(expected)); 41 else 42 junit.framework.Assert.assertEquals(message, expected, actual, delta); 43 } 44 45 public static void assertEquals(String message, float expected, float actual, float delta) { 46 if (delta == 0F) 47 junit.framework.Assert.assertEquals(message, expected, actual, Math.ulp(expected)); 48 else 49 junit.framework.Assert.assertEquals(message, expected, actual, delta); 50 } 51 52 /** 53 * @tests java.lang.Math#abs(double) 54 */ 55 @TestTargetNew( 56 level = TestLevel.COMPLETE, 57 notes = "", 58 method = "abs", 59 args = {double.class} 60 ) 61 public void test_absD() { 62 // Test for method double java.lang.Math.abs(double) 63 assertTrue("Incorrect double abs value", 64 (Math.abs(-1908.8976) == 1908.8976)); 65 assertTrue("Incorrect double abs value", 66 (Math.abs(1908.8976) == 1908.8976)); 67 assertEquals(0.0, Math.abs(0.0)); 68 assertEquals(0.0, Math.abs(-0.0)); 69 assertEquals(Double.POSITIVE_INFINITY, 70 Math.abs(Double.POSITIVE_INFINITY)); 71 assertEquals(Double.POSITIVE_INFINITY, 72 Math.abs(Double.NEGATIVE_INFINITY)); 73 74 assertEquals(Double.NaN, Math.abs(Double.NaN)); 75 } 76 77 /** 78 * @tests java.lang.Math#abs(float) 79 */ 80 @TestTargetNew( 81 level = TestLevel.COMPLETE, 82 notes = "", 83 method = "abs", 84 args = {float.class} 85 ) 86 public void test_absF() { 87 // Test for method float java.lang.Math.abs(float) 88 assertTrue("Incorrect float abs value", 89 (Math.abs(-1908.8976f) == 1908.8976f)); 90 assertTrue("Incorrect float abs value", 91 (Math.abs(1908.8976f) == 1908.8976f)); 92 93 assertEquals(0.0f, Math.abs(0.0f)); 94 assertEquals(0.0f, Math.abs(-0.0f)); 95 assertEquals(Float.POSITIVE_INFINITY, 96 Math.abs(Float.POSITIVE_INFINITY)); 97 assertEquals(Float.POSITIVE_INFINITY, 98 Math.abs(Float.NEGATIVE_INFINITY)); 99 100 assertEquals(Float.NaN, Math.abs(Float.NaN)); 101 } 102 103 /** 104 * @tests java.lang.Math#abs(int) 105 */ 106 @TestTargetNew( 107 level = TestLevel.COMPLETE, 108 notes = "", 109 method = "abs", 110 args = {int.class} 111 ) 112 public void test_absI() { 113 // Test for method int java.lang.Math.abs(int) 114 assertTrue("Incorrect int abs value", (Math.abs(-1908897) == 1908897)); 115 assertTrue("Incorrect int abs value", (Math.abs(1908897) == 1908897)); 116 117 assertEquals(Integer.MIN_VALUE, Math.abs(Integer.MIN_VALUE)); 118 } 119 120 /** 121 * @tests java.lang.Math#abs(long) 122 */ 123 @TestTargetNew( 124 level = TestLevel.COMPLETE, 125 notes = "", 126 method = "abs", 127 args = {long.class} 128 ) 129 public void test_absJ() { 130 // Test for method long java.lang.Math.abs(long) 131 assertTrue("Incorrect long abs value", 132 (Math.abs(-19088976000089L) == 19088976000089L)); 133 assertTrue("Incorrect long abs value", 134 (Math.abs(19088976000089L) == 19088976000089L)); 135 136 assertEquals(Long.MIN_VALUE, Math.abs(Long.MIN_VALUE)); 137 } 138 139 /** 140 * @tests java.lang.Math#acos(double) 141 */ 142 @TestTargetNew( 143 level = TestLevel.COMPLETE, 144 notes = "", 145 method = "acos", 146 args = {double.class} 147 ) 148 public void test_acosD() { 149 // Test for method double java.lang.Math.acos(double) 150 double r = Math.cos(Math.acos(ADJ / HYP)); 151 long lr = Double.doubleToLongBits(r); 152 long t = Double.doubleToLongBits(ADJ / HYP); 153 assertTrue("Returned incorrect arc cosine", lr == t || (lr + 1) == t 154 || (lr - 1) == t); 155 156 assertEquals(Double.NaN, Math.acos(Double.MAX_VALUE)); 157 assertEquals(Double.NaN, Math.acos(Double.NaN)); 158 } 159 160 /** 161 * @tests java.lang.Math#asin(double) 162 */ 163 @TestTargetNew( 164 level = TestLevel.COMPLETE, 165 notes = "", 166 method = "asin", 167 args = {double.class} 168 ) 169 public void test_asinD() { 170 // Test for method double java.lang.Math.asin(double) 171 double r = Math.sin(Math.asin(OPP / HYP)); 172 long lr = Double.doubleToLongBits(r); 173 long t = Double.doubleToLongBits(OPP / HYP); 174 assertTrue("Returned incorrect arc sine", lr == t || (lr + 1) == t 175 || (lr - 1) == t); 176 177 assertEquals(Double.NaN, Math.asin(Double.MAX_VALUE)); 178 assertEquals(Double.NaN, Math.asin(Double.NaN)); 179 assertEquals(0, Math.asin(0), 0); 180 assertEquals(-0, Math.asin(-0), 0); 181 } 182 183 /** 184 * @tests java.lang.Math#atan(double) 185 */ 186 @TestTargetNew( 187 level = TestLevel.COMPLETE, 188 notes = "", 189 method = "atan", 190 args = {double.class} 191 ) 192 public void test_atanD() { 193 // Test for method double java.lang.Math.atan(double) 194 double answer = Math.tan(Math.atan(1.0)); 195 assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 196 && answer >= 9.9999999999999983E-1); 197 198 assertEquals(Double.NaN, Math.atan(Double.NaN)); 199 assertEquals(0.0, Math.atan(0.0), 0.0); 200 assertEquals(-0.0, Math.atan(-0.0), 0.0); 201 } 202 203 /** 204 * @tests java.lang.Math#atan2(double, double) 205 */ 206 @TestTargetNew( 207 level = TestLevel.COMPLETE, 208 notes = "", 209 method = "atan2", 210 args = {double.class, double.class} 211 ) 212 public void test_atan2DD() { 213 double pi = 3.141592653589793; 214 // Test for method double java.lang.Math.atan2(double, double) 215 double answer = Math.atan(Math.tan(1.0)); 216 assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 217 && answer >= 9.9999999999999983E-1); 218 219 assertEquals(Double.NaN, Math.atan2(Double.NaN, 1.0)); 220 assertEquals(Double.NaN, Math.atan2(1.0, Double.NaN)); 221 222 assertEquals(0.0, Math.atan2(0, 1)); 223 assertEquals(0.0, Math.atan2(1, Double.POSITIVE_INFINITY)); 224 225 assertEquals(-0.0, Math.atan2(-0.0, 1.0)); 226 assertEquals(-0.0, Math.atan2(-1.0, Double.POSITIVE_INFINITY)); 227 228 assertEquals(pi, Math.atan2(0.0, -1.0)); 229 assertEquals(pi, Math.atan2(1.0, Double.NEGATIVE_INFINITY)); 230 231 assertEquals(-pi, Math.atan2(-0.0, -1.0)); 232 assertEquals(-pi, Math.atan2(-1.0, Double.NEGATIVE_INFINITY)); 233 234 assertEquals(pi/2, Math.atan2(1.0, 0.0)); 235 assertEquals(pi/2, Math.atan2(1.0, -0.0)); 236 237 assertEquals(pi/2, Math.atan2(Double.POSITIVE_INFINITY, 1)); 238 assertEquals(pi/2, Math.atan2(Double.POSITIVE_INFINITY, -1)); 239 240 assertEquals(-pi/2, Math.atan2(-1, 0)); 241 assertEquals(-pi/2, Math.atan2(-1, -0)); 242 assertEquals(-pi/2, Math.atan2(Double.NEGATIVE_INFINITY, 1)); 243 244 assertEquals(pi/4, Math.atan2(Double.POSITIVE_INFINITY, 245 Double.POSITIVE_INFINITY)); 246 assertEquals(3*pi/4, Math.atan2(Double.POSITIVE_INFINITY, 247 Double.NEGATIVE_INFINITY)); 248 assertEquals(-pi/4, Math.atan2(Double.NEGATIVE_INFINITY, 249 Double.POSITIVE_INFINITY)); 250 assertEquals(-3*pi/4, Math.atan2(Double.NEGATIVE_INFINITY, 251 Double.NEGATIVE_INFINITY)); 252 } 253 254 /** 255 * @tests java.lang.Math#cbrt(double) 256 */ 257 @TestTargetNew( 258 level = TestLevel.COMPLETE, 259 notes = "", 260 method = "cbrt", 261 args = {double.class} 262 ) 263 public void test_cbrt_D() { 264 //Test for special situations 265 assertTrue("Should return Double.NaN", Double.isNaN(Math 266 .cbrt(Double.NaN))); 267 assertEquals("Should return Double.POSITIVE_INFINITY", 268 Double.POSITIVE_INFINITY, Math 269 .cbrt(Double.POSITIVE_INFINITY), 0D); 270 assertEquals("Should return Double.NEGATIVE_INFINITY", 271 Double.NEGATIVE_INFINITY, Math 272 .cbrt(Double.NEGATIVE_INFINITY), 0D); 273 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 274 .cbrt(0.0))); 275 assertEquals(Double.doubleToLongBits(+0.0), Double.doubleToLongBits(Math 276 .cbrt(+0.0))); 277 assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(Math 278 .cbrt(-0.0))); 279 280 assertEquals("Should return 3.0", 3.0, Math.cbrt(27.0), 0D); 281 assertEquals("Should return 23.111993172558684", 23.111993172558684, 282 Math.cbrt(12345.6), 0D); 283 assertEquals("Should return 5.643803094122362E102", 284 5.643803094122362E102, Math.cbrt(Double.MAX_VALUE), 0D); 285 assertEquals("Should return 0.01", 0.01, Math.cbrt(0.000001), 0D); 286 287 assertEquals("Should return -3.0", -3.0, Math.cbrt(-27.0), 0D); 288 assertEquals("Should return -23.111993172558684", -23.111993172558684, 289 Math.cbrt(-12345.6), 0D); 290 assertEquals("Should return 1.7031839360032603E-108", 291 1.7031839360032603E-108, Math.cbrt(Double.MIN_VALUE), 0D); 292 assertEquals("Should return -0.01", -0.01, Math.cbrt(-0.000001), 0D); 293 } 294 295 /** 296 * @tests java.lang.Math#ceil(double) 297 */ 298 @TestTargetNew( 299 level = TestLevel.COMPLETE, 300 notes = "", 301 method = "ceil", 302 args = {double.class} 303 ) 304 public void test_ceilD() { 305 // Test for method double java.lang.Math.ceil(double) 306 assertEquals("Incorrect ceiling for double", 307 79, Math.ceil(78.89), 0); 308 assertEquals("Incorrect ceiling for double", 309 -78, Math.ceil(-78.89), 0); 310 311 assertEquals("Incorrect ceiling for double", 312 -78, Math.ceil(-78), 0); 313 314 double [] args = {0.0, -0.0, Double.NaN, Double.POSITIVE_INFINITY, 315 Double.NEGATIVE_INFINITY}; 316 for(int i = 0; i < args.length; i++) { 317 assertEquals(args[i], Math.ceil(args[i])); 318 } 319 assertEquals(-0.0, Math.ceil(-0.5)); 320 } 321 322 /** 323 * @tests java.lang.Math#cos(double) 324 */ 325 @TestTargetNew( 326 level = TestLevel.COMPLETE, 327 notes = "", 328 method = "cos", 329 args = {double.class} 330 ) 331 public void test_cosD() { 332 // Test for method double java.lang.Math.cos(double) 333 assertEquals("Incorrect answer", 1.0, Math.cos(0), 0D); 334 assertEquals("Incorrect answer", 0.5403023058681398, Math.cos(1), 0D); 335 double [] args = {Double.NaN, Double.POSITIVE_INFINITY, 336 Double.NEGATIVE_INFINITY}; 337 for(int i = 0; i < args.length; i++) { 338 assertEquals(args[i], Math.ceil(args[i])); 339 } 340 } 341 342 /** 343 * @tests java.lang.Math#cosh(double) 344 */ 345 @TestTargetNew( 346 level = TestLevel.COMPLETE, 347 notes = "", 348 method = "cosh", 349 args = {double.class} 350 ) 351 public void test_cosh_D() { 352 // Test for special situations 353 assertTrue(Double.isNaN(Math.cosh(Double.NaN))); 354 assertEquals("Should return POSITIVE_INFINITY", 355 Double.POSITIVE_INFINITY, Math.cosh(Double.POSITIVE_INFINITY), 0D); 356 assertEquals("Should return POSITIVE_INFINITY", 357 Double.POSITIVE_INFINITY, Math.cosh(Double.NEGATIVE_INFINITY), 0D); 358 assertEquals("Should return 1.0", 1.0, Math.cosh(+0.0), 0D); 359 assertEquals("Should return 1.0", 1.0, Math.cosh(-0.0), 0D); 360 361 assertEquals("Should return POSITIVE_INFINITY", 362 Double.POSITIVE_INFINITY, Math.cosh(1234.56), 0D); 363 assertEquals("Should return POSITIVE_INFINITY", 364 Double.POSITIVE_INFINITY, Math.cosh(-1234.56), 0D); 365 assertEquals("Should return 1.0000000000005", 1.0000000000005, Math 366 .cosh(0.000001), 0D); 367 assertEquals("Should return 1.0000000000005", 1.0000000000005, Math 368 .cosh(-0.000001), 0D); 369 assertEquals("Should return 5.212214351945598", 5.212214351945598, Math 370 .cosh(2.33482), 0D); 371 372 assertEquals("Should return POSITIVE_INFINITY", 373 Double.POSITIVE_INFINITY, Math.cosh(Double.MAX_VALUE), 0D); 374 assertEquals("Should return 1.0", 1.0, Math.cosh(Double.MIN_VALUE), 0D); 375 } 376 377 /** 378 * @tests java.lang.Math#exp(double) 379 */ 380 @TestTargetNew( 381 level = TestLevel.COMPLETE, 382 notes = "", 383 method = "exp", 384 args = {double.class} 385 ) 386 public void test_expD() { 387 // Test for method double java.lang.Math.exp(double) 388 assertTrue("Incorrect answer returned for simple power", Math.abs(Math 389 .exp(4D) 390 - Math.E * Math.E * Math.E * Math.E) < 0.1D); 391 assertTrue("Incorrect answer returned for larger power", Math.log(Math 392 .abs(Math.exp(5.5D)) - 5.5D) < 10.0D); 393 394 assertEquals("Incorrect returned value for NaN", 395 Double.NaN, Math.exp(Double.NaN)); 396 assertEquals("Incorrect returned value for positive infinity", 397 Double.POSITIVE_INFINITY, Math.exp(Double.POSITIVE_INFINITY)); 398 assertEquals("Incorrect returned value for negative infinity", 399 0, Math.exp(Double.NEGATIVE_INFINITY), 0); 400 } 401 402 /** 403 * @tests java.lang.Math#expm1(double) 404 */ 405 @TestTargetNew( 406 level = TestLevel.COMPLETE, 407 notes = "", 408 method = "expm1", 409 args = {double.class} 410 ) 411 public void test_expm1_D() { 412 // Test for special cases 413 assertTrue("Should return NaN", Double.isNaN(Math.expm1(Double.NaN))); 414 assertEquals("Should return POSITIVE_INFINITY", 415 Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY), 0D); 416 assertEquals("Should return -1.0", -1.0, Math 417 .expm1(Double.NEGATIVE_INFINITY), 0D); 418 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 419 .expm1(0.0))); 420 assertEquals(Double.doubleToLongBits(+0.0), Double 421 .doubleToLongBits(Math.expm1(+0.0))); 422 assertEquals(Double.doubleToLongBits(-0.0), Double 423 .doubleToLongBits(Math.expm1(-0.0))); 424 425 assertEquals("Should return -9.999950000166666E-6", 426 -9.999950000166666E-6, Math.expm1(-0.00001), 0D); 427 assertEquals("Should return 1.0145103074469635E60", 428 1.0145103074469635E60, Math.expm1(138.16951162), 0D); 429 assertEquals("Should return POSITIVE_INFINITY", 430 Double.POSITIVE_INFINITY, Math 431 .expm1(123456789123456789123456789.4521584223), 0D); 432 assertEquals("Should return POSITIVE_INFINITY", 433 Double.POSITIVE_INFINITY, Math.expm1(Double.MAX_VALUE), 0D); 434 assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, Math 435 .expm1(Double.MIN_VALUE), 0D); 436 } 437 438 /** 439 * @tests java.lang.Math#floor(double) 440 */ 441 @TestTargetNew( 442 level = TestLevel.COMPLETE, 443 notes = "", 444 method = "floor", 445 args = {double.class} 446 ) 447 public void test_floorD() { 448 // Test for method double java.lang.Math.floor(double) 449 assertEquals("Incorrect floor for double", 450 78, Math.floor(78.89), 0); 451 assertEquals("Incorrect floor for double", 452 -79, Math.floor(-78.89), 0); 453 assertEquals("Incorrect floor for integer", 454 -78, Math.floor(-78), 0); 455 double [] args = {0, -0, Double.NaN, Double.POSITIVE_INFINITY, 456 Double.NEGATIVE_INFINITY}; 457 for(int i = 0; i < args.length; i++) { 458 assertEquals(args[i], Math.floor(args[i])); 459 } 460 } 461 462 /** 463 * @tests java.lang.Math#hypot(double, double) 464 */ 465 @TestTargetNew( 466 level = TestLevel.COMPLETE, 467 notes = "", 468 method = "hypot", 469 args = {double.class, double.class} 470 ) 471 public void test_hypot_DD() { 472 // Test for special cases 473 assertEquals("Should return POSITIVE_INFINITY", 474 Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY, 475 1.0), 0D); 476 assertEquals("Should return POSITIVE_INFINITY", 477 Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY, 478 123.324), 0D); 479 assertEquals("Should return POSITIVE_INFINITY", 480 Double.POSITIVE_INFINITY, Math.hypot(-758.2587, 481 Double.POSITIVE_INFINITY), 0D); 482 assertEquals("Should return POSITIVE_INFINITY", 483 Double.POSITIVE_INFINITY, Math.hypot(5687.21, 484 Double.NEGATIVE_INFINITY), 0D); 485 assertEquals("Should return POSITIVE_INFINITY", 486 Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY, 487 Double.NEGATIVE_INFINITY), 0D); 488 assertEquals("Should return POSITIVE_INFINITY", 489 Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY, 490 Double.POSITIVE_INFINITY), 0D); 491 assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN, 492 2342301.89843))); 493 assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680, 494 Double.NaN))); 495 496 assertEquals("Should return 2396424.905416697", 2396424.905416697, Math 497 .hypot(12322.12, -2396393.2258), 0D); 498 assertEquals("Should return 138.16958070558556", 138.16958070558556, 499 Math.hypot(-138.16951162, 0.13817035864), 0D); 500 assertEquals("Should return 1.7976931348623157E308", 501 1.7976931348623157E308, Math.hypot(Double.MAX_VALUE, 211370.35), 0D); 502 assertEquals("Should return 5413.7185", 5413.7185, Math.hypot( 503 -5413.7185, Double.MIN_VALUE), 0D); 504 } 505 506 /** 507 * @tests java.lang.Math#IEEEremainder(double, double) 508 */ 509 @TestTargetNew( 510 level = TestLevel.COMPLETE, 511 notes = "", 512 method = "IEEEremainder", 513 args = {double.class, double.class} 514 ) 515 public void test_IEEEremainderDD() { 516 // Test for method double java.lang.Math.IEEEremainder(double, double) 517 assertEquals("Incorrect remainder returned", 518 0.0, Math.IEEEremainder(1.0, 1.0), 0D); 519 assertTrue("Incorrect remainder returned", Math.IEEEremainder(1.32, 520 89.765) >= 1.4705063220631647E-2 521 || Math.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2); 522 523 assertEquals(Double.NaN, Math.IEEEremainder(Double.NaN, Double.NaN)); 524 assertEquals(Double.NaN, Math.IEEEremainder(Double.NaN, 1.0)); 525 assertEquals(Double.NaN, Math.IEEEremainder(1.0, Double.NaN)); 526 527 assertEquals(Double.NaN, Math.IEEEremainder(Double.POSITIVE_INFINITY, 1.0)); 528 assertEquals(Double.NaN, Math.IEEEremainder(Double.NEGATIVE_INFINITY, 1.0)); 529 assertEquals(1.0, Math.IEEEremainder(1.0, Double.POSITIVE_INFINITY)); 530 assertEquals(1.0, Math.IEEEremainder(1.0, Double.NEGATIVE_INFINITY)); 531 assertEquals(Double.NaN, Math.IEEEremainder(1.0, 0.0)); 532 assertEquals(Double.NaN, Math.IEEEremainder(1.0, -0.0)); 533 } 534 535 /** 536 * @tests java.lang.Math#log(double) 537 */ 538 @TestTargetNew( 539 level = TestLevel.COMPLETE, 540 notes = "", 541 method = "log", 542 args = {double.class} 543 ) 544 public void test_logD() { 545 // Test for method double java.lang.Math.log(double) 546 for (double d = 10; d >= -10; d -= 0.5) { 547 double answer = Math.log(Math.exp(d)); 548 assertTrue("Answer does not equal expected answer for d = " + d 549 + " answer = " + answer, Math.abs(answer - d) <= Math 550 .abs(d * 0.00000001)); 551 } 552 } 553 554 /** 555 * @tests java.lang.Math#log10(double) 556 */ 557 @TestTargetNew( 558 level = TestLevel.COMPLETE, 559 notes = "", 560 method = "log10", 561 args = {double.class} 562 ) 563 @SuppressWarnings("boxing") 564 public void test_log10_D() { 565 // Test for special cases 566 assertTrue(Double.isNaN(Math.log10(Double.NaN))); 567 assertTrue(Double.isNaN(Math.log10(-2541.05745687234187532))); 568 assertTrue(Double.isNaN(Math.log10(-0.1))); 569 assertEquals(Double.POSITIVE_INFINITY, Math.log10(Double.POSITIVE_INFINITY)); 570 assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0)); 571 assertEquals(Double.NEGATIVE_INFINITY, Math.log10(+0.0)); 572 assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0)); 573 574 assertEquals(3.0, Math.log10(1000.0)); 575 assertEquals(14.0, Math.log10(Math.pow(10, 14))); 576 assertEquals(3.7389561269540406, Math.log10(5482.2158)); 577 assertEquals(14.661551142893833, Math.log10(458723662312872.125782332587)); 578 assertEquals(-0.9083828622192334, Math.log10(0.12348583358871)); 579 assertEquals(308.25471555991675, Math.log10(Double.MAX_VALUE)); 580 assertEquals(-323.3062153431158, Math.log10(Double.MIN_VALUE)); 581 } 582 583 /** 584 * @tests java.lang.Math#log1p(double) 585 */ 586 @TestTargetNew( 587 level = TestLevel.COMPLETE, 588 notes = "", 589 method = "log1p", 590 args = {double.class} 591 ) 592 public void test_log1p_D() { 593 // Test for special cases 594 assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN))); 595 assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175))); 596 assertEquals("Should return POSITIVE_INFINITY", 597 Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D); 598 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 599 .log1p(0.0))); 600 assertEquals(Double.doubleToLongBits(+0.0), Double 601 .doubleToLongBits(Math.log1p(+0.0))); 602 assertEquals(Double.doubleToLongBits(-0.0), Double 603 .doubleToLongBits(Math.log1p(-0.0))); 604 605 assertEquals("Should return -0.2941782295312541", -0.2941782295312541, 606 Math.log1p(-0.254856327), 0D); 607 assertEquals("Should return 7.368050685564151", 7.368050685564151, Math 608 .log1p(1583.542), 0D); 609 assertEquals("Should return 0.4633708685409921", 0.4633708685409921, 610 Math.log1p(0.5894227), 0D); 611 assertEquals("Should return 709.782712893384", 709.782712893384, Math 612 .log1p(Double.MAX_VALUE), 0D); 613 assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, Math 614 .log1p(Double.MIN_VALUE), 0D); 615 } 616 617 /** 618 * @tests java.lang.Math#max(double, double) 619 */ 620 @TestTargetNew( 621 level = TestLevel.COMPLETE, 622 notes = "", 623 method = "max", 624 args = {double.class, double.class} 625 ) 626 public void test_maxDD() { 627 // Test for method double java.lang.Math.max(double, double) 628 assertEquals("Incorrect double max value", 1908897.6000089, 629 Math.max(-1908897.6000089, 630 1908897.6000089), 0D); 631 assertEquals("Incorrect double max value", 632 1908897.6000089, Math.max(2.0, 1908897.6000089), 0D); 633 assertEquals("Incorrect double max value", -2.0, Math.max(-2.0, 634 -1908897.6000089), 0D); 635 636 assertEquals("Incorrect returned value", Double.NaN, 637 Math.max(-1.0, Double.NaN)); 638 assertEquals("Incorrect returned value", Double.NaN, 639 Math.max(Double.NaN, -1.0)); 640 assertEquals("Incorrect returned value", 0, Math.max(0, -0), 0D); 641 } 642 643 /** 644 * @tests java.lang.Math#max(float, float) 645 */ 646 @TestTargetNew( 647 level = TestLevel.COMPLETE, 648 notes = "", 649 method = "max", 650 args = {float.class, float.class} 651 ) 652 public void test_maxFF() { 653 // Test for method float java.lang.Math.max(float, float) 654 assertTrue("Incorrect float max value", Math.max(-1908897.600f, 655 1908897.600f) == 1908897.600f); 656 assertTrue("Incorrect float max value", 657 Math.max(2.0f, 1908897.600f) == 1908897.600f); 658 assertTrue("Incorrect float max value", 659 Math.max(-2.0f, -1908897.600f) == -2.0f); 660 assertEquals("Incorrect returned value", Float.NaN, 661 Math.max(-1.0f, Float.NaN)); 662 assertEquals("Incorrect returned value", Float.NaN, 663 Math.max(Float.NaN, -1.0f)); 664 assertEquals("Incorrect returned value", 0f, Math.max(0f, -0f)); 665 } 666 667 /** 668 * @tests java.lang.Math#max(int, int) 669 */ 670 @TestTargetNew( 671 level = TestLevel.COMPLETE, 672 notes = "", 673 method = "max", 674 args = {int.class, int.class} 675 ) 676 public void test_maxII() { 677 // Test for method int java.lang.Math.max(int, int) 678 assertEquals("Incorrect int max value", 679 19088976, Math.max(-19088976, 19088976)); 680 assertEquals("Incorrect int max value", 681 19088976, Math.max(20, 19088976)); 682 assertEquals("Incorrect int max value", -20, Math.max(-20, -19088976)); 683 } 684 685 /** 686 * @tests java.lang.Math#max(long, long) 687 */ 688 @TestTargetNew( 689 level = TestLevel.COMPLETE, 690 notes = "", 691 method = "max", 692 args = {long.class, long.class} 693 ) 694 public void test_maxJJ() { 695 // Test for method long java.lang.Math.max(long, long) 696 assertEquals("Incorrect long max value", 19088976000089L, Math.max(-19088976000089L, 697 19088976000089L)); 698 assertEquals("Incorrect long max value", 699 19088976000089L, Math.max(20, 19088976000089L)); 700 assertEquals("Incorrect long max value", 701 -20, Math.max(-20, -19088976000089L)); 702 } 703 704 /** 705 * @tests java.lang.Math#min(double, double) 706 */ 707 @TestTargetNew( 708 level = TestLevel.COMPLETE, 709 notes = "", 710 method = "min", 711 args = {double.class, double.class} 712 ) 713 public void test_minDD() { 714 // Test for method double java.lang.Math.min(double, double) 715 assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-1908897.6000089, 716 1908897.6000089), 0D); 717 assertEquals("Incorrect double min value", 718 2.0, Math.min(2.0, 1908897.6000089), 0D); 719 assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-2.0, 720 -1908897.6000089), 0D); 721 assertEquals("Incorrect returned value", Double.NaN, 722 Math.min(-1.0, Double.NaN)); 723 assertEquals("Incorrect returned value", Double.NaN, 724 Math.min(Double.NaN, -1.0)); 725 assertEquals("Incorrect returned value", -0.0, Math.min(0.0, -0.0)); 726 } 727 728 /** 729 * @tests java.lang.Math#min(float, float) 730 */ 731 @TestTargetNew( 732 level = TestLevel.COMPLETE, 733 notes = "", 734 method = "min", 735 args = {float.class, float.class} 736 ) 737 public void test_minFF() { 738 // Test for method float java.lang.Math.min(float, float) 739 assertTrue("Incorrect float min value", Math.min(-1908897.600f, 740 1908897.600f) == -1908897.600f); 741 assertTrue("Incorrect float min value", 742 Math.min(2.0f, 1908897.600f) == 2.0f); 743 assertTrue("Incorrect float min value", 744 Math.min(-2.0f, -1908897.600f) == -1908897.600f); 745 assertEquals("Incorrect returned value", Float.NaN, 746 Math.min(-1.0f, Float.NaN)); 747 assertEquals("Incorrect returned value", Float.NaN, 748 Math.min(Float.NaN, -1.0f)); 749 assertEquals("Incorrect returned value", -0f, Math.min(0f, -0f)); 750 } 751 752 /** 753 * @tests java.lang.Math#min(int, int) 754 */ 755 @TestTargetNew( 756 level = TestLevel.COMPLETE, 757 notes = "", 758 method = "min", 759 args = {int.class, int.class} 760 ) 761 public void test_minII() { 762 // Test for method int java.lang.Math.min(int, int) 763 assertEquals("Incorrect int min value", 764 -19088976, Math.min(-19088976, 19088976)); 765 assertEquals("Incorrect int min value", 20, Math.min(20, 19088976)); 766 assertEquals("Incorrect int min value", 767 -19088976, Math.min(-20, -19088976)); 768 769 } 770 771 /** 772 * @tests java.lang.Math#min(long, long) 773 */ 774 @TestTargetNew( 775 level = TestLevel.COMPLETE, 776 notes = "", 777 method = "min", 778 args = {long.class, long.class} 779 ) 780 public void test_minJJ() { 781 // Test for method long java.lang.Math.min(long, long) 782 assertEquals("Incorrect long min value", -19088976000089L, Math.min(-19088976000089L, 783 19088976000089L)); 784 assertEquals("Incorrect long min value", 785 20, Math.min(20, 19088976000089L)); 786 assertEquals("Incorrect long min value", 787 -19088976000089L, Math.min(-20, -19088976000089L)); 788 } 789 790 /** 791 * @tests java.lang.Math#pow(double, double) 792 */ 793 @TestTargetNew( 794 level = TestLevel.COMPLETE, 795 notes = "", 796 method = "pow", 797 args = {double.class, double.class} 798 ) 799 @KnownFailure("Math.pow(double a, double b) returns 1.0 if " + 800 "the absolute value of the first argument equals 1 and " + 801 "the second argument is infinite. It should return NaN.") 802 public void test_powDD() { 803 // Test for method double java.lang.Math.pow(double, double) 804 assertTrue("pow returned incorrect value", 805 (long) Math.pow(2, 8) == 256l); 806 assertTrue("pow returned incorrect value", 807 Math.pow(2, -8) == 0.00390625d); 808 assertEquals("Incorrect root returned1", 809 2, Math.sqrt(Math.pow(Math.sqrt(2), 4)), 0); 810 811 assertEquals("pow returned incorrect value", 1.0, Math.pow(1, 0)); 812 assertEquals("pow returned incorrect value", 2.0, Math.pow(2, 1)); 813 assertEquals("pow returned incorrect value", Double.NaN, 814 Math.pow(Double.MAX_VALUE, Double.NaN)); 815 assertEquals("pow returned incorrect value", Double.NaN, 816 Math.pow(Double.NaN, Double.MAX_VALUE)); 817 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 818 Math.pow(1.1, Double.POSITIVE_INFINITY)); 819 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 820 Math.pow(0.9, Double.NEGATIVE_INFINITY)); 821 822 assertEquals("pow returned incorrect value", 0.0, 823 Math.pow(1.1, Double.NEGATIVE_INFINITY)); 824 assertEquals("pow returned incorrect value", 0.0, 825 Math.pow(0.9, Double.POSITIVE_INFINITY)); 826 827 assertEquals("pow returned incorrect value", Double.NaN, 828 Math.pow(1.0, Double.NEGATIVE_INFINITY)); 829 assertEquals("pow returned incorrect value", Double.NaN, 830 Math.pow(1.0, Double.POSITIVE_INFINITY)); 831 832 assertEquals("pow returned incorrect value", 0.0, Math.pow(0, 1)); 833 assertEquals("pow returned incorrect value", 0.0, 834 Math.pow(Double.POSITIVE_INFINITY, -0.1)); 835 836 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 837 Math.pow(0, -1)); 838 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 839 Math.pow(Double.POSITIVE_INFINITY, 1)); 840 841 assertEquals("pow returned incorrect value", 0.0, 842 Math.pow(-0.0, 0.9)); 843 assertEquals("pow returned incorrect value", 0.0, 844 Math.pow(Double.NEGATIVE_INFINITY, -0.9)); 845 846 assertEquals("pow returned incorrect value", -0.0, 847 Math.pow(-0.0, 1)); 848 assertEquals("pow returned incorrect value", -0.0, 849 Math.pow(Double.NEGATIVE_INFINITY, -1)); 850 851 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 852 Math.pow(-0.0, -0.9)); 853 assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY, 854 Math.pow(Double.NEGATIVE_INFINITY, 0.9)); 855 856 assertEquals("pow returned incorrect value", Double.NEGATIVE_INFINITY, 857 Math.pow(-0.0, -1)); 858 assertEquals("pow returned incorrect value", Double.NEGATIVE_INFINITY, 859 Math.pow(Double.NEGATIVE_INFINITY, 1)); 860 861 assertEquals("pow returned incorrect value", 0.81, Math.pow(-0.9, 2)); 862 assertEquals("pow returned incorrect value", -0.9, Math.pow(-0.9, 1)); 863 assertEquals("pow returned incorrect value", Double.NaN, 864 Math.pow(-0.9, 0.1)); 865 } 866 867 /** 868 * @tests java.lang.Math#rint(double) 869 */ 870 @TestTargetNew( 871 level = TestLevel.COMPLETE, 872 notes = "", 873 method = "rint", 874 args = {double.class} 875 ) 876 public void test_rintD() { 877 // Test for method double java.lang.Math.rint(double) 878 assertEquals("Failed to round properly - up to odd", 879 3.0, Math.rint(2.9), 0D); 880 assertTrue("Failed to round properly - NaN", Double.isNaN(Math 881 .rint(Double.NaN))); 882 assertEquals("Failed to round properly down to even", 883 2.0, Math.rint(2.1), 0D); 884 assertTrue("Failed to round properly " + 2.5 + " to even", Math 885 .rint(2.5) == 2.0); 886 } 887 888 /** 889 * @tests java.lang.Math#round(double) 890 */ 891 @TestTargetNew( 892 level = TestLevel.COMPLETE, 893 notes = "", 894 method = "round", 895 args = {double.class} 896 ) 897 public void test_roundD() { 898 // Test for method long java.lang.Math.round(double) 899 assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89d)); 900 assertEquals("Incorrect rounding of a float", 0, 901 Math.round(Double.NaN)); 902 assertEquals("Incorrect rounding of a float", Long.MIN_VALUE, 903 Math.round(Double.NEGATIVE_INFINITY)); 904 assertEquals("Incorrect rounding of a float", Long.MAX_VALUE, 905 Math.round(Double.POSITIVE_INFINITY)); 906 } 907 908 /** 909 * @tests java.lang.Math#round(float) 910 */ 911 @TestTargetNew( 912 level = TestLevel.COMPLETE, 913 notes = "", 914 method = "round", 915 args = {float.class} 916 ) 917 public void test_roundF() { 918 // Test for method int java.lang.Math.round(float) 919 assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f)); 920 assertEquals("Incorrect rounding of a float", 0, 921 Math.round(Float.NaN)); 922 assertEquals("Incorrect rounding of a float", Integer.MIN_VALUE, 923 Math.round(Float.NEGATIVE_INFINITY)); 924 assertEquals("Incorrect rounding of a float", Integer.MAX_VALUE, 925 Math.round(Float.POSITIVE_INFINITY)); 926 } 927 928 /** 929 * @tests java.lang.Math#signum(double) 930 */ 931 @TestTargetNew( 932 level = TestLevel.COMPLETE, 933 notes = "", 934 method = "signum", 935 args = {double.class} 936 ) 937 public void test_signum_D() { 938 assertTrue(Double.isNaN(Math.signum(Double.NaN))); 939 assertTrue(Double.isNaN(Math.signum(Double.NaN))); 940 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 941 .signum(0.0))); 942 assertEquals(Double.doubleToLongBits(+0.0), Double 943 .doubleToLongBits(Math.signum(+0.0))); 944 assertEquals(Double.doubleToLongBits(-0.0), Double 945 .doubleToLongBits(Math.signum(-0.0))); 946 947 assertEquals(1.0, Math.signum(253681.2187962), 0D); 948 assertEquals(-1.0, Math.signum(-125874693.56), 0D); 949 assertEquals(1.0, Math.signum(1.2587E-308), 0D); 950 assertEquals(-1.0, Math.signum(-1.2587E-308), 0D); 951 952 assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D); 953 assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D); 954 assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D); 955 assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D); 956 assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D); 957 assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D); 958 } 959 960 /** 961 * @tests java.lang.Math#signum(float) 962 */ 963 @TestTargetNew( 964 level = TestLevel.COMPLETE, 965 notes = "", 966 method = "signum", 967 args = {float.class} 968 ) 969 public void test_signum_F() { 970 assertTrue(Float.isNaN(Math.signum(Float.NaN))); 971 assertEquals(Float.floatToIntBits(0.0f), Float 972 .floatToIntBits(Math.signum(0.0f))); 973 assertEquals(Float.floatToIntBits(+0.0f), Float 974 .floatToIntBits(Math.signum(+0.0f))); 975 assertEquals(Float.floatToIntBits(-0.0f), Float 976 .floatToIntBits(Math.signum(-0.0f))); 977 978 assertEquals(1.0f, Math.signum(253681.2187962f), 0f); 979 assertEquals(-1.0f, Math.signum(-125874693.56f), 0f); 980 assertEquals(1.0f, Math.signum(1.2587E-11f), 0f); 981 assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f); 982 983 assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f); 984 assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f); 985 assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f); 986 assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f); 987 assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f); 988 assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f); 989 } 990 991 /** 992 * @tests java.lang.Math#sin(double) 993 */ 994 @TestTargetNew( 995 level = TestLevel.COMPLETE, 996 notes = "", 997 method = "sin", 998 args = {double.class} 999 ) 1000 public void test_sinD() { 1001 // Test for method double java.lang.Math.sin(double) 1002 assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D); 1003 assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D); 1004 1005 double [] args = {Double.NaN, Double.POSITIVE_INFINITY, 1006 Double.NEGATIVE_INFINITY}; 1007 for(int i = 0; i < args.length; i++) { 1008 assertEquals("Incorrest returned value.", Double.NaN, 1009 Math.sin(args[i])); 1010 } 1011 1012 assertEquals("Incorrest returned value.", 0.0, Math.sin(0.0)); 1013 assertEquals("Incorrest returned value.", -0.0, Math.sin(-0.0)); 1014 } 1015 1016 /** 1017 * @tests java.lang.Math#sinh(double) 1018 */ 1019 @TestTargetNew( 1020 level = TestLevel.COMPLETE, 1021 notes = "", 1022 method = "sinh", 1023 args = {double.class} 1024 ) 1025 public void test_sinh_D() { 1026 // Test for special situations 1027 assertTrue("Should return NaN", Double.isNaN(Math.sinh(Double.NaN))); 1028 assertEquals("Should return POSITIVE_INFINITY", 1029 Double.POSITIVE_INFINITY, Math.sinh(Double.POSITIVE_INFINITY), 0D); 1030 assertEquals("Should return NEGATIVE_INFINITY", 1031 Double.NEGATIVE_INFINITY, Math.sinh(Double.NEGATIVE_INFINITY), 0D); 1032 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 1033 .sinh(0.0))); 1034 assertEquals(Double.doubleToLongBits(+0.0), Double 1035 .doubleToLongBits(Math.sinh(+0.0))); 1036 assertEquals(Double.doubleToLongBits(-0.0), Double 1037 .doubleToLongBits(Math.sinh(-0.0))); 1038 1039 assertEquals("Should return POSITIVE_INFINITY", 1040 Double.POSITIVE_INFINITY, Math.sinh(1234.56), 0D); 1041 assertEquals("Should return NEGATIVE_INFINITY", 1042 Double.NEGATIVE_INFINITY, Math.sinh(-1234.56), 0D); 1043 assertEquals("Should return 1.0000000000001666E-6", 1044 1.0000000000001666E-6, Math.sinh(0.000001), 0D); 1045 assertEquals("Should return -1.0000000000001666E-6", 1046 -1.0000000000001666E-6, Math.sinh(-0.000001), 0D); 1047 assertEquals("Should return 5.115386441963859", 5.115386441963859, Math 1048 .sinh(2.33482), 0D); 1049 assertEquals("Should return POSITIVE_INFINITY", 1050 Double.POSITIVE_INFINITY, Math.sinh(Double.MAX_VALUE), 0D); 1051 assertEquals("Should return 4.9E-324", 4.9E-324, Math 1052 .sinh(Double.MIN_VALUE), 0D); 1053 } 1054 1055 /** 1056 * @tests java.lang.Math#sqrt(double) 1057 */ 1058 @TestTargetNew( 1059 level = TestLevel.COMPLETE, 1060 notes = "", 1061 method = "sqrt", 1062 args = {double.class} 1063 ) 1064 public void test_sqrtD() { 1065 // Test for method double java.lang.Math.sqrt(double) 1066 assertEquals("Incorrect root returned2", 7, Math.sqrt(49), 0); 1067 assertEquals("Incorrect value is returned", Double.NaN, 1068 Math.sqrt(Double.NaN)); 1069 assertEquals("Incorrect value is returned", Double.NaN, 1070 Math.sqrt(-1)); 1071 assertEquals("Incorrect value is returned", Double.POSITIVE_INFINITY, 1072 Math.sqrt(Double.POSITIVE_INFINITY)); 1073 assertEquals("Incorrect value is returned", 0.0, Math.sqrt(0.0)); 1074 assertEquals("Incorrect value is returned", -0.0, Math.sqrt(-0.0)); 1075 } 1076 1077 /** 1078 * @tests java.lang.Math#tan(double) 1079 */ 1080 @TestTargetNew( 1081 level = TestLevel.COMPLETE, 1082 notes = "", 1083 method = "tan", 1084 args = {double.class} 1085 ) 1086 public void test_tanD() { 1087 // Test for method double java.lang.Math.tan(double) 1088 assertEquals("Incorrect answer", 0.0, Math.tan(0), 0D); 1089 assertEquals("Incorrect answer", 1.5574077246549023, Math.tan(1), 0D); 1090 1091 double [] args = {Double.NaN, Double.POSITIVE_INFINITY, 1092 Double.NEGATIVE_INFINITY}; 1093 for(int i = 0; i < args.length; i++) { 1094 assertEquals("Incorrest returned value.", Double.NaN, 1095 Math.tan(args[i])); 1096 } 1097 1098 assertEquals("Incorrest returned value.", 0.0, Math.tan(0.0)); 1099 assertEquals("Incorrest returned value.", -0.0, Math.tan(-0.0)); 1100 } 1101 1102 /** 1103 * @tests java.lang.Math#tanh(double) 1104 */ 1105 @TestTargetNew( 1106 level = TestLevel.COMPLETE, 1107 notes = "", 1108 method = "tanh", 1109 args = {double.class} 1110 ) 1111 public void test_tanh_D() { 1112 // Test for special situations 1113 assertTrue("Should return NaN", Double.isNaN(Math.tanh(Double.NaN))); 1114 assertEquals("Should return +1.0", +1.0, Math 1115 .tanh(Double.POSITIVE_INFINITY), 0D); 1116 assertEquals("Should return -1.0", -1.0, Math 1117 .tanh(Double.NEGATIVE_INFINITY), 0D); 1118 assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math 1119 .tanh(0.0))); 1120 assertEquals(Double.doubleToLongBits(+0.0), Double 1121 .doubleToLongBits(Math.tanh(+0.0))); 1122 assertEquals(Double.doubleToLongBits(-0.0), Double 1123 .doubleToLongBits(Math.tanh(-0.0))); 1124 1125 assertEquals("Should return 1.0", 1.0, Math.tanh(1234.56), 0D); 1126 assertEquals("Should return -1.0", -1.0, Math.tanh(-1234.56), 0D); 1127 assertEquals("Should return 9.999999999996666E-7", 1128 9.999999999996666E-7, Math.tanh(0.000001), 0D); 1129 assertEquals("Should return 0.981422884124941", 0.981422884124941, Math 1130 .tanh(2.33482), 0D); 1131 assertEquals("Should return 1.0", 1.0, Math.tanh(Double.MAX_VALUE), 0D); 1132 assertEquals("Should return 4.9E-324", 4.9E-324, Math 1133 .tanh(Double.MIN_VALUE), 0D); 1134 } 1135 1136 /** 1137 * @tests java.lang.Math#random() 1138 */ 1139 @TestTargetNew( 1140 level = TestLevel.COMPLETE, 1141 notes = "", 1142 method = "random", 1143 args = {} 1144 ) 1145 public void test_random() { 1146 // There isn't a place for these tests so just stick them here 1147 assertEquals("Wrong value E", 1148 4613303445314885481L, Double.doubleToLongBits(Math.E)); 1149 assertEquals("Wrong value PI", 1150 4614256656552045848L, Double.doubleToLongBits(Math.PI)); 1151 1152 for (int i = 500; i >= 0; i--) { 1153 double d = Math.random(); 1154 assertTrue("Generated number is out of range: " + d, d >= 0.0 1155 && d < 1.0); 1156 } 1157 } 1158 1159 /** 1160 * @tests java.lang.Math#toRadians(double) 1161 */ 1162 @TestTargetNew( 1163 level = TestLevel.COMPLETE, 1164 notes = "", 1165 method = "toRadians", 1166 args = {double.class} 1167 ) 1168 public void test_toRadiansD() { 1169 for (double d = 500; d >= 0; d -= 1.0) { 1170 double converted = Math.toDegrees(Math.toRadians(d)); 1171 assertTrue("Converted number not equal to original. d = " + d, 1172 converted >= d * 0.99999999 && converted <= d * 1.00000001); 1173 } 1174 } 1175 1176 /** 1177 * @tests java.lang.Math#toDegrees(double) 1178 */ 1179 @TestTargetNew( 1180 level = TestLevel.COMPLETE, 1181 notes = "", 1182 method = "toDegrees", 1183 args = {double.class} 1184 ) 1185 public void test_toDegreesD() { 1186 for (double d = 500; d >= 0; d -= 1.0) { 1187 double converted = Math.toRadians(Math.toDegrees(d)); 1188 assertTrue("Converted number not equal to original. d = " + d, 1189 converted >= d * 0.99999999 && converted <= d * 1.00000001); 1190 } 1191 } 1192 1193 /** 1194 * @tests java.lang.Math#ulp(double) 1195 */ 1196 @TestTargetNew( 1197 level = TestLevel.COMPLETE, 1198 notes = "", 1199 method = "ulp", 1200 args = {double.class} 1201 ) 1202 @SuppressWarnings("boxing") 1203 public void test_ulp_D() { 1204 // Test for special cases 1205 assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN))); 1206 assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math 1207 .ulp(Double.POSITIVE_INFINITY), 0D); 1208 assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math 1209 .ulp(Double.NEGATIVE_INFINITY), 0D); 1210 assertEquals("Returned incorrect value", Double.MIN_VALUE, Math 1211 .ulp(0.0), 0D); 1212 assertEquals("Returned incorrect value", Double.MIN_VALUE, Math 1213 .ulp(+0.0), 0D); 1214 assertEquals("Returned incorrect value", Double.MIN_VALUE, Math 1215 .ulp(-0.0), 0D); 1216 assertEquals("Returned incorrect value", Math.pow(2, 971), Math 1217 .ulp(Double.MAX_VALUE), 0D); 1218 assertEquals("Returned incorrect value", Math.pow(2, 971), Math 1219 .ulp(-Double.MAX_VALUE), 0D); 1220 1221 assertEquals("Returned incorrect value", Double.MIN_VALUE, Math 1222 .ulp(Double.MIN_VALUE), 0D); 1223 assertEquals("Returned incorrect value", Double.MIN_VALUE, Math 1224 .ulp(-Double.MIN_VALUE), 0D); 1225 1226 assertEquals("Returned incorrect value", 2.220446049250313E-16, Math 1227 .ulp(1.0), 0D); 1228 assertEquals("Returned incorrect value", 2.220446049250313E-16, Math 1229 .ulp(-1.0), 0D); 1230 assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math 1231 .ulp(1153.0), 0D); 1232 } 1233 1234 /** 1235 * @tests java.lang.Math#ulp(float) 1236 */ 1237 @TestTargetNew( 1238 level = TestLevel.COMPLETE, 1239 notes = "", 1240 method = "ulp", 1241 args = {float.class} 1242 ) 1243 @SuppressWarnings("boxing") 1244 public void test_ulp_f() { 1245 // Test for special cases 1246 assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN))); 1247 assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math 1248 .ulp(Float.POSITIVE_INFINITY), 0f); 1249 assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math 1250 .ulp(Float.NEGATIVE_INFINITY), 0f); 1251 assertEquals("Returned incorrect value", Float.MIN_VALUE, Math 1252 .ulp(0.0f), 0f); 1253 assertEquals("Returned incorrect value", Float.MIN_VALUE, Math 1254 .ulp(+0.0f), 0f); 1255 assertEquals("Returned incorrect value", Float.MIN_VALUE, Math 1256 .ulp(-0.0f), 0f); 1257 assertEquals("Returned incorrect value", 2.028241E31f, Math 1258 .ulp(Float.MAX_VALUE), 0f); 1259 assertEquals("Returned incorrect value", 2.028241E31f, Math 1260 .ulp(-Float.MAX_VALUE), 0f); 1261 1262 assertEquals("Returned incorrect value", 1.4E-45f, Math 1263 .ulp(Float.MIN_VALUE), 0f); 1264 assertEquals("Returned incorrect value", 1.4E-45f, Math 1265 .ulp(-Float.MIN_VALUE), 0f); 1266 1267 assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f), 1268 0f); 1269 assertEquals("Returned incorrect value", 1.1920929E-7f, 1270 Math.ulp(-1.0f), 0f); 1271 assertEquals("Returned incorrect value", 1.2207031E-4f, Math 1272 .ulp(1153.0f), 0f); 1273 assertEquals("Returned incorrect value", 5.6E-45f, Math 1274 .ulp(9.403954E-38f), 0f); 1275 } 1276} 1277