Exemplo n.º 1
0
        public void TestMethodBinaryOperatorDiff()
        {
            var binaryOperatorDiff = new BinaryOperatorDiff();

            Assert.AreEqual(5, binaryOperatorDiff.getPriority());
            Assert.AreEqual("--", binaryOperatorDiff.getRPolish());

            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.Integer, binaryOperatorDiff.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorDiff.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.Decimal, binaryOperatorDiff.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorDiff.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorDiff.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(-5, binaryOperatorDiff.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(-5.1, binaryOperatorDiff.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8.1)));
            UnitTestUtil.AssertMathTreeNodeValue(-4.5, binaryOperatorDiff.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(-4.6, binaryOperatorDiff.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8.1)));
        }
Exemplo n.º 2
0
        public void TestMethodBinaryOperatorProd()
        {
            var binaryOperatorProd = new BinaryOperatorProd();

            Assert.AreEqual(6, binaryOperatorProd.getPriority());
            Assert.AreEqual("*", binaryOperatorProd.getRPolish());

            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.Integer, binaryOperatorProd.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorProd.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.Decimal, binaryOperatorProd.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorProd.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorProd.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(24, binaryOperatorProd.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(3.0 * 8.1, binaryOperatorProd.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8.1)));
            UnitTestUtil.AssertMathTreeNodeValue(3.5 * 8.0, binaryOperatorProd.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(3.5 * 8.1, binaryOperatorProd.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8.1)));
        }
Exemplo n.º 3
0
        public void TestMethodBinaryOperatorOr()
        {
            var binaryOperatorOr = new BinaryOperatorOr();

            Assert.AreEqual(2, binaryOperatorOr.getPriority());
            Assert.AreEqual("||", binaryOperatorOr.getRPolish());

            Assert.AreEqual(DataType.Boolean, binaryOperatorOr.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorOr.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorOr.eval(new MathTreeNodeValue(true), new MathTreeNodeValue(true)));
            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorOr.eval(new MathTreeNodeValue(true), new MathTreeNodeValue(false)));
            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorOr.eval(new MathTreeNodeValue(false), new MathTreeNodeValue(true)));
            UnitTestUtil.AssertMathTreeNodeValue(false, binaryOperatorOr.eval(new MathTreeNodeValue(false), new MathTreeNodeValue(false)));
        }
Exemplo n.º 4
0
        public void TestMethodBinaryOperatorPow()
        {
            var binaryOperatorPow = new BinaryOperatorPow();

            Assert.AreEqual(7, binaryOperatorPow.getPriority());
            Assert.AreEqual("^", binaryOperatorPow.getRPolish());

            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.Decimal, binaryOperatorPow.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorPow.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.Decimal, binaryOperatorPow.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.Decimal, binaryOperatorPow.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorPow.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(Math.Pow(3, 8), binaryOperatorPow.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(Math.Pow(3.0, 8.1), binaryOperatorPow.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8.1)));
            UnitTestUtil.AssertMathTreeNodeValue(Math.Pow(3.5, 8.0), binaryOperatorPow.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(Math.Pow(3.5, 8.1), binaryOperatorPow.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8.1)));
        }
