public static void TestInsert() { Console.Clear(); Polynomials S = new Polynomials(); DatastructuresLinkedList.Polynomial emptyPolynomial = new DatastructuresLinkedList.Polynomial(); DatastructuresLinkedList.Polynomial polynomial1 = new DatastructuresLinkedList.Polynomial(); Term term1 = new Term(8, 5); Term term2 = new Term(12, 4); Term term3 = new Term(2, 3); Term term4 = new Term(6, 2); polynomial1.AddTerm(term1); polynomial1.AddTerm(term2); polynomial1.AddTerm(term3); polynomial1.AddTerm(term4); DatastructuresLinkedList.Polynomial polynomial2 = new DatastructuresLinkedList.Polynomial(); Term term5 = new Term(6, 4); Term term6 = new Term(-16, 2); polynomial2.AddTerm(term5); polynomial2.AddTerm(term6); DatastructuresLinkedList.Polynomial polynomial3 = new DatastructuresLinkedList.Polynomial(); polynomial3.AddTerm(term2); polynomial3.AddTerm(term6); polynomial3.AddTerm(term3); Console.WriteLine("Testing Polynomials Class - List<Polynomial>"); Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("Method 1: Insert()"); Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("Scenario 3.1.1:"); Console.Write("Polynomial1:\t"); polynomial1.Print(); Console.Write("\nPolynomials S before adding new polynomial1:\n"); S.Print(); S.Insert(polynomial1); Console.Write("\nPolynomial S after adding new polynomial1:\n"); S.Print(); Console.WriteLine("\n"); Console.WriteLine("Scenario 3.1.2:"); Console.Write("Polynomial2:\t"); polynomial2.Print(); Console.Write("\nPolynomials S before adding new polynomial2:\n"); S.Print(); S.Insert(polynomial2); Console.Write("Polynomial S after adding new polynomial2:\n"); S.Print(); Console.WriteLine("\n"); Console.WriteLine("Scenario 3.1.3:"); Console.Write("Polynomial3:\t"); polynomial3.Print(); Console.Write("\nPolynomials S before adding new polynomial3:\n"); S.Print(); S.Insert(polynomial3); Console.Write("Polynomial S after adding new polynomial3:\n"); S.Print(); Console.WriteLine("\n"); Console.WriteLine("Scenario 3.1.4:"); Console.Write("Polynomial2:\t"); emptyPolynomial.Print(); Console.Write("\nPolynomials S before adding new empty polynomial:\n"); S.Print(); S.Insert(emptyPolynomial); Console.Write("Polynomial S after adding new empty polynomial:\n"); S.Print(); Console.WriteLine("\n"); Console.WriteLine("End of Insert() tests"); Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); Console.Clear(); }
public static void TestEvaluate() { Term term1 = new Term(-3, 7); Term term2 = new Term(4, 5); Term term3 = new Term(0, 4); Term term4 = new Term(5, 1); Term term5 = new Term(2, 0); double x1 = 8; double x2 = 0; double x3 = -2; double x4 = 1.2; double x5 = -3.4; DatastructuresLinkedList.Polynomial polynomial = new DatastructuresLinkedList.Polynomial(); Console.WriteLine("Testing Polynomial Class - Linked List Implementation"); Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("Method 2: Evaluate()"); Console.WriteLine("------------------------------------------------------------------"); polynomial.AddTerm(term1); polynomial.AddTerm(term2); polynomial.AddTerm(term3); polynomial.AddTerm(term4); polynomial.AddTerm(term5); Console.WriteLine("Scenario 1.2.1:"); Console.Write("Polynomial: "); polynomial.Print(); Console.WriteLine($"\nx1: {x1}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x1)}"); Console.WriteLine("\n"); Console.WriteLine("Scenario 1.2.2:"); Console.Write("Polynomial: "); polynomial.Print(); Console.WriteLine($"\nx2: {x2}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x2)}"); Console.WriteLine("\n"); Console.WriteLine("Scenario 1.2.3:"); Console.Write("Polynomial: "); polynomial.Print(); Console.WriteLine($"\nx3: {x3}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x3)}"); Console.WriteLine("\n"); Console.WriteLine("Scenario 1.2.4:"); Console.Write("Polynomial: "); polynomial.Print(); Console.WriteLine($"\nx4: {x4}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x4)}"); Console.WriteLine("\n"); Console.WriteLine("Scenario 1.2.5:"); Console.Write("Polynomial: "); polynomial.Print(); Console.WriteLine($"\nx5: {x5}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x5)}"); Console.WriteLine("\n"); Console.WriteLine("Scenario 2.2.6:"); Console.Write("Polynomial: "); polynomial = new Polynomial(); polynomial.Print(); Console.WriteLine($"\nx6: {x5}"); Console.WriteLine($"Evaluate Result: {polynomial.Evaluate(x5)}"); Console.WriteLine("\n"); Console.WriteLine("End of Evaluate() tests"); Console.WriteLine("------------------------------------------------------------------"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); Console.Clear(); }