public void valueTest(String expr, String expected) throws ParseException, Exception { Node node = j.parse(expr); Object res = j.evaluate(node); if (j.hasError()) fail("Evaluation Failure: " + expr + j.getErrorInfo()); assertEquals("<" + expr + ">", expected, res.toString()); System.out.println("Sucess value of <" + expr + "> is " + res.toString()); }
public void complexValueTest(String expr, Complex expected, double tol) throws Exception { Node node = j.parse(expr); Object res = j.evaluate(node); assertTrue( "<" + expr + "> expected: <" + expected + "> but was <" + res + ">", expected.equals((Complex) res, tol)); System.out.println("Sucess value of <" + expr + "> is " + res); }
/* public void simplifyTestString(String expr,String expected) throws ParseException { Node node = j.parse(expr); Node matEqn = j.preprocess(node); String res = j.toString(matEqn); if(!expected.equals(res)) System.out.println("Error: Value of \""+expr+"\" is \""+res+"\" should be \""+expected+"\""); assertEquals("<"+expr+">",expected,res); System.out.println("Sucess: Value of \""+expr+"\" is \""+res+"\""); // System.out.print("Full Brackets:\t"); // j.pv.setFullBrackets(true); // j.pv.println(simp); // j.pv.setFullBrackets(false); } */ void rpTest(String eqns[], String eqn2) throws ParseException, Exception { for (int i = 0; i < eqns.length; ++i) { System.out.println("eqns " + eqns[i]); Node node = j.parse(eqns[i]); j.evaluate(node); } Node node3 = j.parse(eqn2); RpEval rpe = new RpEval(j); RpCommandList list = rpe.compile(node3); // rpe.copyVars(); double rpRes = rpe.evaluate(list); Object matRes = j.evaluate(node3); // System.out.println("rpRes: "+rpRes.getClass().getName()+" = "+rpRes.toString()); if (j.hasError()) fail("Evaluation Failure: " + eqn2 + j.getErrorInfo()); myAssertEquals("<" + eqn2 + ">", "" + rpRes, matRes.toString()); if (!matRes.equals(new Double(rpRes))) fail("Expected <" + matRes + "> found <" + rpRes + ">"); }
/** As before but don't test with MatrixJep.evaluate */ void rpTest2(String eqns[]) throws ParseException, Exception { Node nodes[] = new Node[eqns.length]; double rpRes[] = new double[eqns.length]; RpEval rpe = new RpEval(j); for (int i = 0; i < eqns.length; ++i) { System.out.println("eqns " + eqns[i]); nodes[i] = j.parse(eqns[i]); RpCommandList list = rpe.compile(nodes[i]); rpRes[i] = rpe.evaluate(list); System.out.println("<" + eqns[i] + "> " + rpRes[i]); } for (int i = 0; i < eqns.length; ++i) { Object matRes = j.evaluate(nodes[i]); if (!matRes.equals(new Double(rpRes[i]))) fail("Expected <" + matRes + "> found <" + rpRes[i] + ">"); } rpe.cleanUp(); }
public Object calcValue(String expr) throws ParseException, Exception { Node node = j.parse(expr); Object res = j.evaluate(node); return res; }