Exemple #1
0
        public void SimpleBrackets2Test()
        {
            var input = "-(-(-(x))) = x + y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("2x + y = 0", sut.Normalize(input));
        }
Exemple #2
0
        public void MultipleDigitRankTest()
        {
            var input = "x^22 = y^-233";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x^22 - y^-233 = 0", sut.Normalize(input));
        }
Exemple #3
0
        public void TestAnalyze()
        {
            List <Summand> summands = new List <Summand>()
            {
                new Summand(1, new Dictionary <char, int>()
                {
                    { 'x', 2 }, { 'y', 1 }
                }),
                new Summand(-2, new Dictionary <char, int>()
                {
                    { 'x', 2 }, { 'y', 1 }
                }),
                new Summand(2, new Dictionary <char, int>()
                {
                    { 'x', 1 }, { 'z', 1 }
                }),
                new Summand(3, new Dictionary <char, int>()
                {
                    { 'x', 1 }, { 'z', 1 }
                }),
                new Summand(4, new Dictionary <char, int>()
                {
                    { 'x', 3 }, { 'y', 1 }
                }),
                new Summand(10, new Dictionary <char, int>()),
                new Summand(-4, new Dictionary <char, int>())
            };

            EquationNormalizer       e = new EquationNormalizer();
            Tuple <List <char>, int> a = e.Analyze(summands);

            Assert.AreEqual(a.Item1.Count, 3);
            Assert.AreEqual(a.Item2, 3);
        }
Exemple #4
0
        public void MultipleVariableOrderInsensetiveTest()
        {
            var input = "xy = yx";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("0 = 0", sut.Normalize(input));
        }
Exemple #5
0
        public void ExampleEquationTest()
        {
            var input = "x^2 + 3.5xy + y = y^2 - xy + y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x^2 - y^2 + 4.5xy = 0", sut.Normalize(input));
        }
Exemple #6
0
        public void OneVariableEquationTest()
        {
            var input = "2x + y + 0z = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x = 0", sut.Normalize(input));
        }
Exemple #7
0
        public void VariableGroupingNoSpaceTest()
        {
            var input = "-x-y=x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("2x + y = 0", sut.Normalize(input));
        }
Exemple #8
0
        public void BracketsWithCoefficients2Test()
        {
            var input = "-10(10.0(x + 20(x + 2) + 5(z)^3) + y) = -100.000x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("500z^3 + 2000x + 10y + 4000 = 0", sut.Normalize(input));
        }
Exemple #9
0
        public void BracketsWithCoefficients3Test()
        {
            var input = "-((10))(x + y) = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("11x + 10y = 0", sut.Normalize(input));
        }
Exemple #10
0
        public void BracketsWithCoefficients1Test()
        {
            var input = "2(zw)^3 - 3(xy)^2 = 3.0";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("2(wz)^3 - 3(xy)^2 - 3 = 0", sut.Normalize(input));
        }
Exemple #11
0
        public void CaseInsensetiveTest()
        {
            var input = "x = X";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("0 = 0", sut.Normalize(input));
        }
Exemple #12
0
        public void MultipleRankedVariableTest()
        {
            var input = "(xy)^2 = z";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("(xy)^2 - z = 0", sut.Normalize(input));
        }
Exemple #13
0
        public void SimpleBrackets4Test()
        {
            var input = "x + (x ) = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x = 0", sut.Normalize(input));
        }
Exemple #14
0
        public void SimpleBrackets3Test()
        {
            var input = "-(x - ((xy + z))) = 0";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - xy - z = 0", sut.Normalize(input));
        }
Exemple #15
0
        public void BracketsWithSpaces3Test()
        {
            var input = "2((3x^0 + 4.0y^0) )y= x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - 14y = 0", sut.Normalize(input));
        }
Exemple #16
0
        public void BracketsWithCoefficients4Test()
        {
            var input = "(10 + 2) + (10 + x) = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - y + 22 = 0", sut.Normalize(input));
        }
Exemple #17
0
        public void BracketsWithSpaces5Test()
        {
            var input = "((yz ) )^2 = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("(yz)^2 - x = 0", sut.Normalize(input));
        }
Exemple #18
0
        public void BracketsWithCoefficients5Test()
        {
            var input = "((1 + 2) + 3(5 + x)) = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("3x - y + 18 = 0", sut.Normalize(input));
        }
