Пример #1
0
        public void with_x_variable(string toParse, double x, double expected)
        {
            var n = new SimpleAnalyzer().Parse(toParse);
            var v = new ComputeVisitor(name => name == "x"
                                                    ? (double?)x
                                                    : null);

            v.VisitNode(n);
            v.Result.Should().Be(expected);
        }
Пример #2
0
        public void PlusMinusInvertMutator_in_action(string input, double result)
        {
            var n = new SimpleAnalyzer().Parse(input);

            var mp = new PlusMinusInvertMutator();
            var nV = mp.VisitNode(n);

            var computer = new ComputeVisitor();

            computer.VisitNode(nV);
            computer.Result.Should().Be(result);
        }
Пример #3
0
        public void with_x_and_y_variable(string toParse, double x, double y, double expected)
        {
            var n = new SimpleAnalyzer().Parse(toParse);
            var d = new Dictionary <string, double>
            {
                { "x", x },
                { "y", y }
            };
            var v = new ComputeVisitor(d);

            v.VisitNode(n);
            v.Result.Should().Be(expected);
        }
Пример #4
0
 public void compute_visitor_in_action()
 {
     {
         var n = new SimpleAnalyzer().Parse("3");
         var v = new ComputeVisitor();
         v.VisitNode(n);
         v.Result.Should().Be(3.0);
     }
     {
         var n = new SimpleAnalyzer().Parse("3+3");
         var v = new ComputeVisitor();
         v.VisitNode(n);
         v.Result.Should().Be(6.0);
     }
     {
         var n = new SimpleAnalyzer().Parse("3+3*9-1+3+7-4+1?8:9+3+3*9");
         var v = new ComputeVisitor();
         v.VisitNode(n);
         v.Result.Should().Be((3 + 3 * 9 - 1 + 3 + 7 - 4 + 1) > 0 ? 8 : 9 + 3 + 3 * 9);
     }
 }