db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r441097 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang: MathTrigFunctionsTest.java _Suite.java
Date Thu, 07 Sep 2006 14:35:35 GMT
Author: djd
Date: Thu Sep  7 07:35:35 2006
New Revision: 441097

URL: http://svn.apache.org/viewvc?view=rev&rev=441097
Log:
DERBY-1802  Patch which contains JUnit tests for DERBY-475 and DERBY-592,
the built-in math functions and JDBC escape functions.
Contributed by Susan Cline home4slc@yahoo.com

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java?view=auto&rev=441097
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
Thu Sep  7 07:35:35 2006
@@ -0,0 +1,1002 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Random;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+
+public class MathTrigFunctionsTest extends BaseJDBCTestCase {
+
+	private static final boolean debugFlag = false;
+
+	private static final double SMALLEST_NEG_DERBY_DOUBLE = -1.79769E+308;
+
+	private static final double SMALL_NEG_DOUBLE = -1.79768E+308;
+
+	private static final double SMALLEST_POS_DERBY_DOUBLE = 2.225E-307;
+
+	private static final double LARGEST_POS_DERBY_DOUBLE = 1.79769E+308;
+
+	private static final double LARGEST_NEG_DERBY_DOUBLE = -2.225E-307;
+
+	private static final double[] testRadians = { -0.000000001, -0.25,
+			0.000000001, 0.25, 0.5, 0.0, 1.0, 2.0, java.lang.StrictMath.PI,
+			java.lang.StrictMath.PI };
+
+	private static final double[] testArcValues = { 0.000000001, -0.000000001,
+			0.25, -0.25, 0.5, 0.0, -0.0, 1.0, -1.0 };
+
+	private static final double[] logValues = { 0.000000001, 0.25, 0.5, 1.0,
+			45.0, 90.0, 135.0, 180.0, 270, SMALLEST_POS_DERBY_DOUBLE,
+			LARGEST_POS_DERBY_DOUBLE };
+
+	private static final double[] testValues = { SMALLEST_NEG_DERBY_DOUBLE,
+			SMALL_NEG_DOUBLE, SMALLEST_POS_DERBY_DOUBLE,
+			LARGEST_POS_DERBY_DOUBLE, LARGEST_NEG_DERBY_DOUBLE, 0.000000001,
+			-0.000000001, 0.25, -0.25, 0.5, 0.0, -0.0, 1.0, -1.0, 2.0, 3.0,
+			java.lang.StrictMath.PI, 2 * java.lang.StrictMath.PI, 4.0, 45.0,
+			90.0, 135.0, 180.0, 270 };
+
+	private static final double[] testValuesTwo = { SMALLEST_NEG_DERBY_DOUBLE,
+			SMALL_NEG_DOUBLE, SMALLEST_POS_DERBY_DOUBLE,
+			LARGEST_NEG_DERBY_DOUBLE, 0.000000001, -0.000000001, 0.25, -0.25,
+			0.5, 0.0, -0.0, 1.0, -1.0, 2.0, 3.0, java.lang.StrictMath.PI,
+			2 * java.lang.StrictMath.PI, 4.0, 45.0, 90.0, 135.0, 180.0, 270 };
+
+	/**
+	 * Tests the ACOS function which returns the arc cosine of a specified
+	 * number.
+	 * <p>
+	 * Acceptable input values to the ACOS function are DOUBLE PRECISION values
+	 * from -1 to 1. NULL returns NULL and if the absolute value of the input is
+	 * greater than 1 an SQL state of 22003 is returned.
+	 * <p>
+	 * The return value from the ACOS function is a DOUBLE PRECISION number in
+	 * radians with a range of zero to PI.
+	 * 
+	 */
+	public void testAcos() throws SQLException {
+		// test the case where the input value is null
+		executeNullValues("ACOS");
+		executeNullFn("ACOS");
+		debug();
+		for (int i = 0; i < testArcValues.length; i++) {
+			double expected = java.lang.StrictMath.acos(testArcValues[i]);
+			double rValue = executeValues("ACOS", testArcValues[i]);
+			debug("ACOS: input value: " + testArcValues[i]
+					+ " expected value: " + expected + " return value: "
+					+ rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("ACOS", testArcValues[i]);
+			assertEquals(expected, fValue, 0.0);
+
+		}
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.acos(randD);
+			double rVal = executeValues("ACOS", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("ACOS", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		/* test the case where the input value is out of range */
+		try {
+			executeValues("ACOS", 2.0);
+			fail("ACOS: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+		/* test the case where the input value is out of range */
+		try {
+			executeFn("ACOS", 2.0);
+			fail("ACOS: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the ASIN function which returns the arc sine of a specified number.
+	 * <p>
+	 * Acceptable input values to the ASIN function are DOUBLE PRECISION values
+	 * from -1 to 1.
+	 * <p>
+	 * If the specified number is zero (0), the result of this function is zero.
+	 * Note: Derby does not support negative zero.
+	 * <p>
+	 * An input value of NULL returns NULL.
+	 * <p>
+	 * If the absolute value of the input is greater than 1 an SQL state of
+	 * 22003 is returned.
+	 * <p>
+	 * The return value from the ASIN function is a DOUBLE PRECISION number in
+	 * radians with a range of -PI/2 to PI/2.
+	 * 
+	 */
+	public void testAsin() throws SQLException {
+		executeNullValues("ASIN");
+		executeNullFn("ASIN");
+		debug();
+		for (int i = 0; i < testArcValues.length; i++) {
+			double expected = java.lang.StrictMath.asin(testArcValues[i]);
+			double rValue = executeValues("ASIN", testArcValues[i]);
+			debug("ASIN: input value: " + testArcValues[i]
+					+ " expected value: " + expected + " return value: "
+					+ rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("ASIN", testArcValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.asin(randD);
+			double rVal = executeValues("ASIN", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("ASIN", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("ASIN", 2.0);
+			fail("ASIN: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("ASIN", 2.0);
+			fail("ASIN: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the ATAN function which returns the arc tangent of a specified
+	 * number. Acceptable input values to the ATAN function are DOUBLE PRECISION
+	 * values.
+	 * <p>
+	 * If the specified number is zero (0), the result of this function is zero.
+	 * An input value of NULL returns NULL.
+	 * <p>
+	 * The return value from the ATAN function is a DOUBLE PRECISION number in
+	 * radians with a range of -PI/2 to PI/2.
+	 * 
+	 */
+	public void testAtan() throws SQLException {
+		executeNullValues("ATAN");
+		executeNullFn("ATAN");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.atan(testValues[i]);
+			double rValue = executeValues("ATAN", testValues[i]);
+			debug("ATAN: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("ATAN", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.atan(randD);
+			double rVal = executeValues("ATAN", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("ATAN", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+	}
+
+	/**
+	 * Tests the COS function which returns the cosine of a specified number.
+	 * <p>
+	 * Acceptable input values to the COS function are DOUBLE PRECISION values.
+	 * <p>
+	 * An input value of NULL returns NULL.
+	 */
+	public void testCos() throws SQLException {
+		executeNullValues("COS");
+		executeNullFn("COS");
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.cos(testValues[i]);
+			double rValue = executeValues("COS", testValues[i]);
+			debug("COS: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("COS", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.cos(randD);
+			double rVal = executeValues("COS", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("COS", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+	}
+
+	/**
+	 * Tests the SIN function which returns the sine of a specified number.
+	 * <p>
+	 * Acceptable input values to the SIN function are DOUBLE PRECISION values.
+	 * <p>
+	 * An input value of NULL returns NULL.
+	 * <p>
+	 * If the argument is zero, then the result is zero.
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+	public void testSin() throws SQLException {
+		executeNullValues("SIN");
+		executeNullFn("SIN");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.sin(testValues[i]);
+			double rValue = executeValues("SIN", testValues[i]);
+			debug("SIN: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("SIN", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.sin(randD);
+			double rVal = executeValues("SIN", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("SIN", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+	}
+
+	/**
+	 * Tests the TAN function which returns the tangent of a specified number.
+	 * <p>
+	 * Acceptable input values to the TAN function are DOUBLE PRECISION values.
+	 * <p>
+	 * An input value of NULL returns NULL.
+	 * <p>
+	 * If the argument is zero, then the result is zero.
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+	public void testTan() throws SQLException {
+		executeNullValues("TAN");
+
+		executeNullFn("TAN");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.tan(testValues[i]);
+			double rValue = executeValues("TAN", testValues[i]);
+			debug("TAN: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("TAN", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.tan(randD);
+			double rVal = executeValues("TAN", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("TAN", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+	}
+
+	/**
+	 * Tests the PI function which returns a value that is closer than any other
+	 * value to pi.
+	 * <p>
+	 * The constant pi is the ratio of the circumference of a circle to the
+	 * diameter of a circle.
+	 * <p>
+	 * No input values are allowed for the PI function.
+	 */
+
+	public void testPI() throws SQLException {
+		double value = executeValues("PI");
+		assertEquals(java.lang.StrictMath.PI, value, 0.0);
+		double fValue = executeFn("PI");
+		assertEquals(java.lang.StrictMath.PI, fValue, 0.0);
+
+		try {
+			executeValues("PI", 2.0);
+			fail("PI: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// '<statement>' is not recognized as a function or procedure.
+			assertSQLState("42Y03", sqlE);
+		}
+
+		try {
+			executeFn("PI", 2.0);
+			fail("PI: Out of range test failed, input value is: " + 2.0);
+		} catch (SQLException sqlE) {
+			// '<statement>' is not recognized as a function or procedure.
+			assertSQLState("42Y03", sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the DEGREES function which converts a DOUBLE PRECISION number from
+	 * radians to degrees.
+	 * <p>
+	 * The input is an angle measured in radians, which is converted to an
+	 * approximately equivalent angle measured in degrees.
+	 * <p>
+	 * The conversion from radians to degrees is not exact. You should not
+	 * expect that the COS(DEGREES(PI/2)) to exactly equal 0.0.
+	 * <p>
+	 * The return value is a DOUBLE PRECISION number.
+	 */
+	public void testDegrees() throws SQLException {
+		executeNullValues("DEGREES");
+		executeNullFn("DEGREES");
+
+		debug();
+		for (int i = 0; i < testRadians.length; i++) {
+			double expected = java.lang.StrictMath.toDegrees(testRadians[i]);
+			double rValue = executeValues("DEGREES", testRadians[i]);
+			// rValue = executeValues("DEGREES", SMALL_NEG_DOUBLE);
+			debug("DEGREES: input value: " + testRadians[i]
+					+ " expected value: " + expected + " return value: "
+					+ rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("DEGREES", testRadians[i]);
+			assertEquals(expected, fValue, 0.0);
+
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.toDegrees(randD);
+			double rVal = executeValues("DEGREES", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("DEGREES", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("DEGREES", SMALLEST_NEG_DERBY_DOUBLE);
+			fail("DEGREES: Out of range test failed, input value is: "
+					+ SMALLEST_NEG_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("DEGREES", SMALLEST_NEG_DERBY_DOUBLE);
+			fail("DEGREES: Out of range test failed, input value is: "
+					+ SMALLEST_NEG_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+	}
+
+	/**
+	 * Tests the RADIANS function which converts a DOUBLE PRECISION number from
+	 * degrees to radians.
+	 * <p>
+	 * The input is an angle measured in degrees, which is converted to an
+	 * approximately equivalent angle measured in radians.
+	 * <p>
+	 * The conversion from radians to degrees is not exact. You should not
+	 * expect that the COS(RADIANS(90.0)) to exactly equal 0.0.
+	 * <p>
+	 * The return value is a DOUBLE PRECISION number.
+	 */
+	public void testRadians() throws SQLException {
+		executeNullValues("RADIANS");
+
+		executeNullFn("RADIANS");
+
+		debug();
+		for (int i = 0; i < testArcValues.length; i++) {
+			double expected = java.lang.StrictMath.toRadians(testArcValues[i]);
+			double rValue = executeValues("RADIANS", testArcValues[i]);
+			debug("RADIANS: input value: " + testArcValues[i]
+					+ " expected value: " + expected + " return value: "
+					+ rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("RADIANS", testArcValues[i]);
+			assertEquals(expected, fValue, 0.0);
+
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.toRadians(randD);
+			double rVal = executeValues("RADIANS", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("RADIANS", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("RADIANS", SMALLEST_POS_DERBY_DOUBLE);
+			fail("RADIANS: Out of range test failed, input value is: "
+					+ SMALLEST_NEG_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("RADIANS", SMALLEST_POS_DERBY_DOUBLE);
+			fail("RADIANS: Out of range test failed, input value is: "
+					+ SMALLEST_NEG_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+	}
+
+	/**
+	 * Tests the EXP function which returns e raised to the power of the input
+	 * DOUBLE PRECISION number. The input number is the exponent to raise e to.
+	 * <p>
+	 * The constant e is the base of the natural logarithms.
+	 * <p>
+	 * The return value is a DOUBLE PRECISION number.
+	 * 
+	 * @throws SQLException
+	 */
+	public void testExp() throws SQLException {
+		executeNullValues("EXP");
+		executeNullFn("EXP");
+
+		debug();
+		for (int i = 0; i < testValuesTwo.length; i++) {
+			double expected = java.lang.StrictMath.exp(testValuesTwo[i]);
+			double rValue = executeValues("EXP", testValuesTwo[i]);
+			debug("EXP: input value: " + testValuesTwo[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("EXP", testValuesTwo[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.exp(randD);
+			double rVal = executeValues("EXP", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("EXP", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("EXP", LARGEST_POS_DERBY_DOUBLE);
+			fail("EXP: Out of range test failed, input value is: "
+					+ LARGEST_POS_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("EXP", LARGEST_POS_DERBY_DOUBLE);
+			fail("EXP: Out of range test failed, input value is: "
+					+ LARGEST_POS_DERBY_DOUBLE);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the LOG10 function which returns the base-10 logarithm of a DOUBLE
+	 * PRECISION number that is greater than zero.
+	 * <p>
+	 * If the input value is NULL, the result of this function is NULL.
+	 * <p>
+	 * If the input value is zero or a negative number, an exception is returned
+	 * that indicates that the value is out of range (SQL state 22003).
+	 * <p>
+	 * The return type is a DOUBLE PRECISION number.
+	 */
+
+	public void testLog10() throws SQLException {
+		executeNullValues("LOG10");
+		executeNullFn("LOG10");
+
+		debug();
+		for (int i = 0; i < logValues.length; i++) {
+			// ln 10 = y * (log base 10 (10))
+			// 2.3025850929940456840179914546844 = y * 1
+			double expected = java.lang.StrictMath.log(logValues[i]) / 2.3025850929940456840179914546844;
+			double rValue = executeValues("LOG10", logValues[i]);
+			debug("LOG10: input value: " + logValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("LOG10", logValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.log(randD) / 2.3025850929940456840179914546844;
+			double rVal = executeValues("LOG10", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("LOG10", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("LOG10", 0.0);
+			fail("LOG10: Out of range test failed, input value is: " + 0.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeValues("LOG10", -1.0);
+			fail("LOG10: Out of range test failed, input value is: " + -1.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+		try {
+			executeFn("LOG10", 0.0);
+			fail("LOG10: Out of range test failed, input value is: " + 0.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("LOG10", -1.0);
+			fail("LOG10: Out of range test failed, input value is: " + -1.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the LOG function which returns the natural logarithm (base e) of a
+	 * DOUBLE PRECISION number that is greater than zero (0).
+	 * <p>
+	 * If the specified number is NULL, the result of these functions is NULL.
+	 * If the specified number is zero or a negative number, an exception is
+	 * returned that indicates that the value is out of range (SQL state 22003).
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+	public void testLog() throws SQLException {
+		executeNullValues("LOG");
+		executeNullFn("LOG");
+
+		debug();
+		for (int i = 0; i < logValues.length; i++) {
+			double expected = java.lang.StrictMath.log(logValues[i]);
+			double rValue = executeValues("LOG", logValues[i]);
+			debug("LOG: input value: " + logValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("LOG", logValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.log(randD);
+			double rVal = executeValues("LOG", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("LOG", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+		try {
+			executeValues("LOG", 0.0);
+			fail("LOG: Out of range test failed, input value is: " + 0.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+		try {
+			executeFn("LOG", 0.0);
+			fail("LOG: Out of range test failed, input value is: " + 0.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the LN function which returns the natural logarithm (base e) of a
+	 * DOUBLE PRECISION number that is greater than zero (0).
+	 * <p>
+	 * If the specified number is NULL, the result of these functions is NULL.
+	 * If the specified number is zero or a negative number, an exception is
+	 * returned that indicates that the value is out of range (SQL state 22003).
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+	public void testLn() throws SQLException {
+		executeNullValues("LN");
+		// Note: the syntax 'values {fn ln(value)}' is not supported
+		// Object fnVal = executeNullFn("LN");
+		debug();
+		for (int i = 0; i < logValues.length; i++) {
+			double expected = java.lang.StrictMath.log(logValues[i]);
+			double rValue = executeValues("LN", logValues[i]);
+			debug("LOG: input value: " + logValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.log(randD);
+			double rVal = executeValues("LN", randD);
+			assertEquals(expect, rVal, 0.0);
+		}
+
+		try {
+			executeValues("LN", 0.0);
+			fail("LOG: Out of range test failed, input value is: " + 0.0);
+		} catch (SQLException sqlE) {
+			// "ERROR 22003: The resulting value is outside the range for the
+			// data type DOUBLE.";
+			assertSQLState(
+					SQLStateConstants.DATA_EXCEPTION_NUMERIC_VALUE_OUT_OF_RANGE,
+					sqlE);
+		}
+
+	}
+
+	/**
+	 * Tests the CEIL function which rounds a DOUBLE PRECISION number up, and
+	 * return the smallest number that is greater than or equal to the input
+	 * number.
+	 * <p>
+	 * If the input number is NULL, the result of these functions is NULL. If
+	 * the input number is equal to a mathematical integer, the result of these
+	 * functions is the same as the input number. If the input number is zero
+	 * (0), the result of these functions is zero. If the input number is less
+	 * than zero but greater than -1.0, then the result of these functions is
+	 * zero.
+	 * <p>
+	 * The returned value is the smallest (closest to negative infinity) double
+	 * floating point value that is greater than or equal to the specified
+	 * number. The returned value is equal to a mathematical integer.
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+
+	public void testCeil() throws SQLException {
+		executeNullValues("CEIL");
+
+		// Note: the syntax 'values {fn CEIL(value)}' is not supported
+		// Object fnVal = executeNullFn("CEIL");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.ceil(testValues[i]);
+			double rValue = executeValues("CEIL", testValues[i]);
+			debug("CEIL: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.ceil(randD);
+			double rVal = executeValues("CEIL", randD);
+			assertEquals(expect, rVal, 0.0);
+		}
+
+	}
+
+	/**
+	 * Tests the CEILING function which rounds a DOUBLE PRECISION number up, and
+	 * return the smallest number that is greater than or equal to the input
+	 * number.
+	 * <p>
+	 * If the input number is NULL, the result of these functions is NULL. If
+	 * the input number is equal to a mathematical integer, the result of these
+	 * functions is the same as the input number. If the input number is zero
+	 * (0), the result of these functions is zero. If the input number is less
+	 * than zero but greater than -1.0, then the result of these functions is
+	 * zero.
+	 * <p>
+	 * The returned value is the smallest (closest to negative infinity) double
+	 * floating point value that is greater than or equal to the specified
+	 * number. The returned value is equal to a mathematical integer.
+	 * <p>
+	 * The data type of the returned value is a DOUBLE PRECISION number.
+	 */
+	public void testCeiling() throws SQLException {
+		executeNullValues("CEILING");
+
+		executeNullFn("CEILING");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.ceil(testValues[i]);
+			double rValue = executeValues("CEILING", testValues[i]);
+			debug("CEILING: input value: " + testValues[i]
+					+ " expected value: " + expected + " return value: "
+					+ rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("CEILING", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.ceil(randD);
+			double rVal = executeValues("CEILING", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("CEILING", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+
+	}
+
+	/**
+	 * Tests the FLOOR function which rounds the input value which must be a
+	 * DOUBLE PRECISION number down, and returns the largest number that is less
+	 * than or equal to the input value.
+	 * <p>
+	 * If the input value is NULL, the result of this function is NULL. If the
+	 * input value is equal to a mathematical integer, the result of this
+	 * function is the same as the input number. If the input value is zero (0),
+	 * the result of this function is zero.
+	 * <p>
+	 * The returned value is the largest (closest to positive infinity) double
+	 * floating point value that is less than or equal to the input value. The
+	 * returned value is equal to a mathematical integer. The data type of the
+	 * returned value is a DOUBLE PRECISION number.
+	 * 
+	 * @throws SQLException
+	 */
+
+	public void testFloor() throws SQLException {
+		executeNullValues("FLOOR");
+
+		executeNullFn("FLOOR");
+
+		debug();
+		for (int i = 0; i < testValues.length; i++) {
+			double expected = java.lang.StrictMath.floor(testValues[i]);
+			double rValue = executeValues("FLOOR", testValues[i]);
+			debug("FLOOR: input value: " + testValues[i] + " expected value: "
+					+ expected + " return value: " + rValue);
+			assertEquals(expected, rValue, 0.0);
+			double fValue = executeFn("FLOOR", testValues[i]);
+			assertEquals(expected, fValue, 0.0);
+		}
+
+		Random rand = new java.util.Random();
+		for (int i = 0; i < 100; i++) {
+			double randD = rand.nextDouble();
+			double expect = java.lang.StrictMath.floor(randD);
+			double rVal = executeValues("FLOOR", randD);
+			assertEquals(expect, rVal, 0.0);
+			double fVal = executeFn("FLOOR", randD);
+			assertEquals(expect, fVal, 0.0);
+
+		}
+	}
+
+	private double executeValues(String functionName) throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values " + functionName + "()");
+		double rValue = 0.0;
+		while (rs.next()) {
+			rValue = rs.getDouble(1);
+		}
+		rs.close();
+		stmt.close();
+		return rValue;
+	}
+
+	private double executeValues(String functionName, double value)
+			throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values " + functionName + "(" + value
+				+ ")");
+		double rValue = 0.0;
+		while (rs.next()) {
+			rValue = rs.getDouble(1);
+		}
+		rs.close();
+		stmt.close();
+		return rValue;
+	}
+
+	private void executeNullValues(String functionName) throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values " + functionName + "(null)");
+		Object rValue = new Object();
+		while (rs.next()) {
+			rValue = rs.getObject(1);
+		}
+		rs.close();
+		stmt.close();
+		assertNull(rValue);
+	}
+
+	private double executeFn(String functionName) throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values {fn " + functionName + "()}");
+		double rValue = 0.0;
+		while (rs.next()) {
+			rValue = rs.getDouble(1);
+		}
+		rs.close();
+		stmt.close();
+		return rValue;
+	}
+
+	private double executeFn(String functionName, double value)
+			throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values {fn  " + functionName + "("
+				+ value + ")}");
+		double rValue = 0.0;
+		while (rs.next()) {
+			rValue = rs.getDouble(1);
+		}
+		rs.close();
+		stmt.close();
+		return rValue;
+	}
+
+	private void executeNullFn(String functionName) throws SQLException {
+		Statement stmt = createStatement();
+		ResultSet rs = stmt.executeQuery("values {fn  " + functionName
+				+ "(null)}");
+		Object rValue = new Object();
+		while (rs.next()) {
+			rValue = rs.getObject(1);
+		}
+		rs.close();
+		stmt.close();
+		assertNull(rValue);
+	}
+
+	private void debug(String message) {
+		if (debugFlag) {
+			System.out.println(message);
+		}
+	}
+
+	private void debug() {
+		if (debugFlag) {
+			System.out.println();
+		}
+	}
+
+	public MathTrigFunctionsTest(String name) {
+		super(name);
+	}
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite();
+		suite.addTestSuite(MathTrigFunctionsTest.class);
+		return suite;
+	}
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MathTrigFunctionsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java?view=diff&rev=441097&r1=441096&r2=441097
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
Thu Sep  7 07:35:35 2006
@@ -60,6 +60,7 @@
 		// suite.addTest(PrepareExecuteDDL.suite());
 		suite.addTest(LangScripts.suite());
         suite.addTest(GroupByExpressionTest.suite());
+        suite.addTest(suite.addTest(MathTrigFunctionsTest.suite());
 		
 		// Tests that are compiled using 1.4 target need to
 		// be added this way, otherwise creating the suite



Mime
View raw message