Search in sources :

Example 1 with EvaluationManager

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

the class LookupFunctionTest method testNoLookup.

@Test
public void testNoLookup() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Name", buildColumn("Name", stringManager));
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Result", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    ColumnFormatFactory cfac = new ColumnFormatFactory(finder);
    FormatManager<?> columnMgr = cfac.build("NUMBER", formatLibrary);
    vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    VariableID columnID = vl.getVariableID(getGlobalScopeInst(), "ResultColumn");
    vs.put(columnID, columnMgr.convert("Value"));
    String formula = "lookup(TableA,\"Oh No\",ResultColumn)";
    SimpleNode node = TestUtilities.doParse(formula);
    isValid(formula, node, numberManager, null);
    isStatic(formula, node, false);
    EvaluationManager manager = generateManager();
    Object result = new EvaluateVisitor().visit(node, manager);
    if (!result.equals(0)) {
        TestCase.fail("Expected Invalid result, should have been zero due to invalid column: " + result);
    }
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) EvaluateVisitor(pcgen.base.formula.visitor.EvaluateVisitor) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) ColumnFormatFactory(pcgen.cdom.format.table.ColumnFormatFactory) EvaluationManager(pcgen.base.formula.base.EvaluationManager) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) VariableID(pcgen.base.formula.base.VariableID) Test(org.junit.Test)

Example 2 with EvaluationManager

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

the class SetNumberModifierTest method testGetFormulaModifier.

@Test
public void testGetFormulaModifier() {
    SplitFormulaSetup setup = new SplitFormulaSetup();
    setup.loadBuiltIns();
    setup.getLegalScopeLibrary().registerScope(varScope);
    IndividualSetup iSetup = new IndividualSetup(setup, "Global", new SimpleVariableStore());
    SetModifierFactory factory = new SetModifierFactory();
    Modifier<Number> modifier = factory.getModifier(35, "6+5", new ManagerFactory() {
    }, iSetup.getFormulaManager(), varScope, numManager);
    assertEquals((35L << 32) + factory.getInherentPriority(), modifier.getPriority());
    assertSame(Number.class, modifier.getVariableFormat());
    EvaluationManager evalManager = EvalManagerUtilities.getInputEM(4.3);
    assertEquals(11, modifier.process(evalManager.getWith(EvaluationManager.FMANAGER, iSetup.getFormulaManager())));
}
Also used : SplitFormulaSetup(pcgen.base.solver.SplitFormulaSetup) ManagerFactory(pcgen.base.formula.base.ManagerFactory) SimpleVariableStore(pcgen.base.formula.inst.SimpleVariableStore) IndividualSetup(pcgen.base.solver.IndividualSetup) EvaluationManager(pcgen.base.formula.base.EvaluationManager) Test(org.junit.Test)

Example 3 with EvaluationManager

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

the class AbstractFormulaTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    setup = new SplitFormulaSetup();
    LegalScopeUtilities.loadLegalScopeLibrary(setup.getLegalScopeLibrary());
    localSetup = new IndividualSetup(setup, "Global", new MonitorableVariableStore());
    setup.getSolverFactory().addSolverFormat(Number.class, new Modifier() {

        @Override
        public Object process(EvaluationManager manager) {
            return 0;
        }

        @Override
        public void getDependencies(DependencyManager fdm) {
        }

        @Override
        public long getPriority() {
            return 0;
        }

        @Override
        public Class getVariableFormat() {
            return Number.class;
        }

        @Override
        public String getIdentification() {
            return "SET";
        }

        @Override
        public String getInstructions() {
            return "0";
        }
    });
    setup.getSolverFactory().addSolverFormat(String.class, new Modifier() {

        @Override
        public Object process(EvaluationManager manager) {
            return "";
        }

        @Override
        public void getDependencies(DependencyManager fdm) {
        }

        @Override
        public long getPriority() {
            return 0;
        }

        @Override
        public Class getVariableFormat() {
            return String.class;
        }

        @Override
        public String getIdentification() {
            return "SET";
        }

        @Override
        public String getInstructions() {
            return "";
        }
    });
}
Also used : SplitFormulaSetup(pcgen.base.solver.SplitFormulaSetup) IndividualSetup(pcgen.base.solver.IndividualSetup) DependencyManager(pcgen.base.formula.base.DependencyManager) EvaluationManager(pcgen.base.formula.base.EvaluationManager) MonitorableVariableStore(pcgen.cdom.formula.MonitorableVariableStore) Modifier(pcgen.base.solver.Modifier)

Example 4 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, LoadContext context) {
    EvaluationManager manager = generateManager(context);
    performEvaluation(formula, node, valueOf, manager);
}
Also used : EvaluationManager(pcgen.base.formula.base.EvaluationManager)

Example 5 with EvaluationManager

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

the class LookupFunctionTest method testNoColumn.

@Test
public void testNoColumn() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Name", buildColumn("Name", stringManager));
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Result", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    ColumnFormatFactory cfac = new ColumnFormatFactory(finder);
    FormatManager<?> columnMgr = cfac.build("NUMBER", formatLibrary);
    vl.assertLegalVariableID("ResultColumn", getGlobalScope(), columnMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    VariableID columnID = vl.getVariableID(getGlobalScopeInst(), "ResultColumn");
    vs.put(columnID, columnMgr.convert("Result"));
    String formula = "lookup(TableA,\"That\",ResultColumn)";
    SimpleNode node = TestUtilities.doParse(formula);
    isValid(formula, node, numberManager, null);
    isStatic(formula, node, false);
    EvaluationManager manager = generateManager();
    Object result = new EvaluateVisitor().visit(node, manager);
    if (result instanceof Number) {
        TestCase.fail("Expected Invalid result, should have been a string due to invalid column: " + result);
    }
}
Also used : DataTable(pcgen.cdom.format.table.DataTable) EvaluateVisitor(pcgen.base.formula.visitor.EvaluateVisitor) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) ColumnFormatFactory(pcgen.cdom.format.table.ColumnFormatFactory) EvaluationManager(pcgen.base.formula.base.EvaluationManager) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) VariableID(pcgen.base.formula.base.VariableID) Test(org.junit.Test)

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