00001 namespace Tests
00002 {
00003 using System;
00004 using Microsoft.VisualStudio.TestTools.UnitTesting;
00005 using NewGamePhysics.Mathematics;
00006
00010 [TestClass]
00011 public class UnitTestFactorial
00012 {
00013 public UnitTestFactorial()
00014 {
00015 }
00016
00017 private TestContext testContextInstance;
00018
00023 public TestContext TestContext
00024 {
00025 get
00026 {
00027 return testContextInstance;
00028 }
00029 set
00030 {
00031 testContextInstance = value;
00032 }
00033 }
00034
00035 [TestMethod]
00036 public void FactorialCalc()
00037 {
00038 uint[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
00039
00040
00041 ulong[] expected = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800 };
00042
00043 ulong value;
00044 int numTestdata = expected.Length;
00045 for (int i = 0; i < numTestdata; i++)
00046 {
00047 value = Factorial.Calc(x[i]);
00048 Console.WriteLine(
00049 "Factorial.Calc({0}): expected {1} got {2}",
00050 x[i],
00051 expected[i],
00052 value);
00053 Assert.AreEqual(expected[i], value);
00054 }
00055 }
00056
00057 [TestMethod]
00058 public void FactorialCalcDouble()
00059 {
00060
00061 int[] x = { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8 };
00062
00063
00064 ulong[] expected = { 1, 1, 1, 2, 3, 8, 15, 48, 105, 384 };
00065
00066 ulong value;
00067 int numTestdata = expected.Length;
00068 for (int i = 0; i < numTestdata; i++)
00069 {
00070 value = Factorial.CalcDouble(x[i]);
00071 Console.WriteLine(
00072 "Factorial.CalcDouble({0}): expected {1} got {2}",
00073 x[i],
00074 expected[i],
00075 value);
00076 Assert.AreEqual(expected[i], value);
00077 }
00078 }
00079 }
00080 }
00081