Example #1
0
        // Method for solving system of linear equations,
        // where count of linear equation = linearequationcount,
        // count of unknown members = unknowncount,
        // strlist - list of linear equations formated as strings
        public string TrySolveLinearEquationSystem(int linearequationcount,
                        int unknowncount, List<string> strlist)
        {
            // Result
            string result = "";

            try
            {
                // Initialize the system of linear equation from strlist
                List<LinearPolynomial> linearequationlist = new List<LinearPolynomial>();
                foreach (string str in strlist)
                {
                    LinearPolynomial linPolynomial =
                        new LinearPolynomial(str);

                    // If str is a linear polynomial
                    if (linPolynomial.Members.Count != 0)
                        linearequationlist.Add(linPolynomial);
                }
                LinearEquationSystem leSystem =
                    new LinearEquationSystem(linearequationlist);

                // If wrong input data
                if (leSystem.LinearEquationCount != linearequationcount
                    || leSystem.UnknownCount != unknowncount
                    || linearequationcount != strlist.Count)
                {
                    result = "Wrong input system. "
                              + "Check the input data for pattern matching "
                              + "(look at the example).";

                    return result;
                }

                // Try to find the solution of the system
                Dictionary<string, string> Solution
                     = leSystem.FindSolution_MatrixMethod();
                foreach (var root in Solution)
                    result += root.Key + ": " + root.Value
                              + " ";
            }
            catch (Exception exception)
            {
                // Write to log
                logger.WriteLog(System.DateTime.Now.ToString()
                    + " "
                    + exception.TargetSite.ToString()
                    + " "
                    + exception.Message);

                result = "Wrong input system. "
                         + "Check the input data for pattern matching "
                         + "(look at the example).";
            }

            return result;
        }
Example #2
0
        public void ConstructorTestNotValidInputStr(string notValidInputStr)
        {
            LinearPolynomial lPolynomial =
                new LinearPolynomial(notValidInputStr);

            // Actual values
            SortedDictionary<string, string> actualMembers =
                lPolynomial.Members;
            int actualUnknownCount = lPolynomial.UnknownCount;

            // Asserts
            Assert.AreEqual(0, actualUnknownCount);
            Assert.AreEqual(0, lPolynomial.Members.Count);
        }       
Example #3
0
        public void ConstructorTestValidStr_3_roots(string validInputStr,
            string root_1, string root_2, string root_3, string free, int uCount)
        {
            LinearPolynomial lPolynomial =
                new LinearPolynomial(validInputStr);

            // Actual values
            SortedDictionary<string, string> actualMembers =
                lPolynomial.Members;
            int actualUnknownCount = lPolynomial.UnknownCount;

            // Asserts
            Assert.AreEqual(uCount, actualUnknownCount);
            Assert.AreEqual(root_1, actualMembers["x"]);
            Assert.AreEqual(root_2, actualMembers["y"]);
            Assert.AreEqual(root_3, actualMembers["z"]);
            Assert.AreEqual(free, actualMembers["!!!"]);
        }