Exemplo n.º 1
0
        static public void TestSum(String poly1, String poly2, String answer)
        {
            string testDescr = poly1 + " + " + poly2;

            Console.Write("\n___________________________________________________________________________________\nTestSum: " + testDescr);
            log(ConsoleColor.Magenta, " ? ");

            //initialize polynoms
            TPoly p1 = new TPoly(TPoly.StringToMap(poly1));
            TPoly p2 = new TPoly(TPoly.StringToMap(poly2));

            // calculation
            var test = p1 + p2;

            // write result
            Console.Write(test.PolynomToString());

            // checking
            if (test.PolynomToString() == answer)
            {
                log(ConsoleColor.Green, "\t>>> ok \n");
            }
            else
            {
                log(ConsoleColor.Red, "\t>>> fail \n");
            }
        }
Exemplo n.º 2
0
        static public void TestGetMember(String poly, int i, TMember answer)
        {
            string testDescr = poly;

            Console.Write("\n___________________________________________________________________________________\nTestGetMember: " + testDescr);
            log(ConsoleColor.Magenta, " ? ");

            //initialize polynom
            TPoly p = new TPoly(TPoly.StringToMap(poly));

            // calculation
            var test = p.GetMember(i);

            // write result
            Console.Write(test.FCoeff + " " + test.FDegree);

            // checking
            if (test == answer)
            {
                log(ConsoleColor.Green, "\t>>> ok \n");
            }
            else
            {
                log(ConsoleColor.Red, "\t>>> fail \n");
            }
        }
Exemplo n.º 3
0
        static public void TestDerr(String poly, String answer)
        {
            string testDescr = "(" + poly + ")'";

            Console.Write("\n___________________________________________________________________________________\nTestDerr: " + testDescr);
            log(ConsoleColor.Magenta, " ? ");

            //initialize polynom
            TPoly p = new TPoly(TPoly.StringToMap(poly));

            // calculation
            var test = p.Derivative();

            // write result
            Console.Write(test.PolynomToString());

            // checking
            if (test.PolynomToString() == answer)
            {
                log(ConsoleColor.Green, "\t>>> ok \n");
            }
            else
            {
                log(ConsoleColor.Red, "\t>>> fail \n");
            }
        }
Exemplo n.º 4
0
        static public void TestVal(String poly, int x, int answer)
        {
            string testDescr = "f(x) = " + poly + ", x = " + x;

            Console.Write("\n___________________________________________________________________________________\nTestVal: " + testDescr);
            log(ConsoleColor.Magenta, " ? ");

            //initialize polynom
            TPoly p = new TPoly(TPoly.StringToMap(poly));

            // calculation
            var test = p.Value(x);

            // write result
            Console.Write(test);

            // checking
            if (test == answer)
            {
                log(ConsoleColor.Green, "\t>>> ok \n");
            }
            else
            {
                log(ConsoleColor.Red, "\t>>> fail \n");
            }
        }
Exemplo n.º 5
0
        public static TPoly operator *(TPoly p1, TPoly p2)
        {
            SortedDictionary <int, TMember> tempPolynom;
            TPoly result = new TPoly(TPoly.StringToMap("0x^0"));

            foreach (KeyValuePair <int, TMember> entry1 in p2.polynom)
            {
                tempPolynom = new SortedDictionary <int, TMember>();
                foreach (KeyValuePair <int, TMember> entry2 in p1.polynom)
                {
                    int coeff  = entry1.Value.FCoeff * entry2.Value.FCoeff;
                    int degree = entry1.Key + entry2.Key;
                    tempPolynom.Add(degree, new TMember(coeff, degree));
                }
                result = result + (new TPoly(tempPolynom));
            }

            return(result);
        }