changeset 7:a2cbd7cb6a5e

Re #24: Create limit objects * Extract out common tests * Make old tests use new abstract * Add tests for new class
author IBBoard <dev@ibboard.co.uk>
date Tue, 20 Oct 2009 19:49:44 +0000
parents 9a860452ced0
children 43e282ec574c
files Limits/AbsoluteNumericLimitTest.cs Limits/AbstractLimitTest.cs Limits/NumericSizeConstrainedLimitTest.cs Limits/SimpleRoundedPercentageLimitTest.cs
diffstat 4 files changed, 143 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Limits/AbsoluteNumericLimitTest.cs	Tue Oct 20 19:49:44 2009 +0000
@@ -0,0 +1,45 @@
+// This file (AbsoluteNumericLimitTest.cs) is a part of the IBBoard.Tests project and is copyright 2009 IBBoard
+// 
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+using NUnit.Framework;
+
+namespace IBBoard.Limits
+{
+	[TestFixture()]
+	public class AbsoluteNumericLimitTest : AbstractLimitTest
+	{
+		private const int LIMIT = 10;
+
+		public override AbstractLimit GetDefaultLimitObject ()
+		{
+			return new AbsoluteNumericLimit(LIMIT);
+		}
+		
+		public override double GetSize100ExpectedValue ()
+		{
+			return LIMIT;
+		}
+		
+		public override double GetSize10ExpectedValue ()
+		{
+			return LIMIT;
+		}
+		
+		public override double GetSize1ExpectedValue ()
+		{
+			return LIMIT;
+		}
+		
+		public override AbstractLimit GetEqualLimitObject ()
+		{
+			return new AbsoluteNumericLimit(LIMIT);
+		}
+		
+		public override AbstractLimit GetUnequalLimitObject ()
+		{
+			return new AbsoluteNumericLimit(100);
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Limits/AbstractLimitTest.cs	Tue Oct 20 19:49:44 2009 +0000
@@ -0,0 +1,37 @@
+// This file (AbstractLimitTest.cs) is a part of the IBBoard.Tests project and is copyright 2009 IBBoard
+// 
+//  The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
+
+using System;
+using NUnit.Framework;
+
+namespace IBBoard.Limits
+{
+	[TestFixture()]
+	public abstract class AbstractLimitTest
+	{
+		[Test()]
+		public void TestDefaultValues()
+		{			
+			AbstractLimit limit = GetDefaultLimitObject();
+			Assert.AreEqual(GetSize100ExpectedValue(), limit.GetLimit(100));
+			Assert.AreEqual(GetSize10ExpectedValue(), limit.GetLimit(10));
+			Assert.AreEqual(GetSize1ExpectedValue(), limit.GetLimit(1));
+		}
+		
+		[Test()]
+		public void TestEquality()
+		{
+			Assert.AreEqual(GetDefaultLimitObject(), GetEqualLimitObject());
+			Assert.AreNotEqual(GetDefaultLimitObject(), GetUnequalLimitObject());
+			//TODO: Use reflection to get other "GetUnequal" objects and test them
+		}
+		
+		public abstract AbstractLimit GetDefaultLimitObject();
+		public abstract double GetSize100ExpectedValue();
+		public abstract double GetSize10ExpectedValue();
+		public abstract double GetSize1ExpectedValue();
+		public abstract AbstractLimit GetEqualLimitObject();
+		public abstract AbstractLimit GetUnequalLimitObject();
+	}
+}
--- a/Limits/NumericSizeConstrainedLimitTest.cs	Wed Oct 07 18:40:54 2009 +0000
+++ b/Limits/NumericSizeConstrainedLimitTest.cs	Tue Oct 20 19:49:44 2009 +0000
@@ -8,15 +8,36 @@
 namespace IBBoard.Limits
 {
 	[TestFixture()]
-	public class NumericSizeConstrainedLimitTest
-	{
-		[Test()]
-		public void TestSizeConstrainedLimits()
+	public class NumericSizeConstrainedLimitTest : AbstractLimitTest
+	{		
+		public override AbstractLimit GetDefaultLimitObject ()
+		{
+			return new NumericSizeConstrainedLimit(10);
+		}
+		
+		public override double GetSize100ExpectedValue ()
+		{
+			return 10;
+		}
+		
+		public override double GetSize10ExpectedValue ()
 		{
-			NumericSizeConstrainedLimit limit = new NumericSizeConstrainedLimit(10);
-			Assert.AreEqual(10, limit.GetLimit(100));
-			Assert.AreEqual(10, limit.GetLimit(10));
-			Assert.AreEqual(1, limit.GetLimit(1));
+			return 10;
+		}
+
+		public override double GetSize1ExpectedValue ()
+		{
+			return 1;
+		}
+		
+		public override AbstractLimit GetEqualLimitObject ()
+		{
+			return new NumericSizeConstrainedLimit(10);
+		}
+		
+		public override AbstractLimit GetUnequalLimitObject ()
+		{
+			return new NumericSizeConstrainedLimit(100);
 		}
 	}
 }
--- a/Limits/SimpleRoundedPercentageLimitTest.cs	Wed Oct 07 18:40:54 2009 +0000
+++ b/Limits/SimpleRoundedPercentageLimitTest.cs	Tue Oct 20 19:49:44 2009 +0000
@@ -8,17 +8,8 @@
 namespace IBBoard.Limits
 {
 	[TestFixture()]
-	public class SimpleRoundedPercentageLimitTest
-	{
-		[Test()]
-		public void TestSimpleRoundingUpLimit ()
-		{
-			SimpleRoundedPercentageLimit limit = new SimpleRoundedPercentageLimit(10, true);
-			Assert.AreEqual(10, limit.GetLimit(100));
-			Assert.AreEqual(1, limit.GetLimit(10));
-			Assert.AreEqual(1, limit.GetLimit(1));
-		}
-		
+	public class SimpleRoundedPercentageLimitTest : AbstractLimitTest
+	{		
 		[Test()]
 		public void TestSimpleRoundingDownLimit ()
 		{
@@ -27,5 +18,35 @@
 			Assert.AreEqual(1, limit.GetLimit(10));
 			Assert.AreEqual(0, limit.GetLimit(1));
 		}
+		
+		public override AbstractLimit GetDefaultLimitObject ()
+		{
+			return new SimpleRoundedPercentageLimit(10, true);
+		}
+
+		public override double GetSize100ExpectedValue ()
+		{
+			return 10;
+		}
+		
+		public override double GetSize10ExpectedValue ()
+		{
+			return 1;
+		}
+		
+		public override double GetSize1ExpectedValue ()
+		{
+			return 1;
+		}
+		
+		public override AbstractLimit GetEqualLimitObject ()
+		{
+			return new SimpleRoundedPercentageLimit(10, true);
+		}
+		
+		public override AbstractLimit GetUnequalLimitObject ()
+		{
+			return new SimpleRoundedPercentageLimit(100, true);
+		}
 	}
 }