/hg/rhino-tests: Added five new tests to the test suite src/org/...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Tue Nov 27 00:56:09 PST 2012


changeset b67b5f8f811b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=b67b5f8f811b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Tue Nov 27 09:59:10 2012 +0100

	Added five new tests to the test suite src/org/RhinoTests/CompiledScriptTest.java.
	Added new code snippets into src/org/RhinoTests/JavaScriptSnippets.java.


diffstat:

 ChangeLog                                  |   8 ++
 src/org/RhinoTests/CompiledScriptTest.java |  84 ++++++++++++++++++++++++++++-
 src/org/RhinoTests/JavaScriptSnippets.java |  27 +++++++++-
 3 files changed, 114 insertions(+), 5 deletions(-)

diffs (153 lines):

diff -r 4876f3e3df53 -r b67b5f8f811b ChangeLog
--- a/ChangeLog	Mon Nov 26 11:34:08 2012 +0100
+++ b/ChangeLog	Tue Nov 27 09:59:10 2012 +0100
@@ -1,3 +1,11 @@
+2012-11-27  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/CompiledScriptTest.java:
+	Added five new tests to this test suite.
+
+	* src/org/RhinoTests/JavaScriptSnippets.java:
+	Added new code snippets.
+
 2012-11-26  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/BindingsTest.java:
diff -r 4876f3e3df53 -r b67b5f8f811b src/org/RhinoTests/CompiledScriptTest.java
--- a/src/org/RhinoTests/CompiledScriptTest.java	Mon Nov 26 11:34:08 2012 +0100
+++ b/src/org/RhinoTests/CompiledScriptTest.java	Tue Nov 27 09:59:10 2012 +0100
@@ -149,8 +149,54 @@
      * @throws ScriptException
      *             this exception is thrown when this test case failed.
      */
-    protected void testEvalNumericExpression() throws ScriptException {
-    	CompiledScript script = getCompiledScript("1+2*3");
+    protected void testEvalNumericExpression1() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_1);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 3, "wrong result " + doubleResult);
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 3, "wrong result " + integerResult);
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalNumericExpression2() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_2);
+    	Object result = script.eval();
+    	assertNotNull(result, "result should not be null");
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+		if (getJavaVersion() >= 7) {
+			assertTrue(result instanceof Double, "result is not an instance of Double");
+			double doubleResult = ((Double) result).doubleValue();
+			assertEquals(doubleResult, 6, "wrong result " + doubleResult);
+		}
+		else {
+			assertTrue(result instanceof Integer, "result is not an instance of Integer");
+			int integerResult = ((Integer) result).intValue();
+			assertEquals(integerResult, 6, "wrong result " + integerResult);
+		}
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalNumericExpression3() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.NUMERIC_EXPRESSION_3);
     	Object result = script.eval();
     	assertNotNull(result, "result should not be null");
     	assertTrue(result instanceof Number, "result is not an instance of Number");
@@ -172,8 +218,38 @@
      * @throws ScriptException
      *             this exception is thrown when this test case failed.
      */
-    protected void testEvalDoubleExpression() throws ScriptException {
-    	CompiledScript script = getCompiledScript("1./2");
+    protected void testEvalDoubleExpression1() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_1);
+    	Object result = script.eval();
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+    	assertTrue(result instanceof Double, "result is not an instance of Integer");
+		double doubleResult = ((Double) result).doubleValue();
+    	assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult);
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalDoubleExpression2() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_2);
+    	Object result = script.eval();
+    	assertTrue(result instanceof Number, "result is not an instance of Number");
+    	assertTrue(result instanceof Double, "result is not an instance of Integer");
+		double doubleResult = ((Double) result).doubleValue();
+    	assertEquals(doubleResult, 0.5f, "wrong result " + doubleResult);
+    }
+
+    /**
+     * Test if it is possible to compile and then run script from a string.
+     * 
+     * @throws ScriptException
+     *             this exception is thrown when this test case failed.
+     */
+    protected void testEvalDoubleExpression3() throws ScriptException {
+    	CompiledScript script = getCompiledScript(JavaScriptSnippets.DOUBLE_NUMERIC_EXPRESSION_3);
     	Object result = script.eval();
     	assertTrue(result instanceof Number, "result is not an instance of Number");
     	assertTrue(result instanceof Double, "result is not an instance of Integer");
diff -r 4876f3e3df53 -r b67b5f8f811b src/org/RhinoTests/JavaScriptSnippets.java
--- a/src/org/RhinoTests/JavaScriptSnippets.java	Mon Nov 26 11:34:08 2012 +0100
+++ b/src/org/RhinoTests/JavaScriptSnippets.java	Tue Nov 27 09:59:10 2012 +0100
@@ -80,7 +80,32 @@
     /**
      * Numeric expression.
      */
-    protected static final String NUMERIC_EXPRESSION_1 = "1+2*3";
+    protected static final String NUMERIC_EXPRESSION_1 = "1+2";
+
+    /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_2 = "1+2+3";
+
+    /**
+     * Numeric expression.
+     */
+    protected static final String NUMERIC_EXPRESSION_3 = "1+2*3";
+
+    /**
+     * Numeric expression containing floating point value.
+     */
+    protected static final String DOUBLE_NUMERIC_EXPRESSION_1 = "1./2";
+
+    /**
+     * Numeric expression containing floating point value.
+     */
+    protected static final String DOUBLE_NUMERIC_EXPRESSION_2 = "1/2.";
+
+    /**
+     * Numeric expression containing floating point value.
+     */
+    protected static final String DOUBLE_NUMERIC_EXPRESSION_3 = "1./2.";
 
     /**
      * Classical hello world program. 



More information about the distro-pkg-dev mailing list