Search in sources :

Example 1 with PCGenModifier

use of pcgen.base.calculation.PCGenModifier in project pcgen by PCGen.

the class SetSolverManagerTest method setUp.

@Before
public void setUp() throws Exception {
    FunctionLibrary fl = new SimpleFunctionLibrary();
    fl.addFunction(new DropIntoContext());
    OperatorLibrary ol = new SimpleOperatorLibrary();
    vc = new TrackingVariableCache();
    vsLib = new LegalScopeLibrary();
    EquipmentScope equipScope = new EquipmentScope();
    equipScope.setParent(globalScope);
    vsLib.registerScope(equipScope);
    sl = new VariableLibrary(vsLib);
    arrayManager = new ArrayFormatManager<>(stringManager, ',');
    ManagerFactory managerFactory = new ManagerFactory() {
    };
    siFactory = new ScopeInstanceFactory(vsLib);
    fm = new SimpleFormulaManager(ol, sl, siFactory, vc, new SolverFactory());
    fm = fm.getWith(FormulaManager.FUNCTION, fl);
    SolverFactory solverFactory = new SolverFactory();
    ModifierFactory am1 = new plugin.modifier.set.SetModifierFactory<>();
    PCGenModifier emptyArrayMod = am1.getModifier(0, "", managerFactory, null, globalScope, arrayManager);
    solverFactory.addSolverFormat(arrayManager.getManagedClass(), emptyArrayMod);
    NEPCalculation calc = new ProcessCalculation<>(new Equipment(), new BasicSet(), equipmentManager);
    CalculationModifier em = new CalculationModifier<>(calc, 0);
    solverFactory.addSolverFormat(Equipment.class, em);
    manager = new DynamicSolverManager(fm, managerFactory, solverFactory, vc);
    ModifierFactory mfn = new plugin.modifier.number.SetModifierFactory();
    Modifier mod = mfn.getModifier(0, "0", managerFactory, null, globalScope, numberManager);
    solverFactory.addSolverFormat(numberManager.getManagedClass(), mod);
    ModifierFactory mfs = new plugin.modifier.string.SetModifierFactory();
    Modifier mods = mfs.getModifier(0, "", managerFactory, null, globalScope, stringManager);
    solverFactory.addSolverFormat(stringManager.getManagedClass(), mods);
}
Also used : CalculationModifier(pcgen.base.calculation.CalculationModifier) ProcessCalculation(pcgen.cdom.content.ProcessCalculation) FunctionLibrary(pcgen.base.formula.base.FunctionLibrary) SimpleFunctionLibrary(pcgen.base.formula.inst.SimpleFunctionLibrary) NEPCalculation(pcgen.base.calculation.NEPCalculation) DropIntoContext(plugin.function.DropIntoContext) SimpleFormulaManager(pcgen.base.formula.inst.SimpleFormulaManager) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) EquipmentScope(pcgen.cdom.formula.scope.EquipmentScope) TrackingVariableCache(pcgen.base.solver.testsupport.TrackingVariableCache) OperatorLibrary(pcgen.base.formula.base.OperatorLibrary) SimpleOperatorLibrary(pcgen.base.formula.inst.SimpleOperatorLibrary) LegalScopeLibrary(pcgen.base.formula.base.LegalScopeLibrary) CalculationModifier(pcgen.base.calculation.CalculationModifier) PCGenModifier(pcgen.base.calculation.PCGenModifier) SimpleOperatorLibrary(pcgen.base.formula.inst.SimpleOperatorLibrary) SimpleFunctionLibrary(pcgen.base.formula.inst.SimpleFunctionLibrary) VariableLibrary(pcgen.base.formula.base.VariableLibrary) ManagerFactory(pcgen.base.formula.base.ManagerFactory) Equipment(pcgen.core.Equipment) ScopeInstanceFactory(pcgen.base.formula.inst.ScopeInstanceFactory) PCGenModifier(pcgen.base.calculation.PCGenModifier) Before(org.junit.Before)

Example 2 with PCGenModifier

use of pcgen.base.calculation.PCGenModifier in project pcgen by PCGen.

the class SetSolverManagerTest method testProcessDependentSet.

@Test
public void testProcessDependentSet() {
    sl.assertLegalVariableID("Regions", globalScope, arrayManager);
    ScopeInstance scopeInst = siFactory.getGlobalInstance(globalScope.getName());
    VariableID<String[]> regions = (VariableID<String[]>) sl.getVariableID(scopeInst, "Regions");
    manager.createChannel(regions);
    Object[] array = vc.get(regions);
    List<Object> list = Arrays.asList(array);
    assertEquals(0, array.length);
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
    ModifierFactory am1 = new plugin.modifier.set.AddModifierFactory<>();
    PCGenModifier mod = am1.getModifier(2000, "France,England", new ManagerFactory() {
    }, null, globalScope, arrayManager);
    manager.addModifier(regions, mod, scopeInst);
    array = vc.get(regions);
    assertThat(2, is(array.length));
    list = Arrays.asList(array);
    assertTrue(list.contains("England"));
    assertTrue(list.contains("France"));
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
    ModifierFactory am2 = new plugin.modifier.set.AddModifierFactory<>();
    mod = am2.getModifier(3000, "Greece,England", new ManagerFactory() {
    }, null, globalScope, arrayManager);
    manager.addModifier(regions, mod, scopeInst);
    array = vc.get(regions);
    assertThat(3, is(array.length));
    list = Arrays.asList(array);
    assertTrue(list.contains("England"));
    assertTrue(list.contains("France"));
    assertTrue(list.contains("Greece"));
    assertTrue(vc.set.contains(regions));
    assertEquals(1, vc.set.size());
    vc.reset();
}
Also used : ScopeInstance(pcgen.base.formula.base.ScopeInstance) ManagerFactory(pcgen.base.formula.base.ManagerFactory) VariableID(pcgen.base.formula.base.VariableID) PCGenModifier(pcgen.base.calculation.PCGenModifier) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) Test(org.junit.Test)

Example 3 with PCGenModifier

use of pcgen.base.calculation.PCGenModifier 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)

Aggregations

PCGenModifier (pcgen.base.calculation.PCGenModifier)3 ManagerFactory (pcgen.base.formula.base.ManagerFactory)3 ModifierFactory (pcgen.rules.persistence.token.ModifierFactory)3 Test (org.junit.Test)2 CalculationModifier (pcgen.base.calculation.CalculationModifier)2 NEPCalculation (pcgen.base.calculation.NEPCalculation)2 ScopeInstance (pcgen.base.formula.base.ScopeInstance)2 VariableID (pcgen.base.formula.base.VariableID)2 ProcessCalculation (pcgen.cdom.content.ProcessCalculation)2 Equipment (pcgen.core.Equipment)2 Before (org.junit.Before)1 FunctionLibrary (pcgen.base.formula.base.FunctionLibrary)1 LegalScope (pcgen.base.formula.base.LegalScope)1 LegalScopeLibrary (pcgen.base.formula.base.LegalScopeLibrary)1 OperatorLibrary (pcgen.base.formula.base.OperatorLibrary)1 VariableLibrary (pcgen.base.formula.base.VariableLibrary)1 ScopeInstanceFactory (pcgen.base.formula.inst.ScopeInstanceFactory)1 SimpleFormulaManager (pcgen.base.formula.inst.SimpleFormulaManager)1 SimpleFunctionLibrary (pcgen.base.formula.inst.SimpleFunctionLibrary)1 SimpleLegalScope (pcgen.base.formula.inst.SimpleLegalScope)1