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 diff
     1.1 --- a/Lang/IBBMathTests.cs	Sun May 17 16:09:38 2009 +0000
     1.2 +++ b/Lang/IBBMathTests.cs	Sun May 17 19:25:01 2009 +0000
     1.3 @@ -10,7 +10,7 @@
     1.4  {
     1.5  	[TestFixture()]	
     1.6  	public class IBBMathTest
     1.7 -	{		
     1.8 +	{
     1.9  		[Test()]
    1.10  		public void TestRoundHalfPerformsBankersRoundingBelowLowMidpoint()
    1.11  		{
    1.12 @@ -72,7 +72,7 @@
    1.13  		}
    1.14  		
    1.15  		[Test()]
    1.16 -		public void TestRoundHalfDoesntRoundHalf()
    1.17 +		public void TestRoundHalfDoesntAlterHalf()
    1.18  		{
    1.19  			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.5));
    1.20  		}
    1.21 @@ -88,5 +88,164 @@
    1.22  		{
    1.23  			Assert.AreEqual(3, IBBMath.RoundToHalf(3));
    1.24  		}
    1.25 +		
    1.26 +		[Test()]
    1.27 +		public void TestRoundHalfRoundsUpBelowLowMidpoint()
    1.28 +		{
    1.29 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.2));
    1.30 +		}
    1.31 +		
    1.32 +		[Test()]
    1.33 +		public void TestRoundHalfRoundsUpJustBelowLowMidpoint()
    1.34 +		{
    1.35 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.24));
    1.36 +		}
    1.37 +		
    1.38 +		[Test()]
    1.39 +		public void TestRoundHalfRoundsUpOnLowMidpoint()
    1.40 +		{
    1.41 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.25));
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45 +		public void TestRoundHalfRoundsUpJustAboveLowMidpoint()
    1.46 +		{
    1.47 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.26));
    1.48 +		}
    1.49 +		
    1.50 +		[Test()]
    1.51 +		public void TestRoundHalfRoundsUpAboveLowMidpoint()
    1.52 +		{
    1.53 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.3));
    1.54 +		}
    1.55 +		
    1.56 +		[Test()]
    1.57 +		public void TestRoundHalfRoundsUpBelowHighMidpoint()
    1.58 +		{
    1.59 +			Assert.AreEqual(4, IBBMath.CeilToHalf(3.7));
    1.60 +		}
    1.61 +		
    1.62 +		[Test()]
    1.63 +		public void TestRoundHalfRoundsUpJustBelowHighMidpoint()
    1.64 +		{
    1.65 +			Assert.AreEqual(4, IBBMath.CeilToHalf(3.74));
    1.66 +		}
    1.67 +		
    1.68 +		[Test()]
    1.69 +		public void TestRoundHalfRoundsUpOnHighMidpoint()
    1.70 +		{
    1.71 +			Assert.AreEqual(4, IBBMath.CeilToHalf(3.75));
    1.72 +		}
    1.73 +		
    1.74 +		[Test()]
    1.75 +		public void TestRoundHalfRoundsUpJustAboveHighMidpoint()
    1.76 +		{
    1.77 +			Assert.AreEqual(4, IBBMath.CeilToHalf(3.76));
    1.78 +		}
    1.79 +		
    1.80 +		[Test()]
    1.81 +		public void TestRoundHalfRoundsUpAboveHighMidpoint()
    1.82 +		{
    1.83 +			Assert.AreEqual(4, IBBMath.CeilToHalf(3.8));
    1.84 +		}
    1.85 +		
    1.86 +		[Test()]
    1.87 +		public void TestRoundHalfUpDoesntAlterHalf()
    1.88 +		{
    1.89 +			Assert.AreEqual(3.5, IBBMath.CeilToHalf(3.5));
    1.90 +		}
    1.91 +		
    1.92 +		[Test()]
    1.93 +		public void TestRoundHalfUpDoesntRoundEvenNumber()
    1.94 +		{
    1.95 +			Assert.AreEqual(4, IBBMath.CeilToHalf(4));
    1.96 +		}
    1.97 +		
    1.98 +		[Test()]
    1.99 +		public void TestRoundHalfUpDoesntRoundOddNumber()
   1.100 +		{
   1.101 +			Assert.AreEqual(3, IBBMath.CeilToHalf(3));
   1.102 +		}
   1.103 +		
   1.104 +		[Test()]
   1.105 +		public void TestRoundHalfRoundsDownBelowLowMidpoint()
   1.106 +		{
   1.107 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3.2));
   1.108 +		}
   1.109 +		
   1.110 +		[Test()]
   1.111 +		public void TestRoundHalfRoundsDownJustBelowLowMidpoint()
   1.112 +		{
   1.113 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3.24));
   1.114 +		}
   1.115 +		
   1.116 +		[Test()]
   1.117 +		public void TestRoundHalfRoundsDownOnLowMidpoint()
   1.118 +		{
   1.119 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3.25));
   1.120 +		}
   1.121 +
   1.122 +		[Test()]
   1.123 +		public void TestRoundHalfRoundsDownJustAboveLowMidpoint()
   1.124 +		{
   1.125 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3.26));
   1.126 +		}
   1.127 +		
   1.128 +		[Test()]
   1.129 +		public void TestRoundHalfRoundsDownAboveLowMidpoint()
   1.130 +		{
   1.131 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3.3));
   1.132 +		}
   1.133 +		
   1.134 +		[Test()]
   1.135 +		public void TestRoundHalfRoundsDownBelowHighMidpoint()
   1.136 +		{
   1.137 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.7));
   1.138 +		}
   1.139 +		
   1.140 +		[Test()]
   1.141 +		public void TestRoundHalfRoundsDownJustBelowHighMidpoint()
   1.142 +		{
   1.143 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.74));
   1.144 +		}
   1.145 +		
   1.146 +		[Test()]
   1.147 +		public void TestRoundHalfRoundsDownOnHighMidpoint()
   1.148 +		{
   1.149 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.75));
   1.150 +		}
   1.151 +		
   1.152 +		[Test()]
   1.153 +		public void TestRoundHalfRoundsDownJustAboveHighMidpoint()
   1.154 +		{
   1.155 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.76));
   1.156 +		}
   1.157 +		
   1.158 +		[Test()]
   1.159 +		public void TestRoundHalfRoundsDownAboveHighMidpoint()
   1.160 +		{
   1.161 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.8));
   1.162 +		}
   1.163 +		
   1.164 +		[Test()]
   1.165 +		public void TestRoundHalfDownDoesntAlterHalf()
   1.166 +		{
   1.167 +			Assert.AreEqual(3.5, IBBMath.FloorToHalf(3.5));
   1.168 +		}
   1.169 +		
   1.170 +		[Test()]
   1.171 +		public void TestRoundHalfDownDoesntRoundEvenNumber()
   1.172 +		{
   1.173 +			Assert.AreEqual(4, IBBMath.FloorToHalf(4));
   1.174 +		}
   1.175 +		
   1.176 +		[Test()]
   1.177 +		public void TestRoundHalfDownDoesntRoundOddNumber()
   1.178 +		{
   1.179 +			Assert.AreEqual(3, IBBMath.FloorToHalf(3));
   1.180 +		}
   1.181 +
   1.182 +
   1.183 +		
   1.184  	}
   1.185  }