Exemplo n.º 1
0
        public void TestBasicInterpreterWithVariables()
        {
            IFunctionRegistry functionRegistry = new MockFunctionRegistry();
            IConstantRegistry constantRegistry = new MockConstantRegistry();

            Dictionary <string, double> variables = new Dictionary <string, double>();

            variables.Add("var1", 2);
            variables.Add("age", 4);

            IExecutor interpreter = new Interpreter();
            // var1 + 2 * (3 * age)
            double result = interpreter.Execute(
                new Addition(DataType.FloatingPoint,
                             new Variable("var1"),
                             new Multiplication(
                                 DataType.FloatingPoint,
                                 new IntegerConstant(2),
                                 new Multiplication(
                                     DataType.FloatingPoint,
                                     new IntegerConstant(3),
                                     new Variable("age")))), functionRegistry, constantRegistry, variables);

            Assert.AreEqual(26.0, result);
        }
Exemplo n.º 2
0
        public void TestBasicInterpreterSubstraction()
        {
            IFunctionRegistry functionRegistry = new MockFunctionRegistry();
            IConstantRegistry constantRegistry = new MockConstantRegistry();

            IExecutor executor = new Interpreter();
            double    result   = executor.Execute(new Subtraction(
                                                      DataType.Integer,
                                                      new IntegerConstant(6),
                                                      new IntegerConstant(9)), functionRegistry, constantRegistry);

            Assert.AreEqual(-3.0, result);
        }
Exemplo n.º 3
0
        public void TestBasicInterpreter1()
        {
            IFunctionRegistry functionRegistry = new MockFunctionRegistry();
            IConstantRegistry constantRegistry = new MockConstantRegistry();

            IExecutor executor = new Interpreter();
            // 6 + (2 * 4)
            double result = executor.Execute(
                new Addition(
                    DataType.Integer,
                    new IntegerConstant(6),
                    new Multiplication(
                        DataType.Integer,
                        new IntegerConstant(2),
                        new IntegerConstant(4))), functionRegistry, constantRegistry);

            Assert.AreEqual(14.0, result);
        }