Exemple #1
0
        public void TestFindsInfiniteSolutions()
        {
            var firstEquation  = new LinearEquation(18, -3, 45);
            var secondEquation = new LinearEquation(6, -1, 15);
            var coefficients   = new List <LinearEquation>()
            {
                firstEquation, secondEquation
            };

            bool invalidCoefficients;
            var  actualSolution   = LinearSimultaneousEquationsAnalysisFunctions.CalculateSolution(coefficients, out invalidCoefficients);
            var  expectedSolution = new LinearSimultaneousEquationsSolution(Convert.ToDouble(-14) / Convert.ToDouble(6), 1, false, true);

            Assert.IsTrue(EqualSolutions(expectedSolution, actualSolution));
        }
Exemple #2
0
        public void TestFindsNoSolution()
        {
            var firstEquation  = new LinearEquation(18, -3, 46);
            var secondEquation = new LinearEquation(6, -1, 12);
            var coefficients   = new List <LinearEquation>()
            {
                firstEquation, secondEquation
            };

            bool invalidCoefficients;
            var  actualSolution   = LinearSimultaneousEquationsAnalysisFunctions.CalculateSolution(coefficients, out invalidCoefficients);
            var  expectedSolution = new LinearSimultaneousEquationsSolution(Double.NaN, Double.NaN, true, false);

            Assert.IsTrue(EqualSolutions(expectedSolution, actualSolution));
        }
Exemple #3
0
        public void TestFindsUniqueSolution()
        {
            var firstEquation  = new LinearEquation(3, 2, -36);
            var secondEquation = new LinearEquation(5, 4, -64);
            var coefficients   = new List <LinearEquation>()
            {
                firstEquation, secondEquation
            };

            bool invalidCoefficients;
            var  actualSolution   = LinearSimultaneousEquationsAnalysisFunctions.CalculateSolution(coefficients, out invalidCoefficients);
            var  expectedSolution = new LinearSimultaneousEquationsSolution(8, 6, false, false);

            Assert.IsTrue(EqualSolutions(expectedSolution, actualSolution));
            Assert.IsFalse(invalidCoefficients);
        }
        public LinearSimultaneousEquations CovertToLinearSimultaneousEquations()
        {
            var equations = new List <LinearEquation>()
            {
                new LinearEquation(FirstEquationXTerm, FirstEquationYTerm, FirstEquationConstantTerm),
                new LinearEquation(SecondEquationXTerm, SecondEquationYTerm, SecondEquationConstantTerm)
            };

            var solution = LinearSimultaneousEquationsAnalysisFunctions.CalculateSolution(equations, out var invalidSolution);

            if (invalidSolution)
            {
                throw new Exception("Data was stored incorrectly.");
            }

            return(new LinearSimultaneousEquations(equations, solution));
        }