1 16 17 package org.apache.derbyTesting.functionTests.tests.lang; 18 19 import java.sql.ResultSet ; 20 import java.sql.SQLException ; 21 import java.sql.Statement ; 22 import java.util.Random ; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 27 import org.apache.derbyTesting.functionTests.util.SQLStateConstants; 28 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 29 30 public class MathTrigFunctionsTest extends BaseJDBCTestCase { 31 32 private static final boolean debugFlag = false; 33 34 private static final double SMALLEST_NEG_DERBY_DOUBLE = -1.79769E+308; 35 36 private static final double SMALL_NEG_DOUBLE = -1.79768E+308; 37 38 private static final double SMALLEST_POS_DERBY_DOUBLE = 2.225E-307; 39 40 private static final double LARGEST_POS_DERBY_DOUBLE = 1.79769E+308; 41 42 private static final double LARGEST_NEG_DERBY_DOUBLE = -2.225E-307; 43 44 private static final double[] testRadians = { -0.000000001, -0.25, 45 0.000000001, 0.25, 0.5, 0.0, 1.0, 2.0, java.lang.StrictMath.PI, 46 java.lang.StrictMath.PI }; 47 48 private static final double[] testArcValues = { 0.000000001, -0.000000001, 49 0.25, -0.25, 0.5, 0.0, -0.0, 1.0, -1.0 }; 50 51 private static final double[] logValues = { 0.000000001, 0.25, 0.5, 1.0, 52 45.0, 90.0, 135.0, 180.0, 270, SMALLEST_POS_DERBY_DOUBLE, 53 LARGEST_POS_DERBY_DOUBLE }; 54 55 private static final double[] testValues = { SMALLEST_NEG_DERBY_DOUBLE, 56 SMALL_NEG_DOUBLE, SMALLEST_POS_DERBY_DOUBLE, 57 LARGEST_POS_DERBY_DOUBLE, LARGEST_NEG_DERBY_DOUBLE, 0.000000001, 58 -0.000000001, 0.25, -0.25, 0.5, 0.0, -0.0, 1.0, -1.0, 2.0, 3.0, 59 java.lang.StrictMath.PI, 2 * java.lang.StrictMath.PI, 4.0, 45.0, 60 90.0, 135.0, 180.0, 270 }; 61 62 private static final double[] testValuesTwo = { SMALLEST_NEG_DERBY_DOUBLE, 63 SMALL_NEG_DOUBLE, SMALLEST_POS_DERBY_DOUBLE, 64 LARGEST_NEG_DERBY_DOUBLE, 0.000000001, -0.000000001, 0.25, -0.25, 65 0.5, 0.0, -0.0, 1.0, -1.0, 2.0, 3.0, java.lang.StrictMath.PI, 66 2 * java.lang.StrictMath.PI, 4.0, 45.0, 90.0, 135.0, 180.0, 270 }; 67 68 80 public void testAcos() throws SQLException { 81 executeNullValues("ACOS"); 83 executeNullFn("ACOS"); 84 debug(); 85 for (int i = 0; i < testArcValues.length; i++) { 86 double expected = java.lang.StrictMath.acos(testArcValues[i]); 87 double rValue = executeValues("ACOS", testArcValues[i]); 88 debug("ACOS: input value: " + testArcValues[i] 89 + " expected value: " + expected + " return value: " 90 + rValue); 91 assertEquals(expected, rValue, 0.0); 92 double fValue = executeFn("ACOS", testArcValues[i]); 93 assertEquals(expected, fValue, 0.0); 94 95 } 96 Random rand = new java.util.Random (); 97 for (int i = 0; i < 100; i++) { 98 double randD = rand.nextDouble(); 99 double expect = java.lang.StrictMath.acos(randD); 100 double rVal = executeValues("ACOS", randD); 101 assertEquals(expect, rVal, 0.0); 102 double fVal = executeFn("ACOS", randD); 103 assertEquals(expect, fVal, 0.0); 104 105 } 106 107 108 try { 109 executeValues("ACOS", 2.0); 110 fail("ACOS: Out of range test failed, input value is: " + 2.0); 111 } catch (SQLException sqlE) { 112 assertSQLState( 115 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 116 sqlE); 117 } 118 119 120 try { 121 executeFn("ACOS", 2.0); 122 fail("ACOS: Out of range test failed, input value is: " + 2.0); 123 } catch (SQLException sqlE) { 124 assertSQLState( 127 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 128 sqlE); 129 } 130 131 } 132 133 151 public void testAsin() throws SQLException { 152 executeNullValues("ASIN"); 153 executeNullFn("ASIN"); 154 debug(); 155 for (int i = 0; i < testArcValues.length; i++) { 156 double expected = java.lang.StrictMath.asin(testArcValues[i]); 157 double rValue = executeValues("ASIN", testArcValues[i]); 158 debug("ASIN: input value: " + testArcValues[i] 159 + " expected value: " + expected + " return value: " 160 + rValue); 161 assertEquals(expected, rValue, 0.0); 162 double fValue = executeFn("ASIN", testArcValues[i]); 163 assertEquals(expected, fValue, 0.0); 164 } 165 166 Random rand = new java.util.Random (); 167 for (int i = 0; i < 100; i++) { 168 double randD = rand.nextDouble(); 169 double expect = java.lang.StrictMath.asin(randD); 170 double rVal = executeValues("ASIN", randD); 171 assertEquals(expect, rVal, 0.0); 172 double fVal = executeFn("ASIN", randD); 173 assertEquals(expect, fVal, 0.0); 174 175 } 176 177 try { 178 executeValues("ASIN", 2.0); 179 fail("ASIN: Out of range test failed, input value is: " + 2.0); 180 } catch (SQLException sqlE) { 181 assertSQLState( 184 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 185 sqlE); 186 } 187 try { 188 executeFn("ASIN", 2.0); 189 fail("ASIN: Out of range test failed, input value is: " + 2.0); 190 } catch (SQLException sqlE) { 191 assertSQLState( 194 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 195 sqlE); 196 } 197 198 } 199 200 212 public void testAtan() throws SQLException { 213 executeNullValues("ATAN"); 214 executeNullFn("ATAN"); 215 216 debug(); 217 for (int i = 0; i < testValues.length; i++) { 218 double expected = java.lang.StrictMath.atan(testValues[i]); 219 double rValue = executeValues("ATAN", testValues[i]); 220 debug("ATAN: input value: " + testValues[i] + " expected value: " 221 + expected + " return value: " + rValue); 222 assertEquals(expected, rValue, 0.0); 223 double fValue = executeFn("ATAN", testValues[i]); 224 assertEquals(expected, fValue, 0.0); 225 } 226 227 Random rand = new java.util.Random (); 228 for (int i = 0; i < 100; i++) { 229 double randD = rand.nextDouble(); 230 double expect = java.lang.StrictMath.atan(randD); 231 double rVal = executeValues("ATAN", randD); 232 assertEquals(expect, rVal, 0.0); 233 double fVal = executeFn("ATAN", randD); 234 assertEquals(expect, fVal, 0.0); 235 236 } 237 238 } 239 240 247 public void testCos() throws SQLException { 248 executeNullValues("COS"); 249 executeNullFn("COS"); 250 debug(); 251 for (int i = 0; i < testValues.length; i++) { 252 double expected = java.lang.StrictMath.cos(testValues[i]); 253 double rValue = executeValues("COS", testValues[i]); 254 debug("COS: input value: " + testValues[i] + " expected value: " 255 + expected + " return value: " + rValue); 256 assertEquals(expected, rValue, 0.0); 257 double fValue = executeFn("COS", testValues[i]); 258 assertEquals(expected, fValue, 0.0); 259 } 260 261 Random rand = new java.util.Random (); 262 for (int i = 0; i < 100; i++) { 263 double randD = rand.nextDouble(); 264 double expect = java.lang.StrictMath.cos(randD); 265 double rVal = executeValues("COS", randD); 266 assertEquals(expect, rVal, 0.0); 267 double fVal = executeFn("COS", randD); 268 assertEquals(expect, fVal, 0.0); 269 270 } 271 272 } 273 274 285 public void testSin() throws SQLException { 286 executeNullValues("SIN"); 287 executeNullFn("SIN"); 288 289 debug(); 290 for (int i = 0; i < testValues.length; i++) { 291 double expected = java.lang.StrictMath.sin(testValues[i]); 292 double rValue = executeValues("SIN", testValues[i]); 293 debug("SIN: input value: " + testValues[i] + " expected value: " 294 + expected + " return value: " + rValue); 295 assertEquals(expected, rValue, 0.0); 296 double fValue = executeFn("SIN", testValues[i]); 297 assertEquals(expected, fValue, 0.0); 298 } 299 300 Random rand = new java.util.Random (); 301 for (int i = 0; i < 100; i++) { 302 double randD = rand.nextDouble(); 303 double expect = java.lang.StrictMath.sin(randD); 304 double rVal = executeValues("SIN", randD); 305 assertEquals(expect, rVal, 0.0); 306 double fVal = executeFn("SIN", randD); 307 assertEquals(expect, fVal, 0.0); 308 309 } 310 311 } 312 313 324 public void testTan() throws SQLException { 325 executeNullValues("TAN"); 326 327 executeNullFn("TAN"); 328 329 debug(); 330 for (int i = 0; i < testValues.length; i++) { 331 double expected = java.lang.StrictMath.tan(testValues[i]); 332 double rValue = executeValues("TAN", testValues[i]); 333 debug("TAN: input value: " + testValues[i] + " expected value: " 334 + expected + " return value: " + rValue); 335 assertEquals(expected, rValue, 0.0); 336 double fValue = executeFn("TAN", testValues[i]); 337 assertEquals(expected, fValue, 0.0); 338 } 339 340 Random rand = new java.util.Random (); 341 for (int i = 0; i < 100; i++) { 342 double randD = rand.nextDouble(); 343 double expect = java.lang.StrictMath.tan(randD); 344 double rVal = executeValues("TAN", randD); 345 assertEquals(expect, rVal, 0.0); 346 double fVal = executeFn("TAN", randD); 347 assertEquals(expect, fVal, 0.0); 348 349 } 350 351 } 352 353 362 363 public void testPI() throws SQLException { 364 double value = executeValues("PI"); 365 assertEquals(java.lang.StrictMath.PI, value, 0.0); 366 double fValue = executeFn("PI"); 367 assertEquals(java.lang.StrictMath.PI, fValue, 0.0); 368 369 try { 370 executeValues("PI", 2.0); 371 fail("PI: Out of range test failed, input value is: " + 2.0); 372 } catch (SQLException sqlE) { 373 assertSQLState("42Y03", sqlE); 375 } 376 377 try { 378 executeFn("PI", 2.0); 379 fail("PI: Out of range test failed, input value is: " + 2.0); 380 } catch (SQLException sqlE) { 381 assertSQLState("42Y03", sqlE); 383 } 384 385 } 386 387 399 public void testDegrees() throws SQLException { 400 executeNullValues("DEGREES"); 401 executeNullFn("DEGREES"); 402 403 debug(); 404 for (int i = 0; i < testRadians.length; i++) { 405 double expected = java.lang.StrictMath.toDegrees(testRadians[i]); 406 double rValue = executeValues("DEGREES", testRadians[i]); 407 debug("DEGREES: input value: " + testRadians[i] 409 + " expected value: " + expected + " return value: " 410 + rValue); 411 assertEquals(expected, rValue, 0.0); 412 double fValue = executeFn("DEGREES", testRadians[i]); 413 assertEquals(expected, fValue, 0.0); 414 415 } 416 417 Random rand = new java.util.Random (); 418 for (int i = 0; i < 100; i++) { 419 double randD = rand.nextDouble(); 420 double expect = java.lang.StrictMath.toDegrees(randD); 421 double rVal = executeValues("DEGREES", randD); 422 assertEquals(expect, rVal, 0.0); 423 double fVal = executeFn("DEGREES", randD); 424 assertEquals(expect, fVal, 0.0); 425 426 } 427 428 try { 429 executeValues("DEGREES", SMALLEST_NEG_DERBY_DOUBLE); 430 fail("DEGREES: Out of range test failed, input value is: " 431 + SMALLEST_NEG_DERBY_DOUBLE); 432 } catch (SQLException sqlE) { 433 assertSQLState( 436 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 437 sqlE); 438 } 439 try { 440 executeFn("DEGREES", SMALLEST_NEG_DERBY_DOUBLE); 441 fail("DEGREES: Out of range test failed, input value is: " 442 + SMALLEST_NEG_DERBY_DOUBLE); 443 } catch (SQLException sqlE) { 444 assertSQLState( 447 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 448 sqlE); 449 } 450 } 451 452 464 public void testRadians() throws SQLException { 465 executeNullValues("RADIANS"); 466 467 executeNullFn("RADIANS"); 468 469 debug(); 470 for (int i = 0; i < testArcValues.length; i++) { 471 double expected = java.lang.StrictMath.toRadians(testArcValues[i]); 472 double rValue = executeValues("RADIANS", testArcValues[i]); 473 debug("RADIANS: input value: " + testArcValues[i] 474 + " expected value: " + expected + " return value: " 475 + rValue); 476 assertEquals(expected, rValue, 0.0); 477 double fValue = executeFn("RADIANS", testArcValues[i]); 478 assertEquals(expected, fValue, 0.0); 479 480 } 481 482 Random rand = new java.util.Random (); 483 for (int i = 0; i < 100; i++) { 484 double randD = rand.nextDouble(); 485 double expect = java.lang.StrictMath.toRadians(randD); 486 double rVal = executeValues("RADIANS", randD); 487 assertEquals(expect, rVal, 0.0); 488 double fVal = executeFn("RADIANS", randD); 489 assertEquals(expect, fVal, 0.0); 490 491 } 492 493 try { 494 executeValues("RADIANS", SMALLEST_POS_DERBY_DOUBLE); 495 fail("RADIANS: Out of range test failed, input value is: " 496 + SMALLEST_NEG_DERBY_DOUBLE); 497 } catch (SQLException sqlE) { 498 assertSQLState( 501 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 502 sqlE); 503 } 504 try { 505 executeFn("RADIANS", SMALLEST_POS_DERBY_DOUBLE); 506 fail("RADIANS: Out of range test failed, input value is: " 507 + SMALLEST_NEG_DERBY_DOUBLE); 508 } catch (SQLException sqlE) { 509 assertSQLState( 512 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 513 sqlE); 514 } 515 } 516 517 527 public void testExp() throws SQLException { 528 executeNullValues("EXP"); 529 executeNullFn("EXP"); 530 531 debug(); 532 for (int i = 0; i < testValuesTwo.length; i++) { 533 double expected = java.lang.StrictMath.exp(testValuesTwo[i]); 534 double rValue = executeValues("EXP", testValuesTwo[i]); 535 debug("EXP: input value: " + testValuesTwo[i] + " expected value: " 536 + expected + " return value: " + rValue); 537 assertEquals(expected, rValue, 0.0); 538 double fValue = executeFn("EXP", testValuesTwo[i]); 539 assertEquals(expected, fValue, 0.0); 540 } 541 542 Random rand = new java.util.Random (); 543 for (int i = 0; i < 100; i++) { 544 double randD = rand.nextDouble(); 545 double expect = java.lang.StrictMath.exp(randD); 546 double rVal = executeValues("EXP", randD); 547 assertEquals(expect, rVal, 0.0); 548 double fVal = executeFn("EXP", randD); 549 assertEquals(expect, fVal, 0.0); 550 551 } 552 553 try { 554 executeValues("EXP", LARGEST_POS_DERBY_DOUBLE); 555 fail("EXP: Out of range test failed, input value is: " 556 + LARGEST_POS_DERBY_DOUBLE); 557 } catch (SQLException sqlE) { 558 assertSQLState( 561 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 562 sqlE); 563 } 564 try { 565 executeFn("EXP", LARGEST_POS_DERBY_DOUBLE); 566 fail("EXP: Out of range test failed, input value is: " 567 + LARGEST_POS_DERBY_DOUBLE); 568 } catch (SQLException sqlE) { 569 assertSQLState( 572 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 573 sqlE); 574 } 575 576 } 577 578 589 590 public void testLog10() throws SQLException { 591 executeNullValues("LOG10"); 592 executeNullFn("LOG10"); 593 594 debug(); 595 for (int i = 0; i < logValues.length; i++) { 596 double expected = java.lang.StrictMath.log(logValues[i]) / 2.3025850929940456840179914546844; 599 double rValue = executeValues("LOG10", logValues[i]); 600 debug("LOG10: input value: " + logValues[i] + " expected value: " 601 + expected + " return value: " + rValue); 602 assertEquals(expected, rValue, 0.0); 603 double fValue = executeFn("LOG10", logValues[i]); 604 assertEquals(expected, fValue, 0.0); 605 } 606 607 Random rand = new java.util.Random (); 608 for (int i = 0; i < 100; i++) { 609 double randD = rand.nextDouble(); 610 double expect = java.lang.StrictMath.log(randD) / 2.3025850929940456840179914546844; 611 double rVal = executeValues("LOG10", randD); 612 assertEquals(expect, rVal, 0.0); 613 double fVal = executeFn("LOG10", randD); 614 assertEquals(expect, fVal, 0.0); 615 616 } 617 618 try { 619 executeValues("LOG10", 0.0); 620 fail("LOG10: Out of range test failed, input value is: " + 0.0); 621 } catch (SQLException sqlE) { 622 assertSQLState( 625 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 626 sqlE); 627 } 628 try { 629 executeValues("LOG10", -1.0); 630 fail("LOG10: Out of range test failed, input value is: " + -1.0); 631 } catch (SQLException sqlE) { 632 assertSQLState( 635 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 636 sqlE); 637 } 638 639 try { 640 executeFn("LOG10", 0.0); 641 fail("LOG10: Out of range test failed, input value is: " + 0.0); 642 } catch (SQLException sqlE) { 643 assertSQLState( 646 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 647 sqlE); 648 } 649 try { 650 executeFn("LOG10", -1.0); 651 fail("LOG10: Out of range test failed, input value is: " + -1.0); 652 } catch (SQLException sqlE) { 653 assertSQLState( 656 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 657 sqlE); 658 } 659 660 } 661 662 672 public void testLog() throws SQLException { 673 executeNullValues("LOG"); 674 executeNullFn("LOG"); 675 676 debug(); 677 for (int i = 0; i < logValues.length; i++) { 678 double expected = java.lang.StrictMath.log(logValues[i]); 679 double rValue = executeValues("LOG", logValues[i]); 680 debug("LOG: input value: " + logValues[i] + " expected value: " 681 + expected + " return value: " + rValue); 682 assertEquals(expected, rValue, 0.0); 683 double fValue = executeFn("LOG", logValues[i]); 684 assertEquals(expected, fValue, 0.0); 685 } 686 687 Random rand = new java.util.Random (); 688 for (int i = 0; i < 100; i++) { 689 double randD = rand.nextDouble(); 690 double expect = java.lang.StrictMath.log(randD); 691 double rVal = executeValues("LOG", randD); 692 assertEquals(expect, rVal, 0.0); 693 double fVal = executeFn("LOG", randD); 694 assertEquals(expect, fVal, 0.0); 695 696 } 697 698 try { 699 executeValues("LOG", 0.0); 700 fail("LOG: Out of range test failed, input value is: " + 0.0); 701 } catch (SQLException sqlE) { 702 assertSQLState( 705 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 706 sqlE); 707 } 708 try { 709 executeFn("LOG", 0.0); 710 fail("LOG: Out of range test failed, input value is: " + 0.0); 711 } catch (SQLException sqlE) { 712 assertSQLState( 715 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 716 sqlE); 717 } 718 719 } 720 721 731 public void testLn() throws SQLException { 732 executeNullValues("LN"); 733 debug(); 736 for (int i = 0; i < logValues.length; i++) { 737 double expected = java.lang.StrictMath.log(logValues[i]); 738 double rValue = executeValues("LN", logValues[i]); 739 debug("LOG: input value: " + logValues[i] + " expected value: " 740 + expected + " return value: " + rValue); 741 assertEquals(expected, rValue, 0.0); 742 } 743 744 Random rand = new java.util.Random (); 745 for (int i = 0; i < 100; i++) { 746 double randD = rand.nextDouble(); 747 double expect = java.lang.StrictMath.log(randD); 748 double rVal = executeValues("LN", randD); 749 assertEquals(expect, rVal, 0.0); 750 } 751 752 try { 753 executeValues("LN", 0.0); 754 fail("LOG: Out of range test failed, input value is: " + 0.0); 755 } catch (SQLException sqlE) { 756 assertSQLState( 759 SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE, 760 sqlE); 761 } 762 763 } 764 765 783 784 public void testCeil() throws SQLException { 785 executeNullValues("CEIL"); 786 787 790 debug(); 791 for (int i = 0; i < testValues.length; i++) { 792 double expected = java.lang.StrictMath.ceil(testValues[i]); 793 double rValue = executeValues("CEIL", testValues[i]); 794 debug("CEIL: input value: " + testValues[i] + " expected value: " 795 + expected + " return value: " + rValue); 796 assertEquals(expected, rValue, 0.0); 797 } 798 799 Random rand = new java.util.Random (); 800 for (int i = 0; i < 100; i++) { 801 double randD = rand.nextDouble(); 802 double expect = java.lang.StrictMath.ceil(randD); 803 double rVal = executeValues("CEIL", randD); 804 assertEquals(expect, rVal, 0.0); 805 } 806 807 } 808 809 827 public void testCeiling() throws SQLException { 828 executeNullValues("CEILING"); 829 830 executeNullFn("CEILING"); 831 832 debug(); 833 for (int i = 0; i < testValues.length; i++) { 834 double expected = java.lang.StrictMath.ceil(testValues[i]); 835 double rValue = executeValues("CEILING", testValues[i]); 836 debug("CEILING: input value: " + testValues[i] 837 + " expected value: " + expected + " return value: " 838 + rValue); 839 assertEquals(expected, rValue, 0.0); 840 double fValue = executeFn("CEILING", testValues[i]); 841 assertEquals(expected, fValue, 0.0); 842 } 843 844 Random rand = new java.util.Random (); 845 for (int i = 0; i < 100; i++) { 846 double randD = rand.nextDouble(); 847 double expect = java.lang.StrictMath.ceil(randD); 848 double rVal = executeValues("CEILING", randD); 849 assertEquals(expect, rVal, 0.0); 850 double fVal = executeFn("CEILING", randD); 851 assertEquals(expect, fVal, 0.0); 852 853 } 854 855 } 856 857 874 875 public void testFloor() throws SQLException { 876 executeNullValues("FLOOR"); 877 878 executeNullFn("FLOOR"); 879 880 debug(); 881 for (int i = 0; i < testValues.length; i++) { 882 double expected = java.lang.StrictMath.floor(testValues[i]); 883 double rValue = executeValues("FLOOR", testValues[i]); 884 debug("FLOOR: input value: " + testValues[i] + " expected value: " 885 + expected + " return value: " + rValue); 886 assertEquals(expected, rValue, 0.0); 887 double fValue = executeFn("FLOOR", testValues[i]); 888 assertEquals(expected, fValue, 0.0); 889 } 890 891 Random rand = new java.util.Random (); 892 for (int i = 0; i < 100; i++) { 893 double randD = rand.nextDouble(); 894 double expect = java.lang.StrictMath.floor(randD); 895 double rVal = executeValues("FLOOR", randD); 896 assertEquals(expect, rVal, 0.0); 897 double fVal = executeFn("FLOOR", randD); 898 assertEquals(expect, fVal, 0.0); 899 900 } 901 } 902 903 private double executeValues(String functionName) throws SQLException { 904 Statement stmt = createStatement(); 905 ResultSet rs = stmt.executeQuery("values " + functionName + "()"); 906 double rValue = 0.0; 907 while (rs.next()) { 908 rValue = rs.getDouble(1); 909 } 910 rs.close(); 911 stmt.close(); 912 return rValue; 913 } 914 915 private double executeValues(String functionName, double value) 916 throws SQLException { 917 Statement stmt = createStatement(); 918 ResultSet rs = stmt.executeQuery("values " + functionName + "(" + value 919 + ")"); 920 double rValue = 0.0; 921 while (rs.next()) { 922 rValue = rs.getDouble(1); 923 } 924 rs.close(); 925 stmt.close(); 926 return rValue; 927 } 928 929 private void executeNullValues(String functionName) throws SQLException { 930 Statement stmt = createStatement(); 931 ResultSet rs = stmt.executeQuery("values " + functionName + "(null)"); 932 Object rValue = new Object (); 933 while (rs.next()) { 934 rValue = rs.getObject(1); 935 } 936 rs.close(); 937 stmt.close(); 938 assertNull(rValue); 939 } 940 941 private double executeFn(String functionName) throws SQLException { 942 Statement stmt = createStatement(); 943 ResultSet rs = stmt.executeQuery("values {fn " + functionName + "()}"); 944 double rValue = 0.0; 945 while (rs.next()) { 946 rValue = rs.getDouble(1); 947 } 948 rs.close(); 949 stmt.close(); 950 return rValue; 951 } 952 953 private double executeFn(String functionName, double value) 954 throws SQLException { 955 Statement stmt = createStatement(); 956 ResultSet rs = stmt.executeQuery("values {fn " + functionName + "(" 957 + value + ")}"); 958 double rValue = 0.0; 959 while (rs.next()) { 960 rValue = rs.getDouble(1); 961 } 962 rs.close(); 963 stmt.close(); 964 return rValue; 965 } 966 967 private void executeNullFn(String functionName) throws SQLException { 968 Statement stmt = createStatement(); 969 ResultSet rs = stmt.executeQuery("values {fn " + functionName 970 + "(null)}"); 971 Object rValue = new Object (); 972 while (rs.next()) { 973 rValue = rs.getObject(1); 974 } 975 rs.close(); 976 stmt.close(); 977 assertNull(rValue); 978 } 979 980 private void debug(String message) { 981 if (debugFlag) { 982 System.out.println(message); 983 } 984 } 985 986 private void debug() { 987 if (debugFlag) { 988 System.out.println(); 989 } 990 } 991 992 public MathTrigFunctionsTest(String name) { 993 super(name); 994 } 995 996 public static Test suite() { 997 TestSuite suite = new TestSuite(); 998 suite.addTestSuite(MathTrigFunctionsTest.class); 999 return suite; 1000 } 1001 1002} 1003 | Popular Tags |