private static void TestSubtraction() { Console.WriteLine("Testing BigInt subtraction: 9687 - " + "4999"); int testSmallInt1 = 9687, testSmallInt2 = 4999; BigInt big1 = new BigInt(testSmallInt1.ToString()); BigInt big2 = new BigInt(testSmallInt2.ToString()); BigInt diff = big1 - big2; if (Convert.ToInt32(diff.AbsValue) == testSmallInt1 - testSmallInt2) { Console.WriteLine("Subtraction successful. Diff was: " + diff.AbsValue); } else { Console.WriteLine("Subtraction unsuccessful. Diff was: " + diff.AbsValue + Environment.NewLine + "Expected Diff was:" + diff); } Console.ReadLine(); Console.WriteLine("Testing BigInt subtraction: 4999 - " + "9687"); diff = big2 - big1; if (Convert.ToInt32(diff.ToString()) == testSmallInt2 - testSmallInt1) { Console.WriteLine("Subtraction successful. Diff was: " + diff.ToString()); } else { Console.WriteLine("Subtraction unsuccessful. Diff was: " + diff.ToString() + Environment.NewLine + "Expected Diff was:" + (testSmallInt2 - testSmallInt1).ToString()); } Console.WriteLine("Testing BigInt subtraction: -9687 - 4999"); testSmallInt1 = -9687; testSmallInt2 = 4999; big1 = new BigInt(testSmallInt1.ToString()); big2 = new BigInt(testSmallInt2.ToString()); diff = big1 - big2; if (Convert.ToInt32(diff.ToString()) == testSmallInt1 - testSmallInt2) { Console.WriteLine("Subtraction successful. Diff was: " + diff.ToString()); } else { Console.WriteLine("Subtraction unsuccessful. Diff was: " + diff.ToString() + Environment.NewLine + "Expected Diff was:" + (testSmallInt1 - testSmallInt2).ToString()); } Console.ReadLine(); Console.WriteLine("Testing BigInt Subtraction: 1234567789798797897998798797987987" + "1111110000000000000000000000000000"); big1 = new BigInt("1234567789798797897998798797987987"); big2 = new BigInt("1111110000000000000000000000000000"); diff = big1 - big2; if (diff.AbsValue == "123457789798797897998798797987987") { Console.WriteLine("Subtraction successful. Sum was: " + diff.AbsValue); } else { Console.WriteLine("Subtraction unsuccessful. Sum was: " + diff.AbsValue); } Console.WriteLine("Testing BigInt Subtraction: 10000000" + "9"); big1 = new BigInt("10000000"); big2 = new BigInt("9"); testSmallInt1 = 10000000; testSmallInt2 = 9; diff = big1 - big2; if (Convert.ToInt32(diff.ToString()) == testSmallInt1 - testSmallInt2) { Console.WriteLine("Subtraction successful. Diff was: " + diff.ToString()); } else { Console.WriteLine("Subtraction unsuccessful. Diff was: " + diff.ToString() + Environment.NewLine + "Expected Diff was:" + (testSmallInt2 - testSmallInt1).ToString()); } Console.ReadLine(); }
private static void TestSpecialCases() { BigInt big1 = null, big2 = null; int testSmallInt1 = 9687, testSmallInt2 = 4999; //Test simple cases Console.WriteLine("Testing BigInt Multiplication 9687*0"); testSmallInt1 = 9687; testSmallInt2 = 0; big1 = new BigInt(testSmallInt1.ToString()); big2 = new BigInt(testSmallInt2.ToString()); BigInt product = big1 * big2; if (product.ToString() == (testSmallInt1 * testSmallInt2).ToString()) { Console.WriteLine("Multiplication == successful"); } else { Console.WriteLine("Multiplication == unsuccessful. Expected: " + (testSmallInt1 * testSmallInt2).ToString() + " Received: " + product.ToString()); } Console.ReadLine(); //Test simple cases Console.WriteLine("Testing BigInt Multiplication 9687*1"); testSmallInt1 = 9687; testSmallInt2 = 1; big1 = new BigInt(testSmallInt1.ToString()); big2 = new BigInt(testSmallInt2.ToString()); product = big1 * big2; if (product.ToString() == (testSmallInt1 * testSmallInt2).ToString()) { Console.WriteLine("Multiplication == successful"); } else { Console.WriteLine("Multiplication == unsuccessful. Expected: " + (testSmallInt1 * testSmallInt2).ToString() + " Received: " + product.ToString()); } Console.ReadLine(); //Test simple cases Console.WriteLine("Testing BigInt Multiplication 9687*-1"); testSmallInt1 = 9687; testSmallInt2 = -1; big1 = new BigInt(testSmallInt1.ToString()); big2 = new BigInt(testSmallInt2.ToString()); product = big1 * big2; if (product.ToString() == (testSmallInt1 * testSmallInt2).ToString()) { Console.WriteLine("Multiplication == successful"); } else { Console.WriteLine("Multiplication == unsuccessful. Expected: " + (testSmallInt1 * testSmallInt2).ToString() + " Received: " + product.ToString()); } Console.ReadLine(); //Multiplication by powers of 10 Console.WriteLine("Testing BigInt Multiplication 9687*1000000000000"); testSmallInt1 = 9687; testSmallInt2 = -1; big1 = new BigInt(testSmallInt1.ToString()); big2 = new BigInt("1000000000000"); product = big1 * big2; if (product.ToString() == "9687000000000000") { Console.WriteLine("Multiplication == successful"); } else { Console.WriteLine("Multiplication == unsuccessful. Expected: " + (testSmallInt1 * testSmallInt2).ToString() + " Received: " + product.ToString()); } Console.ReadLine(); }