Пример #1
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");
            }
        }
Пример #2
0
        static public SortedDictionary <int, TMember> StringToMap(String str)
        {
            String[] coeffs = Regex.Split(str, "([+-]?(?:(?:\\d+x\\^\\d+)|(?:\\d+x)|(?:\\d+)|(?:x)))");
            SortedDictionary <int, TMember> result = new SortedDictionary <int, TMember>();

            String[] temp;
            if (str == "")
            {
                result.Add(0, new TMember());
            }
            else
            {
                for (int i = 1; i < coeffs.Length - 1; i = i + 2)
                {
                    temp = Regex.Split(coeffs[i], "[xX^]");
                    TMember newMember = new TMember(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[2]));
                    result.Add(Convert.ToInt32(temp[2]), newMember);
                }
            }
            return(result);
        }