Search in sources :

Example 6 with EvaluationManager

use of pcgen.base.formula.base.EvaluationManager in project pcgen by PCGen.

the class AbstractFormulaTestCase method evaluatesTo.

public void evaluatesTo(String formula, SimpleNode node, Object valueOf) {
    EvaluationManager manager = generateManager();
    Object result = new EvaluateVisitor().visit(node, manager);
    if (result.equals(valueOf)) {
        return;
    }
    //Try ints as double as well just in case (temporary)
    if (valueOf instanceof Integer) {
        if (result.equals(valueOf)) {
            return;
        }
    } else //Give Doubles a bit of fuzz
    if (valueOf instanceof Double) {
        if (TestUtilities.doubleEqual(((Double) valueOf).doubleValue(), ((Number) result).doubleValue(), TestUtilities.SMALL_ERROR)) {
            return;
        }
    }
    TestCase.fail("Expected " + valueOf.getClass().getSimpleName() + " (" + valueOf + ") for Formula: " + formula + ", was " + result + " (" + result.getClass().getSimpleName() + ")");
}
Also used : EvaluateVisitor(pcgen.base.formula.visitor.EvaluateVisitor) EvaluationManager(pcgen.base.formula.base.EvaluationManager)

Aggregations

EvaluationManager (pcgen.base.formula.base.EvaluationManager)6 Test (org.junit.Test)3 EvaluateVisitor (pcgen.base.formula.visitor.EvaluateVisitor)3 VariableID (pcgen.base.formula.base.VariableID)2 VariableLibrary (pcgen.base.formula.base.VariableLibrary)2 WriteableVariableStore (pcgen.base.formula.base.WriteableVariableStore)2 SimpleNode (pcgen.base.formula.parse.SimpleNode)2 IndividualSetup (pcgen.base.solver.IndividualSetup)2 SplitFormulaSetup (pcgen.base.solver.SplitFormulaSetup)2 ColumnFormatFactory (pcgen.cdom.format.table.ColumnFormatFactory)2 DataTable (pcgen.cdom.format.table.DataTable)2 TableFormatFactory (pcgen.cdom.format.table.TableFormatFactory)2 DependencyManager (pcgen.base.formula.base.DependencyManager)1 ManagerFactory (pcgen.base.formula.base.ManagerFactory)1 SimpleVariableStore (pcgen.base.formula.inst.SimpleVariableStore)1 Modifier (pcgen.base.solver.Modifier)1 MonitorableVariableStore (pcgen.cdom.formula.MonitorableVariableStore)1