From 04e7ee1cba314d76fa68738cde045956266fb4d4 Mon Sep 17 00:00:00 2001 From: axexlck Date: Sat, 6 Feb 2016 18:20:30 +0100 Subject: [PATCH] Refactor Exception handling --- .../client/eval/ComplexEvalVisitor.java | 6 +- .../parser/client/eval/DoubleEvaluator.java | 2 +- .../client/eval/api/AbstractASTVisitor.java | 5 +- .../bigfraction/BigFractionEvalVisitor.java | 2 +- .../client/eval/dfp/DfpEvalVisitor.java | 16 +---- .../client/math/ArithmeticMathException.java | 23 ++++++- .../parser/client/math/MathException.java | 25 -------- .../org/matheclipse/parser/util/Console.java | 2 +- .../parser/test/ParserTestCase.java | 60 +++++++++---------- .../eval/EvalBigFractionRelaxedTestCase.java | 8 +-- .../test/eval/EvalComplexRelaxedTestCase.java | 16 ++--- .../parser/test/eval/EvalComplexTestCase.java | 12 ++-- .../test/eval/EvalDfpRelaxedTestCase.java | 19 +++--- .../test/eval/EvalDoubleRelaxedTestCase.java | 21 ++++--- .../parser/test/eval/EvalDoubleTestCase.java | 29 +++++---- 15 files changed, 110 insertions(+), 136 deletions(-) delete mode 100644 symja-parser/src/main/java/org/matheclipse/parser/client/math/MathException.java diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/ComplexEvalVisitor.java b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/ComplexEvalVisitor.java index 59e4738..cd0cd78 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/ComplexEvalVisitor.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/ComplexEvalVisitor.java @@ -45,7 +45,7 @@ import org.matheclipse.parser.client.eval.api.function.PlusFunction; import org.matheclipse.parser.client.eval.api.function.SetFunction; import org.matheclipse.parser.client.eval.api.function.TimesFunction; -import org.matheclipse.parser.client.math.MathException; +import org.matheclipse.parser.client.math.ArithmeticMathException; /** * Abstract AST visitor with empty default method implementation. @@ -323,7 +323,7 @@ public Complex visit(SymbolNode node) { if (c != null) { return c; } - throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString()); + throw new ArithmeticMathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString()); } /** @@ -431,7 +431,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) { if (complexOnly) { try { return new ComplexNode(visit(functionNode)); - } catch (Exception e) { + } catch (RuntimeException e) { } } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java index 82edf13..123b32d 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java @@ -867,7 +867,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) { if (doubleOnly) { try { return new DoubleNode(evaluateFunction(functionNode)); - } catch (Exception e) { + } catch (RuntimeException e) { } } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/api/AbstractASTVisitor.java b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/api/AbstractASTVisitor.java index c9f9731..0c177a6 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/api/AbstractASTVisitor.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/api/AbstractASTVisitor.java @@ -32,7 +32,6 @@ import org.matheclipse.parser.client.eval.ComplexNode; import org.matheclipse.parser.client.eval.DoubleNode; import org.matheclipse.parser.client.math.ArithmeticMathException; -import org.matheclipse.parser.client.math.MathException; /** * Abstract AST visitor with empty default method implementations. @@ -225,7 +224,7 @@ public T visit(FunctionNode functionNode) { } } } - throw new MathException( + throw new ArithmeticMathException( "AbstractASTVisitor#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString()); } @@ -256,7 +255,7 @@ public T visit(SymbolNode node) { if (c != null) { return c; } - throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString()); + throw new ArithmeticMathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString()); } } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/bigfraction/BigFractionEvalVisitor.java b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/bigfraction/BigFractionEvalVisitor.java index ab7bf6c..3676d8b 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/bigfraction/BigFractionEvalVisitor.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/bigfraction/BigFractionEvalVisitor.java @@ -922,7 +922,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) { // if (dfpOnly) { // try { // return new BigFractionNode(evaluateFunction(functionNode)); - // } catch (Exception e) { + // } catch (RuntimeException e) { // // } // } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/dfp/DfpEvalVisitor.java b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/dfp/DfpEvalVisitor.java index 2949f68..bb97cfc 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/eval/dfp/DfpEvalVisitor.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/eval/dfp/DfpEvalVisitor.java @@ -56,7 +56,6 @@ import org.matheclipse.parser.client.eval.api.function.SetFunction; import org.matheclipse.parser.client.eval.api.function.TimesFunction; import org.matheclipse.parser.client.math.ArithmeticMathException; -import org.matheclipse.parser.client.math.MathException; import org.matheclipse.parser.client.operator.ASTNodeFactory; /** @@ -1001,7 +1000,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) { if (dfpOnly) { try { return new DfpNode(evaluateFunction(functionNode)); - } catch (Exception e) { + } catch (RuntimeException e) { } } @@ -1089,17 +1088,4 @@ public Dfp visit(StringNode node) { return null; } - // @Override - // public Dfp visit(SymbolNode node) { - // FieldElementVariable v = fVariableMap.get(node.toString()); - // if (v != null) { - // return v.getValue(); - // } - // Dfp c = SYMBOL_DFP_MAP.get(node.toString()); - // if (c != null) { - // return c; - // } - // throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not - // possible for: " + node.toString()); - // } } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/math/ArithmeticMathException.java b/symja-parser/src/main/java/org/matheclipse/parser/client/math/ArithmeticMathException.java index f78f050..2076407 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/math/ArithmeticMathException.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/client/math/ArithmeticMathException.java @@ -1,12 +1,29 @@ package org.matheclipse.parser.client.math; -public class ArithmeticMathException extends MathException { +import org.apache.commons.math3.exception.MathRuntimeException; +import org.apache.commons.math3.exception.util.LocalizedFormats; + +public class ArithmeticMathException extends MathRuntimeException { + /** * */ - private static final long serialVersionUID = -7859219482948928259L; + private static final long serialVersionUID = -9048053527631483568L; + + final String fMessage; public ArithmeticMathException(String message) { - super(message); + super(LocalizedFormats.ILLEGAL_STATE); + fMessage = message; + } + + @Override + public String getLocalizedMessage() { + return fMessage; + } + + @Override + public String getMessage() { + return fMessage; } } diff --git a/symja-parser/src/main/java/org/matheclipse/parser/client/math/MathException.java b/symja-parser/src/main/java/org/matheclipse/parser/client/math/MathException.java deleted file mode 100644 index 584c1db..0000000 --- a/symja-parser/src/main/java/org/matheclipse/parser/client/math/MathException.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.matheclipse.parser.client.math; - -public class MathException extends RuntimeException { - - /** - * - */ - private static final long serialVersionUID = 3520033778672500363L; - - public MathException() { - super(); - } - - public MathException(String message, Throwable cause) { - super(message, cause); - } - - public MathException(String message) { - super(message); - } - - public MathException(Throwable cause) { - super(cause); - } -} \ No newline at end of file diff --git a/symja-parser/src/main/java/org/matheclipse/parser/util/Console.java b/symja-parser/src/main/java/org/matheclipse/parser/util/Console.java index d634fc7..c610dc6 100644 --- a/symja-parser/src/main/java/org/matheclipse/parser/util/Console.java +++ b/symja-parser/src/main/java/org/matheclipse/parser/util/Console.java @@ -190,7 +190,7 @@ public String interpreter(final String strEval) { } catch (MathRuntimeException e) { System.err.println(); System.err.println(e.getMessage()); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } return ""; diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/ParserTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/ParserTestCase.java index b5adbb4..c9f563f 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/ParserTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/ParserTestCase.java @@ -1,10 +1,10 @@ package org.matheclipse.parser.test; -import junit.framework.TestCase; - import org.matheclipse.parser.client.Parser; import org.matheclipse.parser.client.ast.ASTNode; +import junit.framework.TestCase; + /** * Tests parser function for SimpleParserFactory */ @@ -19,7 +19,7 @@ public void testParser() { Parser p = new Parser(true); ASTNode obj = p.parse("-a-b*c!!+d"); assertEquals(obj.toString(), "Plus(Plus(Times(-1, a), Times(-1, Times(b, Factorial2(c)))), d)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -30,7 +30,7 @@ public void testParser0() { Parser p = new Parser(true); ASTNode obj = p.parse("(#^3)&[x][y,z].{a,b,c}"); assertEquals(obj.toString(), "Dot(Function(Power(Slot(1), 3))[x][y, z], List(a, b, c))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -41,7 +41,7 @@ public void testParser1() { Parser p = new Parser(true); ASTNode obj = p.parse("Integrate(Sin(x)^2+3*x^4, x)"); assertEquals(obj.toString(), "Integrate(Plus(Power(Sin(x), 2), Times(3, Power(x, 4))), x)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -52,7 +52,7 @@ public void testParser2() { Parser p = new Parser(true); ASTNode obj = p.parse("a()[0][1]f[[x]]"); assertEquals(obj.toString(), "Times(a()[0][1], Part(f, x))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -63,7 +63,7 @@ public void testParser3() { Parser p = new Parser(true); ASTNode obj = p.parse("f(y,z)*(a+b+c)"); assertEquals(obj.toString(), "Times(f(y, z), Plus(Plus(a, b), c))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -73,7 +73,7 @@ public void testParser3a() { Parser p = new Parser(true); ASTNode obj = p.parse("f(y,z) (a+b+c)"); assertEquals(obj.toString(), "Times(f(y, z), Plus(Plus(a, b), c))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -84,7 +84,7 @@ public void testParser4() { Parser p = new Parser(true); ASTNode obj = p.parse("$a=2"); assertEquals(obj.toString(), "Set($a, 2)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -95,7 +95,7 @@ public void testParser5() { Parser p = new Parser(true); ASTNode obj = p.parse("4.7942553860420304E-1"); assertEquals(obj.toString(), "4.7942553860420304E-1"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -106,7 +106,7 @@ public void testParser6() { Parser p = new Parser(true); ASTNode obj = p.parse("a+%%%+%3*4!"); assertEquals(obj.toString(), "Plus(Plus(a, Out(-3)), Times(Out(3), Factorial(4)))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -117,7 +117,7 @@ public void testParser7() { Parser p = new Parser(true); ASTNode obj = p.parse("a+%%%+%3*:=4!"); fail("A SyntaxError exception should occur here"); - } catch (Exception e) { + } catch (RuntimeException e) { assertEquals("Syntax error in line: 1 - Operator: := is no prefix operator.\n" + "a+%%%+%3*:=4!\n" + " ^", e .getMessage()); } @@ -128,7 +128,7 @@ public void testParser8() { Parser p = new Parser(true); ASTNode obj = p.parse("-42424242424242424242"); assertEquals(obj.toString(), "-42424242424242424242"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -139,7 +139,7 @@ public void testParser9() { Parser p = new Parser(true); ASTNode obj = p.parse("-42424242424242424242.125"); assertEquals(obj.toString(), "-42424242424242424242.125"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -150,7 +150,7 @@ public void testParser10() { Parser p = new Parser(true); ASTNode obj = p.parse("-3/4"); assertEquals(obj.toString(), "-3/4"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -161,7 +161,7 @@ public void testParser11() { Parser p = new Parser(true); ASTNode obj = p.parse("-(3/4)"); assertEquals(obj.toString(), "-3/4"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -172,7 +172,7 @@ public void testParser12() { Parser p = new Parser(true); ASTNode obj = p.parse("-(Pi/4)"); assertEquals(obj.toString(), "Times(-1, Times(1/4, Pi))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -183,7 +183,7 @@ public void testParser13() { Parser p = new Parser(true); ASTNode obj = p.parse("a*b*c*d"); assertEquals(obj.toString(), "Times(Times(Times(a, b), c), d)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -195,7 +195,7 @@ public void testParser14() { ASTNode obj = p.parse("-a-b*c!!+d"); assertEquals(obj.dependsOn("d"), true); assertEquals(obj.dependsOn("x"), false); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -209,7 +209,7 @@ public void testParser15() { assertEquals( obj.toString(), "SetDelayed(Integrate(Power(Sin(Times(a_., x_)), n_IntegerQ), x_Symbol), Condition(Plus(Times(Times(-1, Power(Sin(Times(a, x)), Plus(n, Times(-1, 1)))), Times(Cos(Times(a, x)), Power(Times(n, a), -1))), Times(Times(Plus(n, Times(-1, 1)), Power(n, -1)), Integrate(Power(Sin(Times(a, x)), Plus(n, Times(-1, 2))), x))), And(Positive(n), FreeQ(a, x))))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -226,7 +226,7 @@ public void testParser16() { assertEquals(obj.toString(), "Part(f, 1, 2, f(x))"); obj = p.parse("f[[1]][[2]][[f(x)]]"); assertEquals(obj.toString(), "Part(Part(Part(f, 1), 2), f(x))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -237,7 +237,7 @@ public void testParser17() { Parser p = new Parser(true); Object obj = p.parse("Integrate(Sin(x)^2+3*x^4, x)"); assertEquals(obj.toString(), "Integrate(Plus(Power(Sin(x), 2), Times(3, Power(x, 4))), x)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -247,7 +247,7 @@ public void testParser18() { Parser p = new Parser(true); Object obj = p.parse("a()[0][1]f[[x]]"); assertEquals(obj.toString(), "Times(a()[0][1], Part(f, x))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -257,7 +257,7 @@ public void testParser19() { Parser p = new Parser(true); Object obj = p.parse("a sin()cos()x()y z"); assertEquals(obj.toString(), "Times(Times(Times(Times(Times(a, sin()), cos()), x()), y), z)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -267,7 +267,7 @@ public void testParser20() { Parser p = new Parser(true); Object obj = p.parse("((1+x) (5+x))"); assertEquals(obj.toString(), "Times(Plus(1, x), Plus(5, x))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -277,7 +277,7 @@ public void testParser21() { Parser p = new Parser(true); Object obj = p.parse("1/((1+x) (5+x))"); assertEquals(obj.toString(), "Power(Times(Plus(1, x), Plus(5, x)), -1)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -289,7 +289,7 @@ public void testParser22() { assertEquals(obj.toString(), "Times(2, Power(x, 3))"); obj = p.parse("2*(x^3)"); assertEquals(obj.toString(), "Times(2, Power(x, 3))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -299,7 +299,7 @@ public void testParser23() { Parser p = new Parser(true); Object obj = p.parse("1/2(x^3)"); assertEquals(obj.toString(), "Times(1/2, Power(x, 3))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -309,7 +309,7 @@ public void testParser24() { Parser p = new Parser(true); Object obj = p.parse("(a+b)^2 (x+y)^3 (u+w)^4"); assertEquals(obj.toString(), "Times(Times(Power(Plus(a, b), 2), Power(Plus(x, y), 3)), Power(Plus(u, w), 4))"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); } } @@ -319,7 +319,7 @@ public void testParser25() { Parser p = new Parser(true); ASTNode obj = p.parse("{ArcCsc}[[1]][x]"); assertEquals(obj.toString(), "Part(List(ArcCsc), 1)[x]"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalBigFractionRelaxedTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalBigFractionRelaxedTestCase.java index 84deb66..5db1d2b 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalBigFractionRelaxedTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalBigFractionRelaxedTestCase.java @@ -26,7 +26,7 @@ public void check(String in, String compareWith) { BigFraction bf = engine.evaluate(in); String result = BigFractionEvaluator.toString(bf); assertEquals(result, compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -65,7 +65,7 @@ public void testEval003() { bf = engine.evaluate(); result = BigFractionEvaluator.toString(bf); assertEquals(result, "208"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -83,7 +83,7 @@ public void testEval006() { vb.setValue(false); bf = engine.evaluate(); Assert.assertEquals(BigFractionEvaluator.toString(bf), "0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -104,7 +104,7 @@ public void testEval007() { vc2.setValue(-3); bf = engine.evaluate(); Assert.assertEquals(BigFractionEvaluator.toString(bf), "1"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexRelaxedTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexRelaxedTestCase.java index 7246e9a..b48493c 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexRelaxedTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexRelaxedTestCase.java @@ -25,7 +25,7 @@ public void check(String in, String compareWith) { Complex c = engine.evaluate(in); String result = ComplexEvaluator.toString(c); assertEquals(result, compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -77,7 +77,7 @@ public void testEval002() { ComplexEvaluator engine = new ComplexEvaluator(true); Complex c = engine.evaluate("Sin(pi/2*Cos(PI))"); assertEquals(ComplexEvaluator.toString(c), "-1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -95,7 +95,7 @@ public void testEval003() { c = engine.evaluate(); result = ComplexEvaluator.toString(c); assertEquals(result, "15.999999999999998+I*12.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -113,7 +113,7 @@ public void testEval006() { vb.setValue(false); cmp = engine.evaluate(); Assert.assertEquals(ComplexEvaluator.toString(cmp), "0.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -132,19 +132,19 @@ public void testEval007() { vc2.setValue(-3.0); cmp = engine.evaluate(); Assert.assertEquals(ComplexEvaluator.toString(cmp), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } } - + public void testEval010() { try { ComplexEvaluator engine = new ComplexEvaluator(true); - engine.defineVariable("x", new ComplexVariable(Complex.I)); + engine.defineVariable("x", new ComplexVariable(Complex.I)); Complex c = engine.evaluate("abs(x)"); assertEquals(ComplexEvaluator.toString(c), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexTestCase.java index bd2cd35..a07ddea 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalComplexTestCase.java @@ -33,7 +33,7 @@ public void check(String in, String compareWith) { Complex c = engine.evaluateNode(obj); String result = ComplexEvaluator.toString(c); assertEquals(result, compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -85,7 +85,7 @@ public void testEval002() { ComplexEvaluator engine = new ComplexEvaluator(); Complex c = engine.evaluate("Sin[Pi/2*Cos[Pi]]"); assertEquals(ComplexEvaluator.toString(c), "-1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -105,7 +105,7 @@ public void testEval003() { c = engine.evaluateNode(obj); result = ComplexEvaluator.toString(c); assertEquals(result, "15.999999999999998+I*12.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -123,7 +123,7 @@ public void testEval006() { vb.setValue(false); cmp = engine.evaluate(); Assert.assertEquals(ComplexEvaluator.toString(cmp), "0.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -142,7 +142,7 @@ public void testEval007() { vc2.setValue(-3.0); cmp = engine.evaluate(); Assert.assertEquals(ComplexEvaluator.toString(cmp), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -154,7 +154,7 @@ public void testEval010() { engine.defineVariable("x", new ComplexVariable(Complex.I)); Complex c = engine.evaluate("Abs[x]"); assertEquals(ComplexEvaluator.toString(c), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDfpRelaxedTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDfpRelaxedTestCase.java index 825bf4b..379664c 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDfpRelaxedTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDfpRelaxedTestCase.java @@ -9,7 +9,6 @@ import org.matheclipse.parser.client.eval.DoubleEvaluator; import org.matheclipse.parser.client.eval.api.FieldElementVariable; import org.matheclipse.parser.client.eval.dfp.DfpEvalVisitor; -import org.matheclipse.parser.client.math.ArithmeticMathException; import junit.framework.TestCase; @@ -27,7 +26,7 @@ public void check(String in, String compareWith) { DfpEvalVisitor engine = new DfpEvalVisitor(50, true); Dfp d = engine.evaluate(in); assertEquals(d.toString(), compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -81,7 +80,7 @@ public void testEval003() { DfpEvalVisitor engine = new DfpEvalVisitor(50, true); Dfp d = engine.evaluate("sin(pi/2*cOs(pi))"); assertEquals(d.toString(), "-1."); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -96,7 +95,7 @@ public void testEval004() { engine.setValue(vd, 4); d = engine.evaluate(); assertEquals(d.toString(), "19."); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -111,7 +110,7 @@ public void testEval005() { engine.setValue(vd, 4); d = engine.evaluate(); assertEquals(d.toString(), "255."); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -130,7 +129,7 @@ public void testEval006() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d.getReal(), 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -148,7 +147,7 @@ public void testEval007() { engine.setValue(vd2, 4.0); d = engine.evaluate(); Assert.assertEquals(d.getReal(), 1d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -166,7 +165,7 @@ public void testEval008() { list.add(string); } Assert.assertEquals(list.toString(), "[a, b, $c]"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -183,7 +182,7 @@ public void testEval009() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d.getReal(), 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -194,7 +193,7 @@ public void testMissingFunction009() { DfpEvalVisitor engine = new DfpEvalVisitor(50, true); Dfp d = engine.evaluate("aTest(1.0)"); assertEquals(d.toString(), ""); - } catch (ArithmeticMathException e) { + } catch (RuntimeException e) { assertEquals("DfpEvaluator#evaluateFunction(FunctionNode) not possible for: atest(1.)", e.getMessage()); } } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleRelaxedTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleRelaxedTestCase.java index e062f39..af3cbee 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleRelaxedTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleRelaxedTestCase.java @@ -8,7 +8,6 @@ import org.matheclipse.parser.client.eval.DoubleEvaluator; import org.matheclipse.parser.client.eval.DoubleVariable; import org.matheclipse.parser.client.eval.IDoubleValue; -import org.matheclipse.parser.client.math.ArithmeticMathException; import junit.framework.TestCase; @@ -26,7 +25,7 @@ public void check(String in, String compareWith) { DoubleEvaluator engine = new DoubleEvaluator(true); double d = engine.evaluate(in); assertEquals(Double.valueOf(d).toString(), compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -80,7 +79,7 @@ public void testEval003() { DoubleEvaluator engine = new DoubleEvaluator(true); double d = engine.evaluate("sin(pi/2*cOs(pi))"); assertEquals(Double.toString(d), "-1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -96,7 +95,7 @@ public void testEval004() { vd.setValue(4); d = engine.evaluate(); assertEquals(Double.valueOf(d).toString(), "19.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -112,7 +111,7 @@ public void testEval005() { vd.setValue(4); d = engine.evaluate(); assertEquals(Double.valueOf(d).toString(), "255.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -131,7 +130,7 @@ public void testEval006() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -151,7 +150,7 @@ public void testEval007() { vd2.setValue(4.0); d = engine.evaluate(); Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -169,7 +168,7 @@ public void testEval008() { list.add(string); } Assert.assertEquals(list.toString(), "[a, b, $c]"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -186,7 +185,7 @@ public void testEval009() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -197,7 +196,7 @@ public void testMissingFunction009() { DoubleEvaluator engine = new DoubleEvaluator(true); double d = engine.evaluate("aTest(1.0)"); assertEquals(Double.toString(d), ""); - } catch (ArithmeticMathException e) { + } catch (RuntimeException e) { assertEquals("EvalDouble#evaluateFunction(FunctionNode) not possible for: atest(1.0)", e.getMessage()); } } @@ -208,7 +207,7 @@ public void testEval011() { engine.defineVariable("x", -1); Double d = engine.evaluate("abs(x)"); assertEquals(Double.toString(d), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } diff --git a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleTestCase.java b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleTestCase.java index 833cb28..375b04c 100644 --- a/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleTestCase.java +++ b/symja-parser/src/test/java/org/matheclipse/parser/test/eval/EvalDoubleTestCase.java @@ -3,15 +3,14 @@ import java.util.ArrayList; import java.util.HashSet; -import junit.framework.TestCase; - import org.junit.Assert; import org.matheclipse.parser.client.ast.ASTNode; import org.matheclipse.parser.client.eval.BooleanVariable; import org.matheclipse.parser.client.eval.DoubleEvaluator; import org.matheclipse.parser.client.eval.DoubleVariable; import org.matheclipse.parser.client.eval.IDoubleValue; -import org.matheclipse.parser.client.math.ArithmeticMathException; + +import junit.framework.TestCase; /** * Tests evaluation in double expression mode @@ -27,7 +26,7 @@ public void check(String in, String compareWith) { DoubleEvaluator engine = new DoubleEvaluator(); double d = engine.evaluate(in); assertEquals(Double.valueOf(d).toString(), compareWith); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -81,7 +80,7 @@ public void testEval003() { DoubleEvaluator engine = new DoubleEvaluator(); double d = engine.evaluate("Sin[Pi/2*Cos[Pi]]"); assertEquals(Double.toString(d), "-1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -97,7 +96,7 @@ public void testEval004() { vd.setValue(4); d = engine.evaluate(); assertEquals(Double.valueOf(d).toString(), "19.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -113,7 +112,7 @@ public void testEval005() { vd.setValue(4); d = engine.evaluate(); assertEquals(Double.valueOf(d).toString(), "255.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -132,7 +131,7 @@ public void testEval006() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -152,7 +151,7 @@ public void testEval007() { vd2.setValue(4.0); d = engine.evaluate(); Assert.assertEquals(d, 1d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -170,7 +169,7 @@ public void testEval008() { list.add(string); } Assert.assertEquals(list.toString(), "[a, b, $c]"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -187,7 +186,7 @@ public void testEval009() { vb.setValue(false); d = engine.evaluate(); Assert.assertEquals(d, 0d, DoubleEvaluator.EPSILON); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); Assert.assertEquals("", e.getMessage()); } @@ -198,7 +197,7 @@ public void testMissingFunction009() { DoubleEvaluator engine = new DoubleEvaluator(); double d = engine.evaluate("aTest[1.0]"); assertEquals(Double.toString(d), ""); - } catch (ArithmeticMathException e) { + } catch (RuntimeException e) { assertEquals("EvalDouble#evaluateFunction(FunctionNode) not possible for: aTest(1.0)", e.getMessage()); } } @@ -209,7 +208,7 @@ public void testEval010() { ASTNode node = engine.parse("Sin[x]"); ASTNode result = engine.derivative(node, "x"); assertEquals(result.toString(), "Cos(x)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -221,7 +220,7 @@ public void testEval011() { engine.defineVariable("x", -1); Double d = engine.evaluate("Abs[x]"); assertEquals(Double.toString(d), "1.0"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); } @@ -236,7 +235,7 @@ public void testEval012() { ASTNode node = engine.parse("Sin[x]"); ASTNode result = engine.derivative(node, "x"); assertEquals(result.toString(), "Cos(x)"); - } catch (Exception e) { + } catch (RuntimeException e) { e.printStackTrace(); assertEquals("", e.getMessage()); }