changeset 116:49fb69ea13f2

Re #27: Unit requirements * Switch to enumeration and update tests as appropriate
author IBBoard <dev@ibboard.co.uk>
date Mon, 04 Apr 2011 19:05:47 +0000
parents bcca07bee8ea
children a52cce66eb07
files API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/ValidationTests.cs
diffstat 3 files changed, 30 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun Apr 03 19:40:06 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Mon Apr 04 19:05:47 2011 +0000
     1.3 @@ -34,7 +34,7 @@
     1.4  			Army army = new Army(mockRace, "Test", 1000);
     1.5  			Unit unit = CreateUnitOfType(unitType1, army);
     1.6  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
     1.7 -			Assert.That(req.AllowsAdding(unit, army), Is.False);
     1.8 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
     1.9  		}
    1.10  
    1.11  		[Test()]
    1.12 @@ -44,7 +44,7 @@
    1.13  			AddUnitOfTypeToArmy(unitType2, army);
    1.14  			Unit unit = CreateUnitOfType(unitType1, army);
    1.15  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.16 -			Assert.That(req.AllowsAdding(unit, army), Is.True);
    1.17 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.18  		}
    1.19  
    1.20  		[Test()]
    1.21 @@ -52,7 +52,7 @@
    1.22  		{
    1.23  			Army army = new Army(mockRace, "Test", 1000);
    1.24  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.25 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.26 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.27  		}
    1.28  
    1.29  		[Test()]
    1.30 @@ -61,7 +61,7 @@
    1.31  			Army army = new Army(mockRace, "Test", 1000);
    1.32  			AddUnitOfTypeToArmy(unitType2, army);
    1.33  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.34 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.35 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.36  		}
    1.37  
    1.38  		[Test()]
    1.39 @@ -69,7 +69,7 @@
    1.40  		{
    1.41  			Army army = new Army(mockRace, "Test", 1000);
    1.42  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.43 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.44 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.45  		}
    1.46  
    1.47  		[Test()]
    1.48 @@ -78,7 +78,7 @@
    1.49  			Army army = new Army(mockRace, "Test", 1000);
    1.50  			AddUnitOfTypeToArmy(unitType2, army);
    1.51  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.52 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.53 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.54  		}
    1.55  
    1.56  		[Test()]
    1.57 @@ -88,7 +88,7 @@
    1.58  			AddUnitOfTypeToArmy(unitType2, army);
    1.59  			AddUnitOfTypeToArmy(unitType3, army);
    1.60  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.61 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.62 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.63  		}
    1.64  
    1.65  		[Test()]
    1.66 @@ -98,7 +98,7 @@
    1.67  			AddUnitOfTypeToArmy(unitType2, army);
    1.68  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    1.69  			req.AddUnitTypeRequirement(unitType2, 2);
    1.70 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.71 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    1.72  		}
    1.73  
    1.74  		[Test()]
    1.75 @@ -109,7 +109,7 @@
    1.76  			AddUnitOfTypeToArmy(unitType2, army);
    1.77  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    1.78  			req.AddUnitTypeRequirement(unitType2, 2);
    1.79 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.80 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.81  		}
    1.82  
    1.83  		[Test()]
    1.84 @@ -119,7 +119,7 @@
    1.85  			AddUnitOfTypeToArmy(unitType2, army);
    1.86  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
    1.87  			req.AddUnitTypeRequirement(unitType2);
    1.88 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.89 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    1.90  		}
    1.91  
    1.92  		[Test()]
    1.93 @@ -127,7 +127,7 @@
    1.94  		{
    1.95  			Army army = new Army(mockRace, "Test", 1000);
    1.96  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.97 -			Assert.That(req.ValidatesArmy(army), Is.False);
    1.98 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.99  		}
   1.100  
   1.101  		[Test()]
   1.102 @@ -136,7 +136,7 @@
   1.103  			Army army = new Army(mockRace, "Test", 1000);
   1.104  			AddUnitOfTypeToArmy(unitType2, army);
   1.105  			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
   1.106 -			Assert.That(req.ValidatesArmy(army), Is.True);
   1.107 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
   1.108  		}
   1.109  
   1.110  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
     2.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Apr 03 19:40:06 2011 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Mon Apr 04 19:05:47 2011 +0000
     2.3 @@ -35,7 +35,7 @@
     2.4  			Unit unit = CreateUnitOfType(unitType1, army);
     2.5  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
     2.6  			req.AddUnitTypeRequirement(unitType2);
     2.7 -			Assert.That(req.AllowsAdding(unit, army), Is.False);
     2.8 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
     2.9  		}
    2.10  
    2.11  		[Test()]
    2.12 @@ -46,7 +46,7 @@
    2.13  			Unit unit = CreateUnitOfType(unitType1, army);
    2.14  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.15  			req.AddUnitTypeRequirement(unitType2);
    2.16 -			Assert.That(req.AllowsAdding(unit, army), Is.True);
    2.17 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    2.18  		}
    2.19  
    2.20  		[Test()]
    2.21 @@ -55,7 +55,7 @@
    2.22  			Army army = new Army(mockRace, "Test", 1000);
    2.23  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.24  			req.AddUnitTypeRequirement(unitType2);
    2.25 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.26 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    2.27  		}
    2.28  
    2.29  		[Test()]
    2.30 @@ -65,7 +65,7 @@
    2.31  			AddUnitOfTypeToArmy(unitType2, army);
    2.32  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.33  			req.AddUnitTypeRequirement(unitType2);
    2.34 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.35 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.36  		}
    2.37  
    2.38  		[Test()]
    2.39 @@ -75,7 +75,7 @@
    2.40  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.41  			req.AddUnitTypeRequirement(unitType2);
    2.42  			req.AddUnitTypeRequirement(unitType3);
    2.43 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.44 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    2.45  		}
    2.46  
    2.47  		[Test()]
    2.48 @@ -86,7 +86,7 @@
    2.49  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.50  			req.AddUnitTypeRequirement(unitType2);
    2.51  			req.AddUnitTypeRequirement(unitType3);
    2.52 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.53 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    2.54  		}
    2.55  
    2.56  		[Test()]
    2.57 @@ -98,7 +98,7 @@
    2.58  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.59  			req.AddUnitTypeRequirement(unitType2);
    2.60  			req.AddUnitTypeRequirement(unitType3);
    2.61 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.62 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.63  		}
    2.64  
    2.65  		[Test()]
    2.66 @@ -108,7 +108,7 @@
    2.67  			AddUnitOfTypeToArmy(unitType2, army);
    2.68  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.69  			req.AddUnitTypeRequirement(unitType2, 2);
    2.70 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.71 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
    2.72  		}
    2.73  
    2.74  		[Test()]
    2.75 @@ -118,7 +118,7 @@
    2.76  			AddUnitOfTypeToArmy(unitType2, army);
    2.77  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.78  			req.AddUnitTypeRequirement(unitType2, 2);
    2.79 -			Assert.That(req.AllowsAdding(unitType3, army), Is.True);
    2.80 +			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
    2.81  		}
    2.82  
    2.83  		[Test()]
    2.84 @@ -129,7 +129,7 @@
    2.85  			AddUnitOfTypeToArmy(unitType2, army);
    2.86  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.87  			req.AddUnitTypeRequirement(unitType2, 2);
    2.88 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.89 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.90  		}
    2.91  
    2.92  		[Test()]
    2.93 @@ -139,7 +139,7 @@
    2.94  			AddUnitOfTypeToArmy(unitType2, army);
    2.95  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    2.96  			req.AddUnitTypeRequirement(unitType2);
    2.97 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.98 +			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
    2.99  		}
   2.100  
   2.101  		[Test()]
   2.102 @@ -149,7 +149,7 @@
   2.103  			AddUnitOfTypeToArmy(unitType1, army);
   2.104  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   2.105  			req.AddUnitTypeRequirement(unitType2);
   2.106 -			Assert.That(req.ValidatesArmy(army), Is.False);
   2.107 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
   2.108  		}
   2.109  
   2.110  		[Test()]
   2.111 @@ -160,7 +160,7 @@
   2.112  			AddUnitOfTypeToArmy(unitType1, army);
   2.113  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   2.114  			req.AddUnitTypeRequirement(unitType2);
   2.115 -			Assert.That(req.ValidatesArmy(army), Is.True);
   2.116 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
   2.117  		}
   2.118  
   2.119  		[Test()]
   2.120 @@ -170,13 +170,16 @@
   2.121  			AddUnitOfTypeToArmy(unitType2, army);
   2.122  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   2.123  			req.AddUnitTypeRequirement(unitType2, 2);
   2.124 -			Assert.That(req.ValidatesArmy(army), Is.True);
   2.125 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
   2.126  		}
   2.127  
   2.128 +
   2.129  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   2.130  		{
   2.131  			army.AddUnit(CreateUnitOfType(unitType, army));
   2.132  		}
   2.133 +
   2.134 +
   2.135  		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   2.136  		{
   2.137  			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
     3.1 --- a/API/Objects/Requirement/ValidationTests.cs	Sun Apr 03 19:40:06 2011 +0000
     3.2 +++ b/API/Objects/Requirement/ValidationTests.cs	Mon Apr 04 19:05:47 2011 +0000
     3.3 @@ -43,7 +43,7 @@
     3.4  			Assert.That(Validates.AsOkay(Validation.Failed), Is.False);
     3.5  		}
     3.6  
     3.7 -		public void TestValidatesAsNotOkaySuccedesForPassedAndNA()
     3.8 +		public void TestValidatesAsNotOkaySuccedesForFailedAndNA()
     3.9  		{
    3.10  			Assert.That(Validates.AsNotOkay(Validation.Failed), Is.True);
    3.11  			Assert.That(Validates.AsNotOkay(Validation.NotApplicable), Is.True);