}
}
public void testSubtractionDbl()
{
ExpressionParser parser = null;
Double result = null;
//using constant-value (with space)
parser = new ExpressionParser("5.6 - 1.2", Double.class);
try
{
result = (Double)parser.evaluate();
Assert.assertNotNull(result);
Assert.assertEquals(4.4, round(result.doubleValue(), 1));
}
catch(Exception ex)
{
Assert.fail(ex.toString());
}
//using constant-value (without space)
parser = new ExpressionParser("5.6-1.2", Double.class);
try
{
result = (Double)parser.evaluate();
Assert.assertNotNull(result);
Assert.assertEquals(4.4, round(result.doubleValue(), 1));
}
catch(Exception ex)
{
Assert.fail(ex.toString());
}
//using variable with space
parser = new ExpressionParser("var1 - var2", Double.class);
parser.createVariable("var1", Double.class, new Double(0));
parser.createVariable("var2", Double.class, new Double(0));
try
{
//set the variable (using variable name)
parser.set("var1", new Double(5.6));
parser.set("var2", new Double(1.2));
//evaluate (5.6 - 1.2)
result = (Double)parser.evaluate();
Assert.assertNotNull(result);
Assert.assertEquals(4.4, round(result.doubleValue(), 1));
//subtract with negative value (using index)
parser.set(1, new Double(-2.3));
//evaluate (5.6 - (-2.3))
result = (Double)parser.evaluate();
Assert.assertNotNull(result);
Assert.assertEquals(7.9, round(result.doubleValue(), 1));
//subtract from negative value (using index)
parser.set(0, new Double(-6.7));
//evaluate (-6.7 - (-2.3))
result = (Double)parser.evaluate();
Assert.assertNotNull(result);
Assert.assertEquals(-4.4, round(result.doubleValue(), 1));
}
catch(Exception ex)
{