use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreMultTest method testMultiFeats.
/**
* Test to ensure that a number of feat test will
* correctly require a number of separate feats in
* any combination of two types.
* @throws Exception
*/
public void testMultiFeats() throws Exception {
final Ability metamagic1 = new Ability();
metamagic1.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
metamagic1.setName("MM1");
metamagic1.put(StringKey.KEY_NAME, "MM1");
metamagic1.setCDOMCategory(AbilityCategory.FEAT);
final Ability metamagic2 = new Ability();
metamagic2.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
metamagic2.setName("MM2");
metamagic2.put(StringKey.KEY_NAME, "MM2");
metamagic2.setCDOMCategory(AbilityCategory.FEAT);
final Ability metamagic3 = new Ability();
metamagic3.addToListFor(ListKey.TYPE, Type.getConstant("METAMAGIC"));
metamagic3.setName("MM3");
metamagic3.put(StringKey.KEY_NAME, "MM3");
metamagic3.setCDOMCategory(AbilityCategory.FEAT);
final Ability item1 = new Ability();
item1.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
item1.setName("IC1");
item1.put(StringKey.KEY_NAME, "IC1");
item1.setCDOMCategory(AbilityCategory.FEAT);
final Ability item2 = new Ability();
item2.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
item2.setName("IC2");
item2.put(StringKey.KEY_NAME, "IC2");
item2.setCDOMCategory(AbilityCategory.FEAT);
final Ability item3 = new Ability();
item3.addToListFor(ListKey.TYPE, Type.getConstant("ItemCreation"));
item3.setName("IC3");
item3.put(StringKey.KEY_NAME, "IC3");
item3.setCDOMCategory(AbilityCategory.FEAT);
final PlayerCharacter character = getCharacter();
final PreAbilityParser producer = new PreAbilityParser();
final Prerequisite prereq = producer.parse("FEAT", "3,TYPE=Metamagic,TYPE=ItemCreation", false, false);
final PreMult test = new PreMult();
int passes = test.passes(prereq, character, null);
assertEquals("No feats should not pass", 0, passes);
addAbility(AbilityCategory.FEAT, metamagic1);
passes = test.passes(prereq, character, null);
assertEquals("One feat should not pass", 0, passes);
addAbility(AbilityCategory.FEAT, metamagic2);
passes = test.passes(prereq, character, null);
assertEquals("Two feats should not pass", 0, passes);
addAbility(AbilityCategory.FEAT, metamagic3);
passes = test.passes(prereq, character, null);
assertEquals("Three feats should pass", 1, passes);
removeAbility(AbilityCategory.FEAT, metamagic3);
addAbility(AbilityCategory.FEAT, item1);
passes = test.passes(prereq, character, null);
assertEquals("Three feats should pass", 1, passes);
addAbility(AbilityCategory.FEAT, item2);
addAbility(AbilityCategory.FEAT, item3);
addAbility(AbilityCategory.FEAT, metamagic3);
passes = test.passes(prereq, character, null);
assertEquals("Six feats should pass", 1, passes);
removeAbility(AbilityCategory.FEAT, metamagic3);
removeAbility(AbilityCategory.FEAT, item3);
removeAbility(AbilityCategory.FEAT, item2);
removeAbility(AbilityCategory.FEAT, item1);
removeAbility(AbilityCategory.FEAT, metamagic2);
removeAbility(AbilityCategory.FEAT, metamagic1);
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class DataSetTest method testGetPrereqAbilities.
/**
* Verify the getPrereqAbilities method is functioning correctly.
* @throws Exception
*/
public void testGetPrereqAbilities() throws Exception {
Ability acrobatics = TestHelper.makeAbility("Acrobatics", AbilityCategory.FEAT, "general");
Ability dodge = TestHelper.makeAbility("Dodge", AbilityCategory.FEAT, "general");
Ability mobility = TestHelper.makeAbility("Mobility", AbilityCategory.FEAT, "general");
Ability springAttack = TestHelper.makeAbility("Spring Attack", AbilityCategory.FEAT, "general");
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY=FEAT,KEY_Dodge", false, false);
mobility.addPrerequisite(prereq);
prereq = parser.parse("ability", "2,CATEGORY=FEAT,KEY_Dodge,KEY_Mobility", false, false);
springAttack.addPrerequisite(prereq);
DataSet dataset = new DataSet(Globals.getContext(), SettingsHandler.getGame(), new DefaultListFacade<>());
List<AbilityFacade> abilities = dataset.getPrereqAbilities(acrobatics);
assertEquals("Acrobatics prereq should be empty", 0, abilities.size());
abilities = dataset.getPrereqAbilities(dodge);
assertEquals("Dodge prereq should be empty", 0, abilities.size());
abilities = dataset.getPrereqAbilities(mobility);
assertEquals("Mobility prereq should not be empty", 1, abilities.size());
assertEquals("Mobility prereq should be dodge", dodge, abilities.get(0));
abilities = dataset.getPrereqAbilities(springAttack);
assertEquals("Spring Attack prereq should not be empty", 2, abilities.size());
assertEquals("Spring Attack prereq should be dodge", dodge, abilities.get(0));
assertEquals("Spring Attack prereq should be mobility", mobility, abilities.get(1));
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityParserTest method testSingleEntry.
/**
* @throws Exception
*/
@Test
public void testSingleEntry() throws Exception {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,Sneak Attack", false, false);
assertEquals("Category not specified for single key", "<prereq kind=\"ability\" key=\"Sneak Attack\" operator=\"GTEQ\" operand=\"1\" >\n" + "</prereq>\n" + "", prereq.toString());
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityParserTest method testInvalidCharacter.
/**
* Test that an error is produced if separators are incorrect
* @throws Exception
*/
@Test
public void testInvalidCharacter() throws Exception {
try {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,KEY_a|Key_b", false, false);
fail("Should have thrown a PersistenceLayerException.");
} catch (PersistenceLayerException e) {
// Ignore, this is the expected result.
}
}
use of plugin.pretokens.parser.PreAbilityParser in project pcgen by PCGen.
the class PreAbilityParserTest method testInvalidSeparators.
/**
* Test that an error is produced if separators are incorrect
* @throws Exception
*/
@Test
public void testInvalidSeparators() throws Exception {
try {
PreAbilityParser parser = new PreAbilityParser();
Prerequisite prereq = parser.parse("ability", "1,CATEGORY.Mutation,,KEY_a", false, false);
fail("Should have thrown a PersistenceLayerException.");
} catch (PersistenceLayerException e) {
// Ignore, this is the expected result.
}
}
Aggregations