Search in sources :

Example 11 with ManagerFactory

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

the class MaxNumberModifierTest method testGetModifier.

@Test
public void testGetModifier() {
    MaxModifierFactory factory = new MaxModifierFactory();
    Modifier<Number> modifier = factory.getModifier(35, "6.5", new ManagerFactory() {
    }, null, varScope, numManager);
    assertEquals((35L << 32) + factory.getInherentPriority(), modifier.getPriority());
    assertSame(Number.class, modifier.getVariableFormat());
    assertEquals(6.5, modifier.process(EvalManagerUtilities.getInputEM(4.3)));
    assertEquals(9.3, modifier.process(EvalManagerUtilities.getInputEM(9.3)));
}
Also used : ManagerFactory(pcgen.base.formula.base.ManagerFactory) Test(org.junit.Test)

Example 12 with ManagerFactory

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

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

the class SetBooleanModifierTest method testInvalidConstruction.

@Test
public void testInvalidConstruction() {
    try {
        ModifierFactory m = new SetModifierFactory();
        m.getModifier(100, null, new ManagerFactory() {
        }, null, null, null);
        fail("Expected SetModifier with null set value to fail");
    } catch (IllegalArgumentException | NullPointerException e) {
    //Yep!
    }
}
Also used : ManagerFactory(pcgen.base.formula.base.ManagerFactory) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) Test(org.junit.Test)

Example 14 with ManagerFactory

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

the class AddNumberModifierTest method testInvalidConstruction.

@Test
public void testInvalidConstruction() {
    try {
        ModifierFactory m = new AddModifierFactory();
        m.getModifier(100, null, new ManagerFactory() {
        }, null, null, null);
        fail("Expected AddModifier with null adder to fail");
    } catch (IllegalArgumentException | NullPointerException e) {
    //Yep!
    }
}
Also used : ManagerFactory(pcgen.base.formula.base.ManagerFactory) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) Test(org.junit.Test)

Example 15 with ManagerFactory

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

the class SetBooleanModifierTest method testGetModifier.

@Test
public void testGetModifier() {
    ModifierFactory factory = new SetModifierFactory();
    Modifier<Boolean> modifier = factory.getModifier(5, "True", new ManagerFactory() {
    }, null, varScope, booleanManager);
    assertEquals(5L << 32, modifier.getPriority());
    assertSame(Boolean.class, modifier.getVariableFormat());
    assertEquals(Boolean.TRUE, modifier.process(EvalManagerUtilities.getInputEM(Boolean.FALSE)));
}
Also used : ManagerFactory(pcgen.base.formula.base.ManagerFactory) ModifierFactory(pcgen.rules.persistence.token.ModifierFactory) Test(org.junit.Test)

Aggregations

ManagerFactory (pcgen.base.formula.base.ManagerFactory)21 Test (org.junit.Test)20 ModifierFactory (pcgen.rules.persistence.token.ModifierFactory)8 PCGenModifier (pcgen.base.calculation.PCGenModifier)3 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 EvaluationManager (pcgen.base.formula.base.EvaluationManager)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