Esempio n. 1
0
        public void TestIterateWithBrackets()
        {
            RawExpression       rawExpression1 = new RawExpression(0, "(x + y)(y^2 + 10) - (5)");
            RawExpressionParser parser         = new RawExpressionParser(rawExpression1);

            List <RawMultiplier> multipliers = parser.Iterator().ToList();

            Assert.AreEqual(multipliers.Count, 2);
            Assert.AreEqual(multipliers[0].rawString, "(x + y)(y^2 + 10) ");
            Assert.AreEqual(multipliers[1].rawString, "(5)");

            rawExpression1 = new RawExpression(0, "((1 - z) + 4) + (((4))) + ((x))");
            parser         = new RawExpressionParser(rawExpression1);

            multipliers = parser.Iterator().ToList();
            Assert.AreEqual(multipliers.Count, 3);
            Assert.AreEqual(multipliers[0].rawString, "((1 - z) + 4) ");
            Assert.AreEqual(multipliers[1].rawString, "(((4))) ");
            Assert.AreEqual(multipliers[2].rawString, "((x))");
        }
Esempio n. 2
0
        public void TestIterate()
        {
            // things are going right
            RawExpression       rawExpression1 = new RawExpression(0, "-4 + 6 -9xy");
            RawExpressionParser parser         = new RawExpressionParser(rawExpression1);

            List <RawMultiplier> multipliers = parser.Iterator().ToList();

            Assert.AreEqual(multipliers.Count, 3);

            Assert.AreEqual(multipliers[0].rawString, "4 ");
            Assert.AreEqual(multipliers[1].rawString, "6 ");
            Assert.AreEqual(multipliers[2].rawString, "9xy");

            Assert.AreEqual(multipliers[0].coeff, -1);
            Assert.AreEqual(multipliers[1].coeff, 1);
            Assert.AreEqual(multipliers[2].coeff, -1);

            Assert.AreEqual(multipliers[0].offset, 1);
            Assert.AreEqual(multipliers[1].offset, 5);
            Assert.AreEqual(multipliers[2].offset, 8);

            parser = new RawExpressionParser(new RawExpression(0, "- +"));
            // things are going wrong
            try
            {
                multipliers = parser.Iterator().ToList();
                Assert.Fail();
            }
            catch (ParseException e)
            {
                Assert.AreEqual(e.index, 2);
                Assert.AreEqual(e.Message, "Summand symbols are expected here, not operand");
            }

            parser = new RawExpressionParser(new RawExpression(0, " +78z"));
            try
            {
                multipliers = parser.Iterator().ToList();
                Assert.Fail();
            }
            catch (ParseException e)
            {
                Assert.AreEqual(e.index, 1);
                Assert.AreEqual(e.Message, "'+' sign is not expected to be here");
            }

            parser = new RawExpressionParser(new RawExpression(0, "78z + uh + - 9"));
            try
            {
                multipliers = parser.Iterator().ToList();
                Assert.Fail();
            }
            catch (ParseException e)
            {
                Assert.AreEqual(e.index, 11);
                Assert.AreEqual(e.Message, "Summand symbols are expected here, not operand");
            }

            parser = new RawExpressionParser(new RawExpression(0, "78z + (dfdg) + 78x - "));
            try
            {
                multipliers = parser.Iterator().ToList();
                Assert.Fail();
            }
            catch (ParseException e)
            {
                Assert.AreEqual(e.index, 21);
                Assert.AreEqual(e.Message, "Symbols are expected after operand");
            }
        }