Search in sources :

Example 11 with VariableID

use of pcgen.base.formula.base.VariableID 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)

Example 12 with VariableID

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

the class SetSolverManagerTest method testProcessDynamicSet.

@Test
public void testProcessDynamicSet() {
    LegalScope equipScope = vsLib.getScope("EQUIPMENT");
    sl.assertLegalVariableID("LocalVar", equipScope, numberManager);
    sl.assertLegalVariableID("ResultVar", globalScope, numberManager);
    sl.assertLegalVariableID("EquipVar", globalScope, equipmentManager);
    Equipment equip = new Equipment();
    equip.setName("EquipKey");
    Equipment equipalt = new Equipment();
    equipalt.setName("EquipAlt");
    ScopeInstance scopeInste = siFactory.get("EQUIPMENT", equip);
    VariableID varIDe = sl.getVariableID(scopeInste, "LocalVar");
    manager.createChannel(varIDe);
    vc.put(varIDe, 2);
    ScopeInstance scopeInsta = siFactory.get("EQUIPMENT", equipalt);
    VariableID varIDa = sl.getVariableID(scopeInsta, "LocalVar");
    manager.createChannel(varIDa);
    vc.put(varIDa, 3);
    ScopeInstance globalInst = siFactory.getGlobalInstance("Global");
    VariableID varIDq = sl.getVariableID(globalInst, "EquipVar");
    manager.createChannel(varIDq);
    VariableID varIDr = sl.getVariableID(globalInst, "ResultVar");
    manager.createChannel(varIDr);
    ModifierFactory am1 = new plugin.modifier.number.SetModifierFactory();
    ModifierFactory amString = new plugin.modifier.string.SetModifierFactory();
    PCGenModifier mod2 = am1.getModifier(2000, "2", new ManagerFactory() {
    }, fm, globalScope, numberManager);
    PCGenModifier mod3 = am1.getModifier(2000, "3", new ManagerFactory() {
    }, fm, globalScope, numberManager);
    PCGenModifier mod4 = am1.getModifier(3000, "4", new ManagerFactory() {
    }, fm, globalScope, numberManager);
    String formula = "dropIntoContext(\"EQUIPMENT\",EquipVar,LocalVar)";
    PCGenModifier modf = am1.getModifier(2000, formula, new ManagerFactory() {
    }, fm, globalScope, numberManager);
    NEPCalculation calc1 = new ProcessCalculation<>(equip, new BasicSet(), equipmentManager);
    CalculationModifier mod_e1 = new CalculationModifier<>(calc1, 2000);
    NEPCalculation calc2 = new ProcessCalculation<>(equipalt, new BasicSet(), equipmentManager);
    CalculationModifier mod_e2 = new CalculationModifier<>(calc2, 3000);
    manager.addModifier(varIDe, mod2, scopeInste);
    manager.addModifier(varIDa, mod3, scopeInsta);
    assertEquals(2, vc.get(varIDe));
    assertEquals(3, vc.get(varIDa));
    assertEquals(0, vc.get(varIDr));
    manager.addModifier(varIDq, mod_e1, globalInst);
    manager.addModifier(varIDr, modf, globalInst);
    assertEquals(2, vc.get(varIDr));
    manager.addModifier(varIDq, mod_e2, globalInst);
    assertEquals(3, vc.get(varIDr));
    manager.addModifier(varIDa, mod4, scopeInsta);
    assertEquals(4, vc.get(varIDr));
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) CalculationModifier(pcgen.base.calculation.CalculationModifier) ProcessCalculation(pcgen.cdom.content.ProcessCalculation) NEPCalculation(pcgen.base.calculation.NEPCalculation) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) ManagerFactory(pcgen.base.formula.base.ManagerFactory) Equipment(pcgen.core.Equipment) SimpleLegalScope(pcgen.base.formula.inst.SimpleLegalScope) LegalScope(pcgen.base.formula.base.LegalScope) VariableID(pcgen.base.formula.base.VariableID) PCGenModifier(pcgen.base.calculation.PCGenModifier) Test(org.junit.Test)

Example 13 with VariableID

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

the class LookupFunctionTest method testInvalidBadSemantics3.

