Exemplo n.º 1
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 static Lexical create(TerminalSymbol terminalSymbol, int parenthesisDepth)
        {
            switch (terminalSymbol.type)
            {
            case TerminalSymbolType.Integer:
                var literalInteger = new LiteralInteger();
                literalInteger.value = terminalSymbol.value;
                return(literalInteger);

            case TerminalSymbolType.Decimal:
                var literalDecimal = new LiteralDecimal();
                literalDecimal.value = terminalSymbol.value;
                return(literalDecimal);

            case TerminalSymbolType.LogicTrue:
                var literalTrue = new LiteralTrue();
                literalTrue.value = terminalSymbol.value;
                return(literalTrue);

            case TerminalSymbolType.LogicFalse:
                var literalFalse = new LiteralFalse();
                literalFalse.value = terminalSymbol.value;
                return(literalFalse);

            case TerminalSymbolType.Variable:
                var literalVariable = new LiteralVariable();
                literalVariable.value = terminalSymbol.value;
                return(literalVariable);

            case TerminalSymbolType.OpAdd:
                var binaryOperatorAdd = new BinaryOperatorAdd();
                binaryOperatorAdd.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorAdd);

            case TerminalSymbolType.OpDiff:
                var binaryOperatorDiff = new BinaryOperatorDiff();
                binaryOperatorDiff.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorDiff);

            case TerminalSymbolType.OpProd:
                var binaryOperatorProd = new BinaryOperatorProd();
                binaryOperatorProd.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorProd);

            case TerminalSymbolType.OpDivide:
                var binaryOperatorDivide = new BinaryOperatorDivide();
                binaryOperatorDivide.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorDivide);

            case TerminalSymbolType.OpMod:
                var binaryOperatorMod = new BinaryOperatorMod();
                binaryOperatorMod.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorMod);

            case TerminalSymbolType.OpPow:
                var binaryOperatorPow = new BinaryOperatorPow();
                binaryOperatorPow.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorPow);

            case TerminalSymbolType.OpNeg:
                var unaryOperatorNegative = new UnaryOperatorNegative();
                unaryOperatorNegative.parenthesisDepth = parenthesisDepth;
                return(unaryOperatorNegative);

            case TerminalSymbolType.OpLt:
                var binaryOperatorLt = new BinaryOperatorLt();
                binaryOperatorLt.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorLt);

            case TerminalSymbolType.OpLtEq:
                var binaryOperatorLtEq = new BinaryOperatorLtEq();
                binaryOperatorLtEq.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorLtEq);

            case TerminalSymbolType.OpGt:
                var binaryOperatorGt = new BinaryOperatorGt();
                binaryOperatorGt.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorGt);

            case TerminalSymbolType.OpGtEq:
                var binaryOperatorGtEq = new BinaryOperatorGtEq();
                binaryOperatorGtEq.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorGtEq);

            case TerminalSymbolType.OpEq:
                var binaryOperatorEqual = new BinaryOperatorEqual();
                binaryOperatorEqual.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorEqual);

            case TerminalSymbolType.OpNotEq:
                var binaryOperatorNotEqual = new BinaryOperatorNotEqual();
                binaryOperatorNotEqual.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorNotEqual);

            case TerminalSymbolType.OpNot:
                var unaryOperatorNot = new UnaryOperatorNot();
                unaryOperatorNot.parenthesisDepth = parenthesisDepth;
                return(unaryOperatorNot);

            case TerminalSymbolType.OpAnd:
                var binaryOperatorAnd = new BinaryOperatorAnd();
                binaryOperatorAnd.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorAnd);

            case TerminalSymbolType.OpOr:
                var binaryOperatorOr = new BinaryOperatorOr();
                binaryOperatorOr.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorOr);

            case TerminalSymbolType.Function:
                var unaryOperatorFunction = new UnaryOperatorFunction();
                // 演算子の中で、関数だけ変数名を登録する必要がある。
                unaryOperatorFunction.functionName     = terminalSymbol.value;
                unaryOperatorFunction.parenthesisDepth = parenthesisDepth;
                return(unaryOperatorFunction);

            case TerminalSymbolType.Comma:
                var binaryOperatorComma = new BinaryOperatorComma();
                binaryOperatorComma.parenthesisDepth = parenthesisDepth;
                return(binaryOperatorComma);

            default:
                throw new ApplicationException("品詞に変換できない終端記号が指定されました。");
            }
        }