view Lang/IBBMathTests.cs @ 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
line wrap: on
line source

//  This file (IBBMathTest.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.Lang
{
	[TestFixture()]	
	public class IBBMathTest
	{
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingBelowLowMidpoint()
		{
			Assert.AreEqual(3, IBBMath.RoundToHalf(3.2));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingJustBelowLowMidpoint()
		{
			Assert.AreEqual(3, IBBMath.RoundToHalf(3.24));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingOnLowMidpoint()
		{
			Assert.AreEqual(3, IBBMath.RoundToHalf(3.25));
		}

		[Test()]
		public void TestRoundHalfPerformsBankersRoundingJustAboveLowMidpoint()
		{
			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.26));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingAboveLowMidpoint()
		{
			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.3));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingBelowHighMidpoint()
		{
			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.7));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingJustBelowHighMidpoint()
		{
			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.74));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingOnHighMidpoint()
		{
			Assert.AreEqual(4, IBBMath.RoundToHalf(3.75));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingJustAboveHighMidpoint()
		{
			Assert.AreEqual(4, IBBMath.RoundToHalf(3.76));
		}
		
		[Test()]
		public void TestRoundHalfPerformsBankersRoundingAboveHighMidpoint()
		{
			Assert.AreEqual(4, IBBMath.RoundToHalf(3.8));
		}
		
		[Test()]
		public void TestRoundHalfDoesntAlterHalf()
		{
			Assert.AreEqual(3.5, IBBMath.RoundToHalf(3.5));
		}
		
		[Test()]
		public void TestRoundHalfDoesntRoundEvenNumber()
		{
			Assert.AreEqual(4, IBBMath.RoundToHalf(4));
		}
		
		[Test()]
		public void TestRoundHalfDoesntRoundOddNumber()
		{
			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));
		}


		
	}
}