Package tcg.common.util

Examples of tcg.common.util.ExpressionParser


      Assert.fail(ex.toString());
    }   
  }
 
  public void testSmallerThan() {
    ExpressionParser parser = null;
    Boolean boolResult = null;
   
    parser = new ExpressionParser("var1 < var2", Boolean.class);
    parser.createVariable("var1", Integer.class, new Integer(0));
    parser.createVariable("var2", Integer.class, new Integer(0));
    try
    {
      //initial state (false -> 0 < 0)
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (4 < 6)
      parser.set("var1", new Integer(4));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (6 < 6)
      parser.set("var1", new Integer(6));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (8 < 6)
      parser.set("var1", new Integer(8));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
    }
    catch(Exception ex)
    {
View Full Code Here


      Assert.fail(ex.toString());
    }   
  }
 
  public void testSmallerThanEqual() {
    ExpressionParser parser = null;
    Boolean boolResult = null;
   
    parser = new ExpressionParser("var1 <= var2", Boolean.class);
    parser.createVariable("var1", Integer.class, new Integer(0));
    parser.createVariable("var2", Integer.class, new Integer(0));
    try
    {
      //initial state (true = 0 <= 0)
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (4 <= 6)
      parser.set("var1", new Integer(4));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (6 <= 6)
      parser.set("var1", new Integer(6));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (8 < 6)
      parser.set("var1", new Integer(8));
      parser.set("var2", new Integer(6));
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
    }
    catch(Exception ex)
    {
View Full Code Here

    fail("Not yet implemented"); // TODO
   
  }
 
  public void testLogicalOr() {
    ExpressionParser parser = null;
    Boolean boolResult = null;
   
    parser = new ExpressionParser("var1 || var2", Boolean.class);
    parser.createVariable("var1", Boolean.class, Boolean.FALSE);
    parser.createVariable("var2", Boolean.class, Boolean.FALSE);
    try
    {
      //initial state
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (false || false)
      parser.set("var1", Boolean.FALSE);
      parser.set("var2", Boolean.FALSE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (false || true)
      parser.set("var1", Boolean.FALSE);
      parser.set("var2", Boolean.TRUE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (true || false)
      parser.set("var1", Boolean.TRUE);
      parser.set("var2", Boolean.FALSE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (true || true)
      parser.set("var1", Boolean.TRUE);
      parser.set("var2", Boolean.TRUE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
    }
    catch(Exception ex)
    {
View Full Code Here

    ArrayList<Class<?>> vartypes = new ArrayList<Class<?>>()
    ArrayList<Object> varvalues = new ArrayList<Object>()
   
    //create the parser
    String str = parse_expression(expression_, params, varnames, vartypes, varvalues);
    expressionParser_ = new ExpressionParser(str, type);
   
    //create all the variables
    for (int i=0; i<varnames.size(); i++)
    {
      expressionParser_.createVariable(varnames.get(i), vartypes.get(i), varvalues.get(i));
View Full Code Here

    ArrayList<Class<?>> vartypes = new ArrayList<Class<?>>()
    ArrayList<Object> varvalues = new ArrayList<Object>()
   
    //create the parser
    String str = parse_expression(lccExpression_, params, varnames, vartypes, varvalues);
    lccParser_ = new ExpressionParser(str, type);
   
    //create all the variables
    for (int i=0; i<varnames.size(); i++)
    {
      lccParser_.createVariable(varnames.get(i), vartypes.get(i), varvalues.get(i));
View Full Code Here

    ArrayList<Class<?>> vartypes = new ArrayList<Class<?>>()
    ArrayList<Object> varvalues = new ArrayList<Object>()
   
    //create the parser
    String str = parse_expression(rccExpression_, params, varnames, vartypes, varvalues);
    rccParser_ = new ExpressionParser(str, type);
   
    //create all the variables
    for (int i=0; i<varnames.size(); i++)
    {
      rccParser_.createVariable(varnames.get(i), vartypes.get(i), varvalues.get(i));
View Full Code Here

        initInputValue = new String("");
        break;
    }

    //create the parser
    rccParser_ = new ExpressionParser(engExpression_, type);
   
    //create the input variable
    rccParser_.createVariable("x", type, initInputValue);
  }
View Full Code Here

      Assert.fail(ex.toString());
    }   
  }
 
  public void testLogicalAnd() {
    ExpressionParser parser = null;
    Boolean boolResult = null;
   
    parser = new ExpressionParser("var1 && var2", Boolean.class);
    parser.createVariable("var1", Boolean.class, Boolean.FALSE);
    parser.createVariable("var2", Boolean.class, Boolean.FALSE);
    try
    {
      //initial state
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (false && false)
      parser.set("var1", Boolean.FALSE);
      parser.set("var2", Boolean.FALSE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (false && true)
      parser.set("var1", Boolean.FALSE);
      parser.set("var2", Boolean.TRUE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (true && false)
      parser.set("var1", Boolean.TRUE);
      parser.set("var2", Boolean.FALSE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
      //evaluate (true && true)
      parser.set("var1", Boolean.TRUE);
      parser.set("var2", Boolean.TRUE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
    }
    catch(Exception ex)
    {
View Full Code Here

      Assert.fail(ex.toString());
    }   
  }
 
  public void testLogicalNot() {
    ExpressionParser parser = null;
    Boolean boolResult = null;
   
    parser = new ExpressionParser("!var1", Boolean.class);
    parser.createVariable("var1", Boolean.class, Boolean.FALSE);
    try
    {
      //initial state (because var1 = false)
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (!false)
      parser.set("var1", Boolean.FALSE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(true, boolResult.booleanValue());
      //evaluate (!true)
      parser.set("var1", Boolean.TRUE);
      boolResult = (Boolean)parser.evaluate();
      Assert.assertNotNull(boolResult);
      Assert.assertEquals(false, boolResult.booleanValue());
    }
    catch(Exception ex)
    {
View Full Code Here

TOP

Related Classes of tcg.common.util.ExpressionParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.