changeset 1:80c42a1101a8

Closes #19 - Add rounding to half methods * Add tests for Floor method that rounds down to a half * Add tests for Ceiling method that rounds up to a half
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 May 2009 19:25:01 +0000
parents 7bd668aeba3c
children 83d1e27d792d
files Lang/IBBMathTests.cs
diffstat 1 files changed, 161 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Lang/IBBMathTests.cs	Sun May 17 16:09:38 2009 +0000
+++ b/Lang/IBBMathTests.cs	Sun May 17 19:25:01 2009 +0000
@@ -10,7 +10,7 @@
 {
 	[TestFixture()]	
 	public class IBBMathTest
-	{		
+	{
 		[Test()]
 		public void TestRoundHalfPerformsBankersRoundingBelowLowMidpoint()
 		{
@@ -72,7 +72,7 @@
 		}
 		
 		[Test()]
-		public void TestRoundHalfDoesntRoundHalf()
+		public void TestRoundHalfDoesntAlterHalf()
 		{
 			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.5));
 		}
@@ -88,5 +88,164 @@
 		{
 			Assert.AreEqual(3, IBBMath.RoundToHalf(3));
 		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpBelowLowMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.2));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpJustBelowLowMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.24));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpOnLowMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.25));
+		}
+
+		[Test()]
+		public void TestRoundHalfRoundsUpJustAboveLowMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.26));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpAboveLowMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.3));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpBelowHighMidpoint()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(3.7));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpJustBelowHighMidpoint()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(3.74));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpOnHighMidpoint()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(3.75));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpJustAboveHighMidpoint()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(3.76));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsUpAboveHighMidpoint()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(3.8));
+		}
+		
+		[Test()]
+		public void TestRoundHalfUpDoesntAlterHalf()
+		{
+			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.5));
+		}
+		
+		[Test()]
+		public void TestRoundHalfUpDoesntRoundEvenNumber()
+		{
+			Assert.AreEqual(4, IBBMath.CeilToHalf(4));
+		}
+		
+		[Test()]
+		public void TestRoundHalfUpDoesntRoundOddNumber()
+		{
+			Assert.AreEqual(3, IBBMath.CeilToHalf(3));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownBelowLowMidpoint()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3.2));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownJustBelowLowMidpoint()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3.24));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownOnLowMidpoint()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3.25));
+		}
+
+		[Test()]
+		public void TestRoundHalfRoundsDownJustAboveLowMidpoint()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3.26));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownAboveLowMidpoint()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3.3));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownBelowHighMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.7));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownJustBelowHighMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.74));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownOnHighMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.75));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownJustAboveHighMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.76));
+		}
+		
+		[Test()]
+		public void TestRoundHalfRoundsDownAboveHighMidpoint()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.8));
+		}
+		
+		[Test()]
+		public void TestRoundHalfDownDoesntAlterHalf()
+		{
+			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.5));
+		}
+		
+		[Test()]
+		public void TestRoundHalfDownDoesntRoundEvenNumber()
+		{
+			Assert.AreEqual(4, IBBMath.FloorToHalf(4));
+		}
+		
+		[Test()]
+		public void TestRoundHalfDownDoesntRoundOddNumber()
+		{
+			Assert.AreEqual(3, IBBMath.FloorToHalf(3));
+		}
+
+
+		
 	}
 }