Exemplo n.º 1
0
 /** 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();
 }
Exemplo n.º 2
0
  /*
  	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 + ">");
  }