Exemple #19
0
        public void MultipleVariablesTest()
        {
            var input = "x - xy = xyz - y + xy";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - 2xy - xyz + y = 0", sut.Normalize(input));
        }
Exemple #20
0
        public void BracketsWithCoefficients6Test()
        {
            var input = "2(1 + 2)x + 2(10 + x) = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("8x - y + 20 = 0", sut.Normalize(input));
        }
Exemple #21
0
        public void PlusAfterConstantTest()
        {
            var input = "10+x = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - y + 10 = 0", sut.Normalize(input));
        }
Exemple #22
0
        public void BracketsWithCoefficients8Test()
        {
            var input = "2(10 + 3x + 2z^2) = y";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("4z^2 + 6x - y + 20 = 0", sut.Normalize(input));
        }
Exemple #23
0
        public void MultipleRanksTest()
        {
            var input = "x^2 + x + xy + y = yx + y^2 + y + z";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x^2 - y^2 + x - z = 0", sut.Normalize(input));
        }
Exemple #24
0
        public void BracketsWithCoefficient11Test()
        {
            var input = "2((10)) = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x - 20 = 0", sut.Normalize(input));
        }
Exemple #25
0
        public void SignedRankTest()
        {
            var input = "x^+2 = y^-2";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("x^2 - y^-2 = 0", sut.Normalize(input));
        }
Exemple #26
0
        public void BracketsWithCoefficient12Test()
        {
            var input = "2((3x^0 + 4.0y^0))(y - x) = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("15x - 14y = 0", sut.Normalize(input));
        }
Exemple #27
0
        public void TestSortSummands()
        {
            List <Summand> summands = new List <Summand>()
            {
                new Summand(1, new Dictionary <char, int>()
                {
                    { 'x', 2 }, { 'y', 1 }
                }),
                new Summand(2, new Dictionary <char, int>()
                {
                    { 'x', 1 }, { 'z', 1 }
                }),
                new Summand(4, new Dictionary <char, int>()
                {
                    { 'x', 3 }, { 'y', 1 }
                }),
                new Summand(10, new Dictionary <char, int>())
            };

            EquationNormalizer e = new EquationNormalizer();
            List <Summand>     sortedSummands = e.Sort(summands);

            Assert.AreEqual(sortedSummands[0].coeff, 4);
            Assert.AreEqual(sortedSummands[1].coeff, 1);
            Assert.AreEqual(sortedSummands[2].coeff, 2);
            Assert.AreEqual(sortedSummands[3].coeff, 10);
        }
Exemple #28
0
        public void BracketsWithSpaces2Test()
        {
            var input = "-(-(-(10 + 2) ))(x + y) = x";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("13x + 12y = 0", sut.Normalize(input));
        }
Exemple #29
0
        public void TestNormalize()
        {
            EquationNormalizer e      = new EquationNormalizer();
            string             output = e.Normalize("((x - 2)(y + 3)) = 0");

            Assert.AreEqual(output, "xy + 3x - 2y - 6 = 0");

            output = e.Normalize("(x - 2)(y + 3) = ((x - 5)(x - 1))");
            Assert.AreEqual(output, "-x^2 + xy + 9x - 2y - 11 = 0");

            output = e.Normalize("(x - 2)(y + 3) = xy(x - 5)(x - 1)");
            Assert.AreEqual(output, "-x^3y + 6x^2y - 4xy + 3x - 2y - 6 = 0");

            output = e.Normalize("(x - 2)((x + 5) + 4) = 0");
            Assert.AreEqual(output, "x^2 + 7x - 18 = 0");

            output = e.Normalize("x = 1");
            Assert.AreEqual(output, "x - 1 = 0");

            output = e.Normalize("x^2 + 3.5xy + y = y^2 - xy + y");
            Assert.AreEqual(output, "x^2 - y^2 + 4.5xy = 0");

            output = e.Normalize("x - (0 - (0 - x)) = 0");
            Assert.AreEqual(output, "0 = 0");
        }
Exemple #30
0
        public void SimpleBrackets1Test()
        {
            var input = "-(x + y) = (x + y)";
            var sut   = new EquationNormalizer();

            Assert.AreEqual("2x + 2y = 0", sut.Normalize(input));
        }