Exemplo n.º 1
0
  // TODO add test methods here. The name must begin with 'test'. For example:
  // public void testHello() {}
  public void testClonazione1() {
    JEP jepExpression = new JEP();
    jepExpression.setAllowUndeclared(true);
    jepExpression.addStandardConstants();
    jepExpression.addStandardFunctions();

    jepExpression.parseExpression("(a + 1) * (b - 3)");
    System.out.println("JEP: " + jepExpression);
    System.out.println(jepExpression.getTopNode().toLongString());
    System.out.println("Errori: " + jepExpression.getErrorInfo());
    Variable a = jepExpression.getVar("a");
    Variable b = jepExpression.getVar("b");
    jepExpression.setVarValue("a", 1);
    jepExpression.setVarValue("b", 2);
    System.out.println("Value: " + jepExpression.getValueAsObject());

    JEP clone = (JEP) jepExpression.clone();
    Variable aClone = clone.getVar("a");
    aClone.setDescription("a.a");
    Variable bClone = clone.getVar("b");
    bClone.setDescription("b.b");
    System.out.println(clone.getTopNode().toLongString());
    clone.setVarValue("a", 10);
    clone.setVarValue("b", 30);

    System.out.println("Value originale: " + jepExpression.getValueAsObject());
    System.out.println("Value clone: " + clone.getValueAsObject());

    System.out.println("Variable a originale: " + a.toString() + " - " + a.hashCode());
    System.out.println("Variable a clone: " + aClone.toString() + " - " + aClone.hashCode());

    System.out.println("Variable b originale: " + b.toString() + " - " + b.hashCode());
    System.out.println("Variable b clone: " + bClone.toString() + " - " + bClone.hashCode());

    System.out.println(
        "Symbol table: "
            + jepExpression.getSymbolTable()
            + " - "
            + jepExpression.getSymbolTable().hashCode());
    System.out.println(
        "Symbol table clone: "
            + clone.getSymbolTable()
            + " - "
            + clone.getSymbolTable().hashCode());
  }
Exemplo n.º 2
0
  public void test4() {
    JEP jepExpression = new JEP();
    jepExpression.setAllowUndeclared(true);
    jepExpression.addStandardConstants();
    jepExpression.addStandardFunctions();
    //        jepExpression.parseExpression("((paolo + marco + giovanni) * log(franco) ) == 1.0");
    jepExpression.parseExpression(
        "( ( (paolo + marco + giovanni) * log(franco) ) == 1.0 ) && (!luigi)");
    System.out.println("JEP: " + jepExpression);

    Variable a = jepExpression.getVar("paolo");
    a.setDescription("v2.paolo");
    System.out.println("JEP: " + jepExpression);
  }