public override TestResult Run() { ulong n = 999; Stopwatch sw = new Stopwatch(); TestResult tr = new TestResult(); for (int i = 0; i < 10; i++) { sw.Restart(); byte[] nByte = BigInt.MakeByteArray(n); sw.Stop(); long t = sw.ElapsedTicks; tr.AddSegment("Make byte array", t); Console.WriteLine(tr.SegmentString()); sw.Restart(); byte[] result = BigInt.Factorial(nByte); sw.Stop(); t = sw.ElapsedTicks; tr.AddSegment("Factorial", t); Console.WriteLine(tr.SegmentString()); } return(tr); }
public void FactorialTest() { TestCase1[] factorial_data = new TestCase1[Math2.FactorialTable.Length]; // step 1: compute factorials using big integer to avoid trunctaion errors factorial_data[0] = new TestCase1(0, 1); for (int i = 1; i < Math2.FactorialTable.Length; i++) { factorial_data[i] = new TestCase1(i, BigInt.Factorial(i)); } // Run the test case TestCaseSet <int>[] testCases = { new TestCaseSet <int>(factorial_data, "Factorial: Complete table", 1), }; NumericFunctionTest.RunSet(Math2.Factorial, "Factorial", testCases); Assert.AreEqual(double.PositiveInfinity, Math2.Factorial(Math2.FactorialTable.Length)); Assert.AreEqual(double.PositiveInfinity, Math2.Factorial(int.MaxValue)); // TODO: negative }
void TestFactorial(ulong n) { byte[] nByte = BigInt.MakeByteArray(n); byte[] result = BigInt.Factorial(nByte); string r = ClearZeroes(result); BigInteger result2 = NumericsFactorial(n); Assert.AreEqual(r, result2.ToString()); }
public void FactorialTableTest() { TestCase1[] factorial_data = new TestCase1[Math2.FactorialTable.Length]; // step 1: compute factorials using big integer to avoid trunctaion errors factorial_data[0] = new TestCase1(0, 1); for (int i = 1; i < Math2.FactorialTable.Length; i++) { factorial_data[i] = new TestCase1(i, BigInt.Factorial(i)); } // Run the test case TestCaseSet <int>[] testCases = { new TestCaseSet <int>(factorial_data, "Factorial: Complete table", 1), }; NumericFunctionTest.RunSet((int i) => Math2.FactorialTable[i], "Factorial Table", testCases); }