changeset 11:37642712f632

* Tests for method for making percentage of one integer compared to another to ensure consistency no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Fri, 06 Nov 2009 19:57:44 +0000
parents 5507654d189d
children 298786adcddc
files CustomMath/IBBMathTests.cs
diffstat 1 files changed, 40 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/CustomMath/IBBMathTests.cs	Sat Oct 24 19:50:09 2009 +0000
     1.2 +++ b/CustomMath/IBBMathTests.cs	Fri Nov 06 19:57:44 2009 +0000
     1.3 @@ -245,7 +245,46 @@
     1.4  			Assert.AreEqual(3, IBBMath.FloorToHalf(3));
     1.5  		}
     1.6  
     1.7 +		[Test()]
     1.8 +		public void TestPercentageCalculations()
     1.9 +		{
    1.10 +			Assert.AreEqual(50, IBBMath.Percentage(1,2));
    1.11 +			Assert.AreEqual(50, IBBMath.Percentage(2,4));
    1.12 +			Assert.AreEqual(25, IBBMath.Percentage(1,4));
    1.13 +			Assert.AreEqual(10, IBBMath.Percentage(1,10));
    1.14 +			Assert.AreEqual(1, IBBMath.Percentage(1,100));
    1.15 +			Assert.AreEqual(0.1, IBBMath.Percentage(1,1000));
    1.16 +			Assert.AreEqual(200, IBBMath.Percentage(2,1));
    1.17 +			Assert.AreEqual(-50, IBBMath.Percentage(-1,2));
    1.18 +			Assert.AreEqual(-50, IBBMath.Percentage(-2,4));
    1.19 +			Assert.AreEqual(-50, IBBMath.Percentage(1,-2));
    1.20 +			Assert.AreEqual(-50, IBBMath.Percentage(2,-4));
    1.21 +		}
    1.22  
    1.23 -		
    1.24 +		[Test()]
    1.25 +		public void TestPercentageCalculationsForZero()
    1.26 +		{
    1.27 +			Assert.AreEqual(0, IBBMath.Percentage(0,2));
    1.28 +			Assert.AreEqual(0, IBBMath.Percentage(0,4));
    1.29 +			Assert.AreEqual(0, IBBMath.Percentage(0,10));
    1.30 +			Assert.AreEqual(0, IBBMath.Percentage(0,-2));
    1.31 +			Assert.AreEqual(0, IBBMath.Percentage(0,-4));
    1.32 +			Assert.AreEqual(0, IBBMath.Percentage(0,-10));
    1.33 +		}
    1.34 +
    1.35 +		[Test()]
    1.36 +		public void TestPercentageCalculationsWithZeroAsDivisor()
    1.37 +		{
    1.38 +			Assert.AreEqual(double.PositiveInfinity, IBBMath.Percentage(1,0));
    1.39 +			Assert.AreEqual(double.PositiveInfinity, IBBMath.Percentage(2,0));
    1.40 +			Assert.AreEqual(double.NegativeInfinity, IBBMath.Percentage(-1,0));
    1.41 +			Assert.AreEqual(double.NegativeInfinity, IBBMath.Percentage(-2,0));
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45 +		public void TestPercentageCalculationsWithZeroAsNumberAndDivisor()
    1.46 +		{
    1.47 +			Assert.AreEqual(double.NaN, IBBMath.Percentage(0,0));
    1.48 +		}
    1.49  	}
    1.50  }