From: <nu...@us...> - 2006-03-30 16:21:26
|
Revision: 528 Author: nuance Date: 2006-03-30 08:21:05 -0800 (Thu, 30 Mar 2006) ViewCVS: http://svn.sourceforge.net/pcgen/?rev=528&view=rev Log Message: ----------- Add some tests for the choiceManagers. Add a test for LevelAbilityClassSkillsTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/chooser/ArmorTypeChoiceManagerTest.java Trunk/pcgen/code/src/test/pcgen/core/chooser/ClassSkillsChoiceManagerTest.java Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityClassSkillsTest.java Added: Trunk/pcgen/code/src/test/pcgen/core/chooser/ArmorTypeChoiceManagerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/chooser/ArmorTypeChoiceManagerTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/chooser/ArmorTypeChoiceManagerTest.java 2006-03-30 16:21:05 UTC (rev 528) @@ -0,0 +1,204 @@ +/* + * ArmorTypeChoiceManagerTest.java + * Copyright 2005 (C) Andrew Wilson <nu...@so...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Oct 7, 2005 + * + * $Author: nuance $ + * $Date: 2006-03-26 08:00:03 +0100 (Sun, 26 Mar 2006) $ + * $Revision: 471 $ + * + */ +package pcgen.core.chooser; + +import pcgen.AbstractCharacterTestCase; +import pcgen.core.AbilityUtilities; +import pcgen.core.PCClass; +import pcgen.core.PObject; +import pcgen.core.PlayerCharacter; +import pcgen.core.EquipmentList; +import pcgen.core.Race; +import pcgen.util.TestHelper; + +import java.lang.Class; +import java.lang.reflect.Field; +import java.util.List; +import java.util.ArrayList; + +/** + * {@code ArmorTypeChoiceManagerTest} test that the ArmorTypeChoiceManager class is functioning correctly. + * + * @author Andrew Wilson <nu...@so...> + */ + +public class ArmorTypeChoiceManagerTest extends AbstractCharacterTestCase { + + PCClass pcClass; + Race emptyRace = new Race(); + boolean firstTime = true; + PlayerCharacter myChar; + + /** + * Constructs a new {@code ArmorTypeChoiceManagerTest}. + */ + public ArmorTypeChoiceManagerTest() + { + // Do Nothing + } + + + protected void setUp() throws Exception + { + super.setUp(); + + if (firstTime) { + firstTime = false; + + + TestHelper.makeAbility("Ability One", "FEAT", "General"); + TestHelper.makeAbility("Armor Proficiency (Light)", "FEAT", "General.Fighter"); + TestHelper.makeAbility("Armor Proficiency (Medium)","FEAT", "General.Fighter"); + TestHelper.makeAbility("Armor Proficiency (Heavy)", "FEAT", "General.Fighter"); + TestHelper.makeAbility("Armor Proficiency (Heavy)", "FOO", "General.Fighter"); + } + + myChar = getCharacter(); + AbilityUtilities.modFeat(myChar, null, "Armor Proficiency (Light)", true, true); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + EquipmentList.clearEquipmentMap(); + } + + /** + * Test the constructor + */ + public void test001() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|ARMORTYPE"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|ARMORTYPE")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("ARMORTYPE"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } + + /** + * Test the choice constructing routine + */ + public void test002() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|ARMORTYPE"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|ARMORTYPE")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("ARMORTYPE"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + + ArrayList avail = new ArrayList(); + ArrayList selected = new ArrayList(); + + choiceManager.getChoices(myChar, avail, selected); + + is (new Integer (avail.size()), eq(1), "Available choices is correct size"); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } + + /** + * Test the choice constructing routine + */ + public void test003() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|ARMORTYPE"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|ARMORTYPE")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("ARMORTYPE"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + + ArrayList avail = new ArrayList(); + ArrayList selected = new ArrayList(); + + choiceManager.getChoices(myChar, avail, selected); + + is (new Integer (avail.size()), eq(1), "Available choices is correct size"); + is (new Integer (selected.size()), eq(0), "Selected choices is correct size"); + + is (avail.get(0), strEq("Light")); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/chooser/ArmorTypeChoiceManagerTest.java ___________________________________________________________________ Name: keywords + "Date Revision Author Id" Name: svn:eol-style + native Added: Trunk/pcgen/code/src/test/pcgen/core/chooser/ClassSkillsChoiceManagerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/chooser/ClassSkillsChoiceManagerTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/chooser/ClassSkillsChoiceManagerTest.java 2006-03-30 16:21:05 UTC (rev 528) @@ -0,0 +1,211 @@ +/* + * ClassSkillsChoiceManagerTest.java + * Copyright 2005 (C) Andrew Wilson <nu...@so...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Oct 7, 2005 + * + * $Author: nuance $ + * $Date: 2006-03-26 08:00:03 +0100 (Sun, 26 Mar 2006) $ + * $Revision: 471 $ + * + */ +package pcgen.core.chooser; + +import pcgen.AbstractCharacterTestCase; +import pcgen.core.PCClass; +import pcgen.core.PObject; +import pcgen.core.PlayerCharacter; +import pcgen.core.EquipmentList; +import pcgen.core.Race; +import pcgen.util.TestHelper; + +import java.lang.Class; +import java.lang.reflect.Field; +import java.util.List; +import java.util.ArrayList; + +/** + * {@code ClassSkillsChoiceManagerTest} test that the ClassSkillsChoiceManager class is functioning correctly. + * + * @author Andrew Wilson <nu...@so...> + */ + +public class ClassSkillsChoiceManagerTest extends AbstractCharacterTestCase { + + PCClass pcClass; + Race emptyRace = new Race(); + boolean firstTime = true; + PlayerCharacter myChar; + + /** + * Constructs a new {@code ClassSkillsChoiceManagerTest}. + */ + public ClassSkillsChoiceManagerTest() + { + // Do Nothing + } + + protected void setUp() throws Exception { + super.setUp(); + + if (firstTime) { + firstTime = false; + + TestHelper.makeSkill("Bluff", "Charisma", "CHA", "YES", "NO"); + TestHelper.makeSkill("Listen", "Wisdom", "WIS", "YES", "NO"); + TestHelper.makeSkill("Move Silently", "Dexterity", "DEX", "YES", "YES"); + TestHelper.makeSkill("Knowledge (Arcana)", "Intelligence.Knowledge", "INT", "NO", "NO"); + TestHelper.makeSkill("Knowledge (Dungeoneering)", "Intelligence.Knowledge", "INT", "NO", "NO"); + + pcClass = new PCClass(); + pcClass.addCSkill("Bluff"); + pcClass.addCSkill("Listen"); + pcClass.addCSkill("TYPE.Knowledge"); + pcClass.addCcSkill("Move Silently"); + + } + + myChar = getCharacter(); + myChar.incrementClassLevel(1, pcClass); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + EquipmentList.clearEquipmentMap(); + } + + /** + * Test the constructor + */ + public void test001() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|CSKILLS"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|CSKILLS")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("CSKILLS"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } + + /** + * Test the choice constructing routine + */ + public void test002() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|CSKILLS"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|CSKILLS")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("CSKILLS"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + + ArrayList avail = new ArrayList(); + ArrayList selected = new ArrayList(); + + choiceManager.getChoices(myChar, avail, selected); + + is (new Integer (avail.size()), eq(4), "Available choices is correct size"); + is (new Integer (selected.size()), eq(0), "Selected choices is correct size"); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } + + /** + * Test the choice constructing routine + */ + public void test003() + { + PObject pObj = new PObject(); + pObj.setName("My PObject"); + pObj.setChoiceString("NUMCHOICES=2|CSKILLS"); + is(pObj.getChoiceString(), strEq("NUMCHOICES=2|CSKILLS")); + + PlayerCharacter aPC = getCharacter(); + + ChoiceManagerList choiceManager = ChooserUtilities.getChoiceManager(pObj, null, aPC); + is(choiceManager, not(eq(null)), "Found the chooser"); + + is(choiceManager.typeHandled(), strEq("CSKILLS"), "got expected chooser"); + + try + { + Class cMClass = choiceManager.getClass(); + + Field aField = (Field) TestHelper.findField(cMClass, "numberOfChoices"); + is (aField.get(choiceManager), eq(2)); + + aField = (Field) TestHelper.findField(cMClass, "choices"); + List choices = (List) aField.get(choiceManager); + is (new Integer (choices.size()), eq(0)); + + ArrayList avail = new ArrayList(); + ArrayList selected = new ArrayList(); + + choiceManager.getChoices(myChar, avail, selected); + + is (new Integer (avail.size()), eq(4), "Available choices is correct size"); + is (new Integer (selected.size()), eq(0), "Selected choices is correct size"); + + is (avail.get(0), strEq("Bluff")); + is (avail.get(1), strEq("Listen")); + is (avail.get(2), strEq("Knowledge (Arcana)")); + is (avail.get(3), strEq("Knowledge (Dungeoneering)")); + } + catch (IllegalAccessException e) { + System.out.println(e); + } + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/chooser/ClassSkillsChoiceManagerTest.java ___________________________________________________________________ Name: keywords + "Date Revision Author Id" Name: svn:eol-style + native Added: Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityClassSkillsTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityClassSkillsTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityClassSkillsTest.java 2006-03-30 16:21:05 UTC (rev 528) @@ -0,0 +1,189 @@ +/* + * LevelAbility.java + * Copyright 2006 (C) Andrew Wilson <nu...@so...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * $$Revision$$ + * $$Date$$ + * $$Time$$ + * + * $$id$$ + */ +package pcgen.core.levelability; + +import java.awt.HeadlessException; +import java.util.ArrayList; + +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Globals; +import pcgen.core.PCClass; +import pcgen.core.PlayerCharacter; +import pcgen.core.Race; +import pcgen.core.Skill; +import pcgen.gui.utils.SwingChooser; +import pcgen.util.Logging; +import pcgen.util.TestHelper; +import pcgen.util.chooser.ChooserFactory; +import pcgen.util.chooser.ChooserInterface; + +public class LevelAbilityClassSkillsTest extends AbstractCharacterTestCase { + + PCClass pcClass; + Race emptyRace = new Race(); + boolean firstTime = true; + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + + if (firstTime) { + firstTime = false; + + pcClass = new PCClass(); + + TestHelper.makeSkill("Bluff", "Charisma", "CHA", "YES", "NO"); + TestHelper.makeSkill("Listen", "Wisdom", "WIS", "YES", "NO"); + TestHelper.makeSkill("Move Silently", "Dexterity", "DEX", "YES", "YES"); + TestHelper.makeSkill("Knowledge (Arcana)", "Intelligence.Knowledge", "INT", "NO", "NO"); + TestHelper.makeSkill("Knowledge (Dungeoneering)", "Intelligence.Knowledge", "INT", "NO", "NO"); + } + + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(1, pcClass); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + pcClass = null; + super.tearDown(); + } + + /* + * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)' + */ + public void testGetChoicesList1() { + ChooserFactory.setInterfaceClassname(SwingChooser.class.getName()); + + final LevelAbility ability = LevelAbility.createAbility(pcClass, 1, "CLASSSKILLS(Bluff,Listen,Move Silently)2"); + is (new Integer(ability.level()), eq(1), "Is level correct"); + is (new Boolean(ability.canProcess()), eq(true), "Can we process this LevelAbility"); + + + try + { + final ChooserInterface c = ChooserFactory.getChooserInstance(); + ability.setType(getCharacter()); + final String bString = ability.prepareChooser(c, getCharacter()); + is (new Integer(c.getPool()), eq(2), "Ar two choices being offered"); + + final ArrayList choicesList = (ArrayList) ability.getChoicesList(bString, getCharacter()); + is (new Integer(choicesList.size()), eq(3), "Ar there three choices available"); + + String s = (String) choicesList.get(0); + is(s, strEq("Bluff"), "Is First choice correct"); + s = (String) choicesList.get(1); + is(s, strEq("Listen"), "Is Second Choice"); + s = (String) choicesList.get(2); + is(s, strEq("Move Silently"), "Is Third Choice"); + } + catch(HeadlessException e) + { + Logging.debugPrint("Ignoring Headless excpetion."); + } + } + + /* + * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)' + */ + public void testGetChoicesList2() { + ChooserFactory.setInterfaceClassname(SwingChooser.class.getName()); + + final LevelAbility ability = LevelAbility.createAbility(pcClass, 1, "CLASSSKILLS(Bluff,Listen,Knowledge (Arcana))2"); + is (new Integer(ability.level()), eq(1), "Is level correct"); + is (new Boolean(ability.canProcess()), eq(true), "Can we process this LevelAbility"); + + Skill mySkill = new Skill(); + mySkill.setName(""); + Globals.getSkillList().add(mySkill); + + + + try + { + final ChooserInterface c = ChooserFactory.getChooserInstance(); + ability.setType(getCharacter()); + final String bString = ability.prepareChooser(c, getCharacter()); + is (new Integer(c.getPool()), eq(2), "Ar two choices being offered"); + + final ArrayList choicesList = (ArrayList) ability.getChoicesList(bString, getCharacter()); + is (new Integer(choicesList.size()), eq(3), "Ar there three choices available"); + + String s = (String) choicesList.get(0); + is(s, strEq("Bluff"), "Is First choice correct"); + s = (String) choicesList.get(1); + is(s, strEq("Listen"), "Is Second Choice"); + s = (String) choicesList.get(2); + is(s, strEq("Knowledge (Arcana)"), "Is Third Choice"); + } + catch(HeadlessException e) + { + Logging.debugPrint("Ignoring Headless excpetion."); + } + } + /* + * Test method for 'pcgen.core.levelability.LevelAbilityClassSkills.getChoicesList(String, PlayerCharacter)' + */ + public void testGetChoicesList3() { + ChooserFactory.setInterfaceClassname(SwingChooser.class.getName()); + + final LevelAbility ability = LevelAbility.createAbility(pcClass, 1, "CLASSSKILLS(Bluff,Listen,Knowledge (Arcana),Knowledge (Dungeoneering))2"); + is (new Integer(ability.level()), eq(1), "Is level correct"); + is (new Boolean(ability.canProcess()), eq(true), "Can we process this LevelAbility"); + + Skill mySkill = new Skill(); + mySkill.setName(""); + Globals.getSkillList().add(mySkill); + + + + try + { + final ChooserInterface c = ChooserFactory.getChooserInstance(); + ability.setType(getCharacter()); + final String bString = ability.prepareChooser(c, getCharacter()); + is (new Integer(c.getPool()), eq(2), "Ar two choices being offered"); + + final ArrayList choicesList = (ArrayList) ability.getChoicesList(bString, getCharacter()); + is (new Integer(choicesList.size()), eq(4), "Are there four choices available"); + + String s = (String) choicesList.get(0); + is(s, strEq("Bluff"), "Is First choice correct"); + s = (String) choicesList.get(1); + is(s, strEq("Listen"), "Is Second Choice"); + s = (String) choicesList.get(2); + is(s, strEq("Knowledge (Arcana)"), "Is Third Choice"); + s = (String) choicesList.get(3); + is(s, strEq("Knowledge (Dungeoneering)"), "Is Fourth Choice"); + } + catch(HeadlessException e) + { + Logging.debugPrint("Ignoring Headless excpetion."); + } + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityClassSkillsTest.java ___________________________________________________________________ Name: keywords + "Date Revision Author Id" Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |