Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs @ 239:370bec16a364 default tip
Add initial testing for equipment with type (incomplete)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 16 Oct 2016 20:29:35 +0100 |
parents | e173c5512067 |
children |
line wrap: on
line source
// This file (UnitRequiresAtLeastNUnitsRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard // // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. using System; using NUnit.Framework; using IBBoard.WarFoundry.API.Objects.Mock; namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresAtLeastNUnitsRequirement> { [Test()] public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0)."); } [Test()] public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__PassesAdding(req, unitType1, army); } [Test()] public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired() { //Rollcall's "-1,X,-1,Y" requirement - unlimited once you have one of both Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0); 1 × " + unitType3.Name + " (would have 0)."); } [Test()] public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() { //Rollcall's "-1,X,-1,Y" requirement - unlimited once you have one of both Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType3.Name + " (would have 0)."); } [Test()] public void TestAddingUnitTypeWithOtherOneUnitAndTwoUnitTypesRequired() { //Rollcall's "-1,X,-1,Y" requirement - unlimited once you have one of both Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0)."); } [Test()] public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired() { //Rollcall's "-1,X,-1,Y" requirement - unlimited once you have one of both Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__PassesAdding(req, unitType1, army); } [Test()] public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " (would have 1)."); } [Test()] public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicable() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__AddingNotApplicable(req, unitType3, army); } [Test()] public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicableWhenRequirementsNotMet() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__AddingNotApplicable(req, unitType3, army); } [Test()] public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__PassesAdding(req, unitType1, army); } [Test()] public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__PassesAdding(req, unitType1, army); } [Test()] public void TestAddingUnitTypeMakesRequirementPass() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " (would have 1)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__PassesAdding(req, unitType1, army); } [Test] public void TestAddingRequirementWithOR() { //Rollcall's "-1,X|Y" requirement - unlimited for one of either Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " (would have 0)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__PassesAdding(req, unitType1, army); } [Test] public void TestAddingRequirementWithORWithOtherUnit() { //Rollcall's "-1,X|Y" requirement - unlimited for one of either Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " (would have 0)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__PassesAdding(req, unitType1, army); } [Test] public void TestAddingRequirementWithORWithLimit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(2, unitType2, unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (would have 0)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (would have 1)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__PassesAdding(req, unitType1, army); } [Test] public void TestAddingRequirementWithORWithLimitWithOtherUnit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(2, unitType2, unitType3); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (would have 0)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (would have 1)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__PassesAdding(req, unitType1, army); } [Test()] public void TestValidatingWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0)."); } [Test()] public void TestValidatingWithOneUnitAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__ValidationPasses(req, army); } [Test()] public void TestValidatingWithNoUnitsAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0)."); } [Test()] public void TestValidatingWithOneUnitAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " (have 0)."); } [Test()] public void TestValidatingWithOtherOneUnitAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0)."); } [Test()] public void TestValidatingWithBothUnitsAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); req.AddUnitTypeRequirement(unitType3); Assert_That__ValidationPasses(req, army); } [Test()] public void TestValidatingWithOneUnitAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1)."); } [Test()] public void TestValidatingWithUnrelatedUnitTypeValidatesAsNotApplicable() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType3, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__NotApplicable(req, army); } [Test()] public void TestValidatingWithTwoUnitsAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__ValidationPasses(req, army); } [Test()] public void TestValidatingRequirementWithNoNumberDefaultsToHavingOne() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert_That__ValidationPasses(req, army); } [Test()] public void TestAddingUnitTypeMakesRequirementPassValidating() { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType1, army); AddUnitOfTypeToArmy(unitType2, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, 2); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationPasses(req, army); } [Test] public void TestRequirementWithOR() { //Rollcall's "-1,X|Y" requirement - unlimited for one of either Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " (have 0)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationPasses(req, army); } [Test] public void TestRequirementWithORWithOtherUnit() { //Rollcall's "-1,X|Y" requirement - unlimited for one of either Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2, unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " (have 0)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__ValidationPasses(req, army); } [Test] public void TestRequirementWithORWithLimit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(2, unitType2, unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (have 0)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (have 1)."); AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationPasses(req, army); } [Test] public void TestRequirementWithORWithLimitWithOtherUnit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(2, unitType2, unitType3); AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (have 0)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " (have 1)."); AddUnitOfTypeToArmy(unitType3, army); Assert_That__ValidationPasses(req, army); } protected override UnitRequiresAtLeastNUnitsRequirement CreateRequirement(UnitType requirementOn) { return new UnitRequiresAtLeastNUnitsRequirement(requirementOn); } } }