Exemple #1
0
        public void ThisSetterAndGetter()
        {
            SystemOfLinearEquation sle = new SystemOfLinearEquation(2);

            sle[1] = new LinearEquation(new double[] { 4, 5, 2 });
            Assert.AreEqual("2x2+5x1+4=0", sle[1].ToString());
        }
Exemple #2
0
        public void IntConstructor()
        {
            int m = 3;
            SystemOfLinearEquation sle = new SystemOfLinearEquation(m);

            Assert.AreEqual("0=0\n0=0\n0=0\n", sle.ToString());
        }
Exemple #3
0
        public void SetAndGet()
        {
            SystemOfLinearEquation sole = new SystemOfLinearEquation(2);

            sole[0] = new LinearEquation(new double[] { 1, 2, 3 });
            Assert.AreEqual("3x2+2x1+1=0", sole[0].ToString());
        }
Exemple #4
0
        public void ThisSetterWithWrongArgument()
        {
            SystemOfLinearEquation sle = new SystemOfLinearEquation(2);

            Assert.Equals(typeof(IndexOutOfRangeException), sle[3] = new LinearEquation(new double[4] {
                1, 2, 3, 4
            }));                                                                                                       //может тут бы подошел и OutOfRangeException?
        }
Exemple #5
0
        public void SetWithIncorrectArgument()
        {
            SystemOfLinearEquation sole = new SystemOfLinearEquation(2);

            Assert.Equals(typeof(ArgumentException), sole[3] = new LinearEquation(new double[4] {
                1, 2, 3, 6
            }));
        }
        public void Index()//индексация ур-й
        {
            SystemOfLinearEquation s = new SystemOfLinearEquation(3);

            s.Add(new LinearEquation("1,2,3,4"));
            s.Add(new LinearEquation("5,6,7,8"));
            s.Add(new LinearEquation("10,11,12,13"));
            Assert.AreEqual(new LinearEquation("10,11,12,13"), s[2]);
        }
Exemple #7
0
        public void Solve()
        {
            SystemOfLinearEquation sle = new SystemOfLinearEquation(3);

            sle[0] = new LinearEquation(new double[] { -8, -1, 1, 2 });
            sle[1] = new LinearEquation(new double[] { 11, 2, -1, -3 });
            sle[2] = new LinearEquation(new double[] { 3, 2, 1, -2 });
            Assert.IsTrue(new double[] { -1, 3, 2 }.SequenceEqual(sle.Solve()));
        }
Exemple #8
0
        public void FailWithWrongArguments7()
        {
            LinearEquation         l1  = new LinearEquation("2 4 1 36", 4);
            LinearEquation         l2  = new LinearEquation("5 2 1 47", 4);
            LinearEquation         l3  = new LinearEquation(4);
            SystemOfLinearEquation slu = new SystemOfLinearEquation(3);

            Assert.ThrowsException <IndexOutOfRangeException>(() => slu[3] = l1);
        }
Exemple #9
0
        public void CorrectIndexing()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1, -2, 4, 3"));
            s.Add(new LinearEquation("-2, 5, 7, 3"));
            s.Add(new LinearEquation("-3, 3, -7, 6"));
            Assert.AreEqual(new LinearEquation("-3, 3, -7, 6"), s[2]);
        }
        public void FailIndex2()//Индексация
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1,-2,4,3"));
            s.Add(new LinearEquation("-4,5,7,3"));
            s.Add(new LinearEquation("-3,3,-7,6"));
            Assert.Equals(typeof(IndexOutOfRangeException), s[5]);
        }
Exemple #11
0
        public void FailWithIndexing2()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1,-2,1,0"));
            s.Add(new LinearEquation("2,2,-1,3"));
            s.Add(new LinearEquation("4,-1,1,5"));
            Assert.Equals(typeof(IndexOutOfRangeException), s[-5]);
        }
Exemple #12
0
        public void CorrectIndexLine()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1,-2,1,0"));
            s.Add(new LinearEquation("2,2,-1,3"));
            s.Add(new LinearEquation("4,-1,1,5"));
            Assert.AreEqual(new LinearEquation("1,-2,1,0"), s[0]);
        }
Exemple #13
0
        public void Triangular()
        {
            SystemOfLinearEquation sole = new SystemOfLinearEquation(3);

            sole[0] = new LinearEquation(new double[] { -8, -1, 1, 2 });
            sole[1] = new LinearEquation(new double[] { 11, 2, -1, -3 });
            sole[2] = new LinearEquation(new double[] { 3, 2, 1, -2 });
            sole.ToTriangular();
            Assert.AreEqual("2x3+1x2-1x1-8=0\n0,5x2+0,5x1-1=0\n-1x1-1=0\n", sole.ToString());
        }
        public void CorrectIndexing()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1,2,3,15"));
            s.Add(new LinearEquation("2,4,3,20"));
            s.Add(new LinearEquation("5,6,7,33"));
            Assert.AreEqual(new LinearEquation("2,4,3,20"), s[1]);
        }