Exemplo n.º 5
0
        public void TestMethodBinaryOperatorGtEq()
        {
            var binaryOperatorGtEq = new BinaryOperatorGtEq();

            Assert.AreEqual(4, binaryOperatorGtEq.getPriority());
            Assert.AreEqual(">=", binaryOperatorGtEq.getRPolish());

            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.Boolean, binaryOperatorGtEq.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.Boolean, binaryOperatorGtEq.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.Boolean, binaryOperatorGtEq.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.Boolean, binaryOperatorGtEq.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorGtEq.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorGtEq.eval(new MathTreeNodeValue(1), new MathTreeNodeValue(1)));
            UnitTestUtil.AssertMathTreeNodeValue(false, binaryOperatorGtEq.eval(new MathTreeNodeValue(3), new MathTreeNodeValue(8)));
            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorGtEq.eval(new MathTreeNodeValue(8), new MathTreeNodeValue(3.5)));
            UnitTestUtil.AssertMathTreeNodeValue(true, binaryOperatorGtEq.eval(new MathTreeNodeValue(8.1), new MathTreeNodeValue(3)));
            UnitTestUtil.AssertMathTreeNodeValue(false, binaryOperatorGtEq.eval(new MathTreeNodeValue(3.5), new MathTreeNodeValue(8.1)));
        }
        public void TestMethodLiteralVariableMultiVariable()
        {
            var variableDataTypeMap = new Dictionary <string, DataType>();

            variableDataTypeMap.Add("testVariable1", DataType.Boolean);
            variableDataTypeMap.Add("testVariable2", DataType.Integer);
            variableDataTypeMap.Add("testVariable3", DataType.Decimal);
            var variableMap = new Dictionary <string, Variable>();

            variableMap.Add("testVariable1", new Variable(true));
            variableMap.Add("testVariable2", new Variable(222));
            variableMap.Add("testVariable3", new Variable(333.33));
            var literalVariable = new LiteralVariable();

            literalVariable.value = "testVariable1";
            Assert.AreEqual("Var[testVariable1]", literalVariable.getRPolish());
            Assert.AreEqual(DataType.Boolean, literalVariable.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(true, literalVariable.eval(variableMap));
            literalVariable.value = "testVariable2";
            Assert.AreEqual("Var[testVariable2]", literalVariable.getRPolish());
            Assert.AreEqual(DataType.Integer, literalVariable.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(222, literalVariable.eval(variableMap));
            literalVariable.value = "testVariable3";
            Assert.AreEqual("Var[testVariable3]", literalVariable.getRPolish());
            Assert.AreEqual(DataType.Decimal, literalVariable.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(333.33, literalVariable.eval(variableMap));
        }
        public void TestMethodLiteralFalse()
        {
            var variableDataTypeMap = new Dictionary <string, DataType>();
            var variableMap         = new Dictionary <string, Variable>();
            var literalFalse        = new LiteralFalse();

            Assert.AreEqual("false", literalFalse.getRPolish());
            Assert.AreEqual(DataType.Boolean, literalFalse.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(false, literalFalse.eval(variableMap));
        }
        public void TestMethodLiteralDecimal2()
        {
            var variableDataTypeMap = new Dictionary <string, DataType>();
            var variableMap         = new Dictionary <string, Variable>();
            var literalDecimal      = new LiteralDecimal();

            literalDecimal.value = "12345678.";
            Assert.AreEqual("Dec[12345678.]", literalDecimal.getRPolish());
            Assert.AreEqual(DataType.Decimal, literalDecimal.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue((double)12345678, literalDecimal.eval(variableMap));
        }
        public void TestMethodLiteralInteger2()
        {
            var variableDataTypeMap = new Dictionary <string, DataType>();
            var variableMap         = new Dictionary <string, Variable>();
            var literalInteger      = new LiteralInteger();

            literalInteger.value = "0987";
            Assert.AreEqual("Int[0987]", literalInteger.getRPolish());
            Assert.AreEqual(DataType.Integer, literalInteger.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(987L, literalInteger.eval(variableMap));
        }
        public void TestMethodLiteralVariableBoolean()
        {
            var variableDataTypeMap = new Dictionary <string, DataType>();

            variableDataTypeMap.Add("testVariable", DataType.Boolean);
            var variableMap = new Dictionary <string, Variable>();

            variableMap.Add("testVariable", new Variable(true));
            var literalVariable = new LiteralVariable();

            literalVariable.value = "testVariable";
            Assert.AreEqual("Var[testVariable]", literalVariable.getRPolish());
            Assert.AreEqual(DataType.Boolean, literalVariable.getDataType(variableDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(true, literalVariable.eval(variableMap));
        }
        public void TestMethodUnaryOperatorNot()
        {
            var functionDataTypeMap = new Dictionary <string, DataType>();
            var functionMap         = new Dictionary <string, Function>();
            var unaryOperatorNot    = new UnaryOperatorNot();

            Assert.AreEqual("!", unaryOperatorNot.getRPolish());
            Assert.AreEqual(8, unaryOperatorNot.getPriority());
            Assert.AreEqual(DataType.Boolean, unaryOperatorNot.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorNot.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorNot.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorNot.getDataType(DataType.DecimalList, functionDataTypeMap));
            UnitTestUtil.AssertMathTreeNodeValue(false, unaryOperatorNot.eval(new MathTreeNodeValue(true), functionMap));
            try
            {
                unaryOperatorNot.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorNot.eval(new MathTreeNodeValue(12345.678), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorNot.eval(new MathTreeNodeValue(new List <double>()
                {
                    1.2, 3.4, 5.6
                }), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
        }
        public void TestMethodUnaryOperatorFunction()
        {
            var functionDataTypeMap = new Dictionary <string, DataType>();

            functionDataTypeMap.Add("testFunction1", DataType.Boolean);
            functionDataTypeMap.Add("testFunction2", DataType.Boolean);
            functionDataTypeMap.Add("testFunction3", DataType.Boolean);
            functionDataTypeMap.Add("testFunction4", DataType.Integer);
            functionDataTypeMap.Add("testFunction5", DataType.Integer);
            functionDataTypeMap.Add("testFunction6", DataType.Integer);
            functionDataTypeMap.Add("testFunction7", DataType.Decimal);
            functionDataTypeMap.Add("testFunction8", DataType.Decimal);
            functionDataTypeMap.Add("testFunction9", DataType.Decimal);
            var functionMap = new Dictionary <string, Function>();

            functionMap.Add("testFunction1", new Function(this.testFunction1));
            functionMap.Add("testFunction2", new Function(this.testFunction2));
            functionMap.Add("testFunction3", new Function(this.testFunction3));
            functionMap.Add("testFunction4", new Function(this.testFunction4));
            functionMap.Add("testFunction5", new Function(this.testFunction5));
            functionMap.Add("testFunction6", new Function(this.testFunction6));
            functionMap.Add("testFunction7", new Function(this.testFunction7));
            functionMap.Add("testFunction8", new Function(this.testFunction8));
            functionMap.Add("testFunction9", new Function(this.testFunction9));

            var unaryOperatorFunction = new UnaryOperatorFunction();

            Assert.AreEqual(9, unaryOperatorFunction.getPriority());

            unaryOperatorFunction.functionName = "testFunction1";
            Assert.AreEqual("Func[testFunction1]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(true, unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(false, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(true, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction2";
            Assert.AreEqual("Func[testFunction2]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(true, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction3";
            Assert.AreEqual("Func[testFunction3]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Boolean, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(true, unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(false, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(true, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction4";
            Assert.AreEqual("Func[testFunction4]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(12348, unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(-121, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(4, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction5";
            Assert.AreEqual("Func[testFunction5]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(3, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction6";
            Assert.AreEqual("Func[testFunction6]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Integer, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(12345, unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(-124, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(10, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction7";
            Assert.AreEqual("Func[testFunction7]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue(Math.Sqrt((double)12345), unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(Double.NaN, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue((double)1, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction8";
            Assert.AreEqual("Func[testFunction8]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentOutOfRangeException));
            }
            UnitTestUtil.AssertMathTreeNodeValue((double)0, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction9";
            Assert.AreEqual("Func[testFunction9]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.Decimal, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            UnitTestUtil.AssertMathTreeNodeValue((double)152399025, unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue(15239.9025, unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap));
            UnitTestUtil.AssertMathTreeNodeValue((double)30, unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
            {
                1, 2, 3, 4
            }), functionMap));

            unaryOperatorFunction.functionName = "testFunction10";
            Assert.AreEqual("Func[testFunction10]", unaryOperatorFunction.getRPolish());
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Boolean, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Integer, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.Decimal, functionDataTypeMap));
            Assert.AreEqual(DataType.None, unaryOperatorFunction.getDataType(DataType.DecimalList, functionDataTypeMap));
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(true), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(12345), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(-123.45), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
            try
            {
                unaryOperatorFunction.eval(new MathTreeNodeValue(new List <double>()
                {
                    1, 2, 3, 4
                }), functionMap);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.GetType() == typeof(ArgumentException));
            }
        }
Exemplo n.º 13
0
        public void TestMethodBinaryOperatorComma()
        {
            var binaryOperatorComma = new BinaryOperatorComma();

            Assert.AreEqual(1, binaryOperatorComma.getPriority());
            Assert.AreEqual(",", binaryOperatorComma.getRPolish());

            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Boolean, DataType.Boolean));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Boolean, DataType.Integer));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Boolean, DataType.Decimal));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Boolean, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Integer, DataType.Boolean));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Integer, DataType.Integer));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Integer, DataType.Decimal));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Integer, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.Decimal, DataType.Boolean));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Decimal, DataType.Integer));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Decimal, DataType.Decimal));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.Decimal, DataType.DecimalList));
            Assert.AreEqual(DataType.None, binaryOperatorComma.getDataType(DataType.DecimalList, DataType.Boolean));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.DecimalList, DataType.Integer));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.DecimalList, DataType.Decimal));
            Assert.AreEqual(DataType.DecimalList, binaryOperatorComma.getDataType(DataType.DecimalList, DataType.DecimalList));

            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                2, 2
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(2), new MathTreeNodeValue(2)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                2, 4
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(2), new MathTreeNodeValue(4.0)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                2, 5.6, 7.8
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(2), new MathTreeNodeValue(new List <double>()
            {
                5.6, 7.8
            })));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                4, 2
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(4.0), new MathTreeNodeValue(2)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                4, 4
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(4.0), new MathTreeNodeValue(4.0)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                4, 5.6, 7.8
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(4.0), new MathTreeNodeValue(new List <double>()
            {
                5.6, 7.8
            })));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                1.2, 3.4, 2
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(new List <double>()
            {
                1.2, 3.4
            }), new MathTreeNodeValue(2)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                1.2, 3.4, 4
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(new List <double>()
            {
                1.2, 3.4
            }), new MathTreeNodeValue(4.0)));
            UnitTestUtil.AssertMathTreeNodeValue(new List <double>()
            {
                1.2, 3.4, 5.6, 7.8
            },
                                                 binaryOperatorComma.eval(new MathTreeNodeValue(new List <double>()
            {
                1.2, 3.4
            }), new MathTreeNodeValue(new List <double>()
            {
                5.6, 7.8
            })));
        }