Ejemplo n.º 1
0
        public void SimpleParsing()
        {
            IToken[] tokens =
            {
                new Term(1,             "x"),
                new Operator('-'),
                new LeftParenthesis(),
                new Term(3,             "y"),
                new Operator('-'),
                new Term(2,             "y"),
                new RightParenthesis(),
                new Operator('='),
                new Term(0,             string.Empty)
            };

            IToken[] expected =
            {
                new Term(1,        "x"),
                new Operator('-'),
                new Term(3,        "y"),
                new Operator('+'),
                new Term(2,        "y"),
                new Operator('='),
                new Term(0,        string.Empty)
            };

            var parenthesisRemover = new ParenthesisRemover();
            var result             = parenthesisRemover.RemoveParenthesis(tokens);

            Assert.Equal(expected, result);
        }
Ejemplo n.º 2
0
        public void NotEnoughBracesError()
        {
            IToken[] tokens =
            {
                new LeftParenthesis(),
                new RightParenthesis(),
                new RightParenthesis()
            };

            var parenthesisRemover = new ParenthesisRemover();
            var exception          = Assert.Throws <InvalidOperationException>(() => parenthesisRemover.RemoveParenthesis(tokens));

            Assert.Contains("Right parenthesis is placed before the left one", exception.Message);
        }
Ejemplo n.º 3
0
        public void TooManyBracesError()
        {
            IToken[] tokens =
            {
                new LeftParenthesis(),
                new LeftParenthesis(),
                new RightParenthesis()
            };

            var parenthesisRemover = new ParenthesisRemover();
            var exception          = Assert.Throws <InvalidOperationException>(() => parenthesisRemover.RemoveParenthesis(tokens));

            Assert.Equal("1 left parenthesis are not balanced", exception.Message);
        }