Exemplo n.º 1
0
        public void should_throw_if_expression_contains_invalid_token()
        {
            var evaluator = new InfixToPostfixEvaluator();

            string[] expression = { "1", "+", "2", "wtf", "3" };
            Assert.Throws <ArgumentException>(() => evaluator.Evaluate(expression));
        }
Exemplo n.º 2
0
        public void should_detect_simple_syntax_error()
        {
            var evaluator = new InfixToPostfixEvaluator();

            string[] expression = { "+", "1", "+", "2", "-", "3" };
            Assert.Throws <ArgumentException>(() => evaluator.Evaluate(expression));
        }
Exemplo n.º 3
0
        public void should_calculate_plus()
        {
            var evaluator = new InfixToPostfixEvaluator();

            string[] expression        = { "1", "+", "2" };
            string[] postfixExpression = evaluator.Evaluate(expression);

            Assert.Equal(new [] { "1", "2", "+" }, postfixExpression);
        }
Exemplo n.º 4
0
        public void should_calculate_mixed_plus_minors_times_div()
        {
            var evaluator = new InfixToPostfixEvaluator();

            string[] expression        = { "10", "+", "2", "*", "8", "-", "3" };
            string[] postfixExpression = evaluator.Evaluate(expression);

            Assert.Equal(new [] { "10", "2", "8", "*", "+", "3", "-" }, postfixExpression);
        }