Example #1
0
        public void InfinitelyManySolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("2.0, 6.0,-5.0, 10.0"));
            s.Add(new LinearEquation("4.0, 12.0, -10.0, 20.0"));
            s.Add(new LinearEquation("4.0, 12.0, -10.0, 20.0"));
            s.SteppingUp();
            Assert.Equals(typeof(ArgumentException), s.SolveSystem());
        }
        public void CheckNoSolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("3.0, 2.0,-4.0, 3.0"));
            s.Add(new LinearEquation("6.0, 4.0, -8.0, 15.0"));
            s.Add(new LinearEquation("6.0, 4.0, -8.0, 15.0"));
            s.SteppingUp();
            Assert.Equals(typeof(ArgumentException), s.SolveSystem());
        }
Example #3
0
        public void CorrectAnswer()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("3.0, 2.0,-4.0, 3.0"));
            s.Add(new LinearEquation("2.0, 3.0, 3.0, 15.0"));
            s.Add(new LinearEquation("5.0, -3, 1.0, 14.0"));
            s.SteppingUp();
            double[] solve1 = new double[] { 3, 1, 2 };
            double[] solve2 = s.SolveSystem();
            bool     check  = true;

            for (int i = 0; i < n; i++)
            {
                if (Math.Abs(solve1[i] - solve2[i]) > 1e-9)
                {
                    check = false;
                }
            }
            Assert.AreEqual(true, check);
        }