Exemple #15
0
        public void SolveWithContradictoryEquations()
        {
            SystemOfLinearEquation sle = new SystemOfLinearEquation(4);

            sle[0] = new LinearEquation(new double[] { -8, -1, 1, 2 });
            sle[1] = new LinearEquation(new double[] { 11, 2, -1, -3 });
            sle[2] = new LinearEquation(new double[] { 3, 2, 1, -2 });
            sle[3] = new LinearEquation(new double[] { 4, 2, 2, -2 });
            Assert.Equals(typeof(ArithmeticException), sle.Solve());
        }
        public void FailWithIndexing2()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1,2,3,15"));
            s.Add(new LinearEquation("2,4,3,20"));
            s.Add(new LinearEquation("5,6,7,33"));
            Assert.Equals(typeof(IndexOutOfRangeException), s[12]);
        }
Exemple #17
0
        public void FailWithIndexing2()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("2,-4,9,28"));
            s.Add(new LinearEquation("7,3,-6,-1"));
            s.Add(new LinearEquation("7,9,-9,5"));
            Assert.Equals(typeof(IndexOutOfRangeException), s[12]);
        }
Exemple #18
0
        public void TestSystem2()
        {
            LinearEquation         l1  = new LinearEquation(4);
            LinearEquation         l2  = new LinearEquation(4);
            SystemOfLinearEquation slu = new SystemOfLinearEquation(3);

            slu[0] = l1;
            slu[1] = l2;
            Assert.AreEqual(slu[0].indexes[1], slu[1].indexes[3]);
        }
Exemple #19
0
        public void CorrectIndexing()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("2,-4,9,28"));
            s.Add(new LinearEquation("7,3,-6,-1"));
            s.Add(new LinearEquation("7,9,-9,5"));
            Assert.AreEqual(new LinearEquation("7,3,-6,-1"), s[1]);
        }
Exemple #20
0
        public void CheckNoSolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("3, 6, 4, 5"));
            s.Add(new LinearEquation("5, 10, 8, 7"));
            s.Add(new LinearEquation("-5, -10, -8, -7"));
            s.StepUp();
            Assert.Equals(typeof(ArgumentException), s.Solve());
        }
Exemple #21
0
        public void InfSolutions()
        {
            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.Shiftg();
            Assert.Equals(typeof(ArgumentException), s.System());
        }
        public void NoSolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("14,16, 40, 20"));
            s.Add(new LinearEquation("7, 8, 20, 10"));
            s.Add(new LinearEquation("0, 0, 0, 0"));
            s.StepView();
            Assert.Equals(typeof(ArgumentException), s.Solve());
        }
        public void ManySolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("3,7,1,0"));
            s.Add(new LinearEquation("1,2,3,4"));

            s.StepView();
            Assert.Equals(typeof(ArgumentException), s.Solve());
        }
        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());
        }
Exemple #25
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());
        }
Exemple #26
0
        public void InfinitelyManySolutions()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1, 4,-7, 10"));
            s.Add(new LinearEquation("-1, 4, 3, -14"));
            s.Add(new LinearEquation("-1, 4, 3, -14"));
            s.StepUp();
            Assert.Equals(typeof(ArgumentException), s.Solve());
        }
Exemple #27
0
        public void FailWithWrongArguments6()
        {
            LinearEquation         l1  = new LinearEquation("2 4 1 36", 4);
            LinearEquation         l2  = new LinearEquation("5 2 1 47", 4);
            LinearEquation         l3  = new LinearEquation("0 0 0 1", 4);
            SystemOfLinearEquation slu = new SystemOfLinearEquation(3);

            slu[0] = l1;
            slu[1] = l2;
            slu[2] = l3;
            Assert.ThrowsException <ArgumentException>(() => slu.gauss());
        }
Exemple #28
0
        public void TestSystem1()
        {
            LinearEquation         l1  = new LinearEquation("2 4 1 36", 4);
            LinearEquation         l2  = new LinearEquation("5 2 1 47", 4);
            LinearEquation         l3  = new LinearEquation("2 3 4 37", 4);
            SystemOfLinearEquation slu = new SystemOfLinearEquation(3);

            slu[0] = l1;
            slu[1] = l2;
            slu[2] = l3;
            double[] x = slu.gauss();
            Assert.AreEqual(x[0], 7.0);
        }
Exemple #29
0
        public void CorrectAnswer()
        {
            int n = 3;
            SystemOfLinearEquation s = new SystemOfLinearEquation(n);

            s.Add(new LinearEquation("1, -2, 4, 3"));
            s.Add(new LinearEquation("-4, 5, 7, 3"));
            s.Add(new LinearEquation("-3, 3, -7, 6"));
            s.StepUp();
            double[] solve1 = new double[] { -7, -5, 0 };
            double[] solve2 = s.Solve();
            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);
        }
Exemple #30
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);
        }