@Test
public void testInvalidBadSemantics3() {
    Finder finder = new Finder();
    DataTable dt = doTableSetup();
    finder.map.put(DataTable.class, "A", dt);
    finder.map.put(TableColumn.class, "Value", buildColumn("Value", numberManager));
    finder.map.put(TableColumn.class, "Result", buildColumn("Value", stringManager));
    VariableLibrary vl = getVariableLibrary();
    WriteableVariableStore vs = getVariableStore();
    TableFormatFactory fac = new TableFormatFactory(finder);
    FormatManager<?> tableMgr = fac.build("STRING,NUMBER", formatLibrary);
    vl.assertLegalVariableID("TableA", getGlobalScope(), tableMgr);
    VariableID tableID = vl.getVariableID(getGlobalScopeInst(), "TableA");
    vs.put(tableID, tableMgr.convert("A"));
    String formula = "lookup(TableA,\"That\",badf())";
    SimpleNode node = TestUtilities.doParse(formula);
    isNotValid(formula, node, numberManager, null);
}
Also used : TableFormatFactory(pcgen.cdom.format.table.TableFormatFactory) DataTable(pcgen.cdom.format.table.DataTable) WriteableVariableStore(pcgen.base.formula.base.WriteableVariableStore) VariableID(pcgen.base.formula.base.VariableID) VariableLibrary(pcgen.base.formula.base.VariableLibrary) SimpleNode(pcgen.base.formula.parse.SimpleNode) Test(org.junit.Test)

Example 14 with VariableID

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

the class AbstractFormulaTestCase method getVariable.

protected VariableID<Number> getVariable(String formula) {
    VariableLibrary variableLibrary = getVariableLibrary();
    variableLibrary.assertLegalVariableID(formula, localSetup.getGlobalScopeInst().getLegalScope(), numberManager);
    return (VariableID<Number>) variableLibrary.getVariableID(localSetup.getGlobalScopeInst(), formula);
}
Also used : VariableID(pcgen.base.formula.base.VariableID) VariableLibrary(pcgen.base.formula.base.VariableLibrary)

Example 15 with VariableID

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

the class AbstractFormulaTestCase method getBooleanVariable.

protected VariableID<Boolean> getBooleanVariable(String formula) {
    VariableLibrary variableLibrary = getVariableLibrary();
    variableLibrary.assertLegalVariableID(formula, localSetup.getGlobalScopeInst().getLegalScope(), FormatUtilities.BOOLEAN_MANAGER);
    return (VariableID<Boolean>) variableLibrary.getVariableID(localSetup.getGlobalScopeInst(), formula);
}
Also used : VariableID(pcgen.base.formula.base.VariableID) VariableLibrary(pcgen.base.formula.base.VariableLibrary)

Aggregations

VariableID (pcgen.base.formula.base.VariableID)20 VariableLibrary (pcgen.base.formula.base.VariableLibrary)16 Test (org.junit.Test)14 SimpleNode (pcgen.base.formula.parse.SimpleNode)12 WriteableVariableStore (pcgen.base.formula.base.WriteableVariableStore)10 ColumnFormatFactory (pcgen.cdom.format.table.ColumnFormatFactory)8 DataTable (pcgen.cdom.format.table.DataTable)8 TableFormatFactory (pcgen.cdom.format.table.TableFormatFactory)8 ScopeInstance (pcgen.base.formula.base.ScopeInstance)6 FormulaSemantics (pcgen.base.formula.base.FormulaSemantics)3 LegalScope (pcgen.base.formula.base.LegalScope)3 ReconstructionVisitor (pcgen.base.formula.visitor.ReconstructionVisitor)3 SemanticsVisitor (pcgen.base.formula.visitor.SemanticsVisitor)3 Equipment (pcgen.core.Equipment)3 PCGenModifier (pcgen.base.calculation.PCGenModifier)2 EvaluationManager (pcgen.base.formula.base.EvaluationManager)2 ManagerFactory (pcgen.base.formula.base.ManagerFactory)2 EvaluateVisitor (pcgen.base.formula.visitor.EvaluateVisitor)2 ConsolidatedListCommitStrategy (pcgen.rules.context.ConsolidatedListCommitStrategy)2 LoadContext (pcgen.rules.context.LoadContext)2