示例#1
0
        public static void TestRetrieve()
        {
            Console.Clear();

            Polynomials S = new Polynomials();

            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 2: Retrieve()");
            Console.WriteLine("------------------------------------------------------------------");


            Console.WriteLine("Scenario 3.2.1:");
            Console.Write("S:\n");
            S.Print();
            Console.Write($"\nindex1 = {0}\n");
            Console.Write($"Polynomial at index{0}:\t");
            S.Retrieve(0).Print();
            Console.WriteLine("\n");

            S.Insert(polynomial1);
            S.Insert(polynomial2);
            S.Insert(polynomial3);

            Console.WriteLine("Scenario 3.2.2:");
            Console.Write("S:\n");
            S.Print();
            Console.Write($"\nindex1 = {0}\n");
            Console.Write($"Polynomial at index{0}:\t");
            S.Retrieve(0).Print();
            Console.WriteLine("\n\n");

            Console.WriteLine("Scenario 3.2.3:");
            Console.Write("S:\n");
            S.Print();
            Console.Write($"\nindex2 = {1} [<count]\n");
            Console.Write($"Polynomial at index{1}:\t");
            S.Retrieve(1).Print();
            Console.WriteLine("\n\n");

            Console.WriteLine("Scenario 3.2.4:");
            Console.Write("S:\n");
            S.Print();
            Console.Write($"\nindex3 = {2} [count - 1]\n");
            Console.Write($"Polynomial at index{2}:\t");
            S.Retrieve(2).Print();
            Console.WriteLine("\n\n");

            Console.WriteLine("Scenario 3.2.5:");
            Console.Write("S:\n");
            S.Print();
            Console.Write($"\nindex4 = {5} [>= count]\n");
            Console.Write($"Polynomial at index{5}:\t");
            S.Retrieve(5).Print();
            Console.WriteLine("\n\n");


            Console.WriteLine("End of Retrieve() tests");
            Console.WriteLine("------------------------------------------------------------------");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
        }
示例#2
0
        public static void TestPrint()
        {
            Console.Clear();

            Polynomials S = new Polynomials();

            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 5: Print()");
            Console.WriteLine("-----------------------------------------------------------------");


            Console.WriteLine("Scenario 3.5.1:");
            Console.WriteLine("When S is empty");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.WriteLine("\n");

            S.Insert(polynomial1);
            Console.WriteLine("Scenario 3.5.2:");
            Console.WriteLine("When S has only one entry");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.WriteLine("\n");

            S.Insert(polynomial2);
            S.Insert(polynomial3);
            Console.WriteLine("Scenario 3.5.3:");
            Console.WriteLine("When S has more than one entry");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.WriteLine("\n");


            Console.WriteLine("End of Print() tests");
            Console.WriteLine("------------------------------------------------------------------");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
        }
示例#3
0
        public static void TestSize()
        {
            Console.Clear();

            Polynomials S = new Polynomials();

            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 4: Size()");
            Console.WriteLine("------------------------------------------------------------------");

            Console.WriteLine("Scenario 3.4.1:");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.Write($"\nSize of polynomials S: {S.Size()}\n");
            Console.WriteLine("\n");

            S.Insert(polynomial1);
            Console.WriteLine("Scenario 3.4.2:");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.Write($"Size of polynomials S: {S.Size()}\n");
            Console.WriteLine("\n");

            S.Insert(polynomial2);
            S.Insert(polynomial3);
            Console.WriteLine("Scenario 3.4.3:");
            Console.Write($"Polynomials S :\n");
            S.Print();
            Console.Write($"Size of polynomials S: {S.Size()}\n");
            Console.WriteLine("\n");

            Console.WriteLine("End of Size() tests");
            Console.WriteLine("------------------------------------------------------------------");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
        }
示例#4
0
        public static void TestDelete()
        {
            Console.Clear();

            Polynomials S = new Polynomials();

            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 3: Delete()");
            Console.WriteLine("------------------------------------------------------------------");

            Console.WriteLine("Scenario 3.3.1:");
            Console.Write($"\nindex 1 = {0}");
            Console.Write($"\nPolynomials S before deleting polynomial at {0}:\n");
            S.Print();
            //S.Delete(0);
            Console.Write($"\nPolynomial S after deleting polynomial at {0}:\n");
            S.Print();
            Console.WriteLine("\n");


            S.Insert(polynomial1);
            S.Insert(polynomial2);
            S.Insert(polynomial3);

            Console.WriteLine("Scenario 3.3.2:");
            Console.Write($"\nindex 2 = {0}");
            Console.Write($"\nPolynomials S before deleting polynomial at {0}:\n");
            S.Print();
            S.Delete(0);
            Console.Write($"\nPolynomial S after deleting polynomial at {0}:\n");
            S.Print();
            Console.WriteLine("\n\n");

            S.Insert(polynomial1);

            Console.WriteLine("Scenario 3.3.3:");
            Console.Write($"\nindex 3 = {1}");
            Console.Write($"\nPolynomials S before deleting polynomial at {1}:\n");
            S.Print();
            S.Delete(1);
            Console.Write($"\nPolynomial S after deleting polynomial at {1}:\n");
            S.Print();
            Console.WriteLine("\n\n");

            S.Insert(polynomial3);

            Console.WriteLine("Scenario 3.3.4:");
            Console.Write($"\nindex 4 = {2}");
            Console.Write($"\nPolynomials S before deleting polynomial at {2}:\n");
            S.Print();
            S.Delete(2);
            Console.Write($"\nPolynomial S after deleting polynomial at {2}:\n");
            S.Print();
            Console.WriteLine("\n\n");

            S.Insert(polynomial3);

            Console.WriteLine("Scenario 3.3.5:");
            Console.Write($"\nindex 5 = {5}");
            Console.Write($"\nPolynomials S before deleting polynomial at {5}:\n");
            S.Print();
            S.Delete(5);
            Console.Write($"\nPolynomial S after deleting polynomial at {5}:\n");
            S.Print();
            Console.WriteLine("\n\n");


            Console.WriteLine("End of Delete() tests");
            Console.WriteLine("------------------------------------------------------------------");
            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
            Console.Clear();
        }
示例#5
0
        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();
        }
示例#6
0
        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();
        }