use of pcgen.base.formula.base.ManagerFactory in project pcgen by PCGen.
the class MinNumberModifierTest method testGetModifier.
@Test
public void testGetModifier() {
MinModifierFactory factory = new MinModifierFactory();
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(4.3, modifier.process(EvalManagerUtilities.getInputEM(4.3)));
assertEquals(6.5, modifier.process(EvalManagerUtilities.getInputEM(9.3)));
}
use of pcgen.base.formula.base.ManagerFactory 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);
}
use of pcgen.base.formula.base.ManagerFactory 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();
}
use of pcgen.base.formula.base.ManagerFactory in project pcgen by PCGen.
the class AddNumberModifierTest method testGetModifier.
@Test
public void testGetModifier() {
AddModifierFactory factory = new AddModifierFactory();
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(10.8, modifier.process(EvalManagerUtilities.getInputEM(4.3)));
}
use of pcgen.base.formula.base.ManagerFactory in project pcgen by PCGen.
the class DivideNumberModifierTest method testGetModifier.
@Test
public void testGetModifier() {
DivideModifierFactory factory = new DivideModifierFactory();
Modifier<Number> modifier = factory.getModifier(35, "4.3", new ManagerFactory() {
}, null, varScope, numManager);
assertEquals((35L << 32) + factory.getInherentPriority(), modifier.getPriority());
assertSame(Number.class, modifier.getVariableFormat());
assertEquals(3.2, modifier.process(EvalManagerUtilities.getInputEM(13.76)));
}
Aggregations