changeset 130:7fa4d5215afe

Re #27: Unit requirements * Initial rebuild of tests so that we check for "N/A" in more of the appropriate cases for adding units
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 19:54:10 +0000
parents 95dac00e9330
children 5ede1c0a1454
files API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs
diffstat 1 files changed, 44 insertions(+), 29 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sat Apr 09 19:13:42 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sat Apr 09 19:54:10 2011 +0000
     1.3 @@ -29,38 +29,56 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 -		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
     1.8 +		public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequired()
     1.9  		{
    1.10  			Army army = new Army(mockRace, "Test", 1000);
    1.11  			Unit unit = CreateUnitOfType(unitType1, army);
    1.12  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.13 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.14 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    1.15  		}
    1.16  
    1.17  		[Test()]
    1.18 -		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
    1.19 +		public void TestAddingOneUnitWithOneUnitTypeRequired()
    1.20  		{
    1.21  			Army army = new Army(mockRace, "Test", 1000);
    1.22 -			AddUnitOfTypeToArmy(unitType2, army);
    1.23  			Unit unit = CreateUnitOfType(unitType1, army);
    1.24 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    1.25 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.26 +		}
    1.27 +
    1.28 +		[Test()]
    1.29 +		public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired()
    1.30 +		{
    1.31 +			Army army = new Army(mockRace, "Test", 1000);
    1.32 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    1.33 +			req.AddUnitTypeRequirement(unitType1, 2);
    1.34 +			AddUnitOfTypeToArmy(unitType1, army);
    1.35 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.36 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.37 +		}
    1.38 +
    1.39 +		[Test()]
    1.40 +		public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired()
    1.41 +		{
    1.42 +			Army army = new Army(mockRace, "Test", 1000);
    1.43  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.44 -			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.45 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable));
    1.46  		}
    1.47  
    1.48  		[Test()]
    1.49  		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
    1.50  		{
    1.51  			Army army = new Army(mockRace, "Test", 1000);
    1.52 -			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.53 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.54 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    1.55 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.56  		}
    1.57  
    1.58  		[Test()]
    1.59  		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
    1.60  		{
    1.61  			Army army = new Army(mockRace, "Test", 1000);
    1.62 -			AddUnitOfTypeToArmy(unitType2, army);
    1.63 -			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.64 +			AddUnitOfTypeToArmy(unitType1, army);
    1.65 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
    1.66  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.67  		}
    1.68  
    1.69 @@ -69,16 +87,16 @@
    1.70  		{
    1.71  			Army army = new Army(mockRace, "Test", 1000);
    1.72  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.73 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.74 +			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
    1.75  		}
    1.76  
    1.77  		[Test()]
    1.78  		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
    1.79  		{
    1.80  			Army army = new Army(mockRace, "Test", 1000);
    1.81 -			AddUnitOfTypeToArmy(unitType2, army);
    1.82 +			AddUnitOfTypeToArmy(unitType3, army);
    1.83  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.84 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.85 +			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
    1.86  		}
    1.87  
    1.88  		[Test()]
    1.89 @@ -88,27 +106,25 @@
    1.90  			AddUnitOfTypeToArmy(unitType2, army);
    1.91  			AddUnitOfTypeToArmy(unitType3, army);
    1.92  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.93 -			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.94 +			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
    1.95  		}
    1.96  
    1.97  		[Test()]
    1.98 -		public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
    1.99 +		public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired()
   1.100  		{
   1.101  			Army army = new Army(mockRace, "Test", 1000);
   1.102 -			AddUnitOfTypeToArmy(unitType2, army);
   1.103  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   1.104 -			req.AddUnitTypeRequirement(unitType2, 2);
   1.105 +			req.AddUnitTypeRequirement(unitType1, 2);
   1.106  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
   1.107  		}
   1.108  
   1.109  		[Test()]
   1.110 -		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
   1.111 +		public void TestAddingOneUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
   1.112  		{
   1.113  			Army army = new Army(mockRace, "Test", 1000);
   1.114 -			AddUnitOfTypeToArmy(unitType2, army);
   1.115 -			AddUnitOfTypeToArmy(unitType2, army);
   1.116 +			AddUnitOfTypeToArmy(unitType1, army);
   1.117  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   1.118 -			req.AddUnitTypeRequirement(unitType2, 2);
   1.119 +			req.AddUnitTypeRequirement(unitType1, 2);
   1.120  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
   1.121  		}
   1.122  
   1.123 @@ -116,9 +132,8 @@
   1.124  		public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne()
   1.125  		{
   1.126  			Army army = new Army(mockRace, "Test", 1000);
   1.127 -			AddUnitOfTypeToArmy(unitType2, army);
   1.128  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   1.129 -			req.AddUnitTypeRequirement(unitType2);
   1.130 +			req.AddUnitTypeRequirement(unitType1);
   1.131  			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
   1.132  		}
   1.133  
   1.134 @@ -126,7 +141,7 @@
   1.135  		public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired()
   1.136  		{
   1.137  			Army army = new Army(mockRace, "Test", 1000);
   1.138 -			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
   1.139 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
   1.140  			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
   1.141  		}
   1.142  
   1.143 @@ -134,8 +149,8 @@
   1.144  		public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired()
   1.145  		{
   1.146  			Army army = new Army(mockRace, "Test", 1000);
   1.147 -			AddUnitOfTypeToArmy(unitType2, army);
   1.148 -			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
   1.149 +			AddUnitOfTypeToArmy(unitType1, army);
   1.150 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1);
   1.151  			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
   1.152  		}
   1.153  
   1.154 @@ -144,10 +159,10 @@
   1.155  		{
   1.156  			Army army = new Army(mockRace, "Test", 1000);
   1.157  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   1.158 -			req.AddUnitTypeRequirement(unitType2, 2);
   1.159 -			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
   1.160 -			AddUnitOfTypeToArmy(unitType2, army);
   1.161 -			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
   1.162 +			req.AddUnitTypeRequirement(unitType1, 2);
   1.163 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
   1.164 +			AddUnitOfTypeToArmy(unitType1, army);
   1.165 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
   1.166  		}
   1.167  
   1.168  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)