Esempio n. 1
0
        public void Test9()
        {
            var oex = new OperationExecutor(new OperationRecognizerProvider());
            var ab = new AbsoluteBracketsOperationRecognizer(new LambdaUnaryOperationProvider(Math.Abs));

            var op = ab.Recognize("|-9|", oex);
            Assert.AreEqual(9, op.Value);

            var sub = new BinaryOperationRecognizer("-", new LambdaBinaryOperationProvider((x, y) => x - y));
            var ind = sub.Index("|-9|", oex);
            Assert.AreEqual(-1, ind);
        }
Esempio n. 2
0
        public void Test7()
        {
            var oex = new OperationExecutor(new OperationRecognizerProvider());
            var sub = new BinaryOperationRecognizer("-", new LambdaBinaryOperationProvider((x, y) => x - y));
            var add = new BinaryOperationRecognizer("+", new LambdaBinaryOperationProvider((x, y) => x + y));

            var index = sub.Index("135-9+3", oex);
            Assert.AreEqual(3, index);

            index = add.Index("135-9+3", oex);
            Assert.AreEqual(5, index);

            var ex = Expression.Create("1+9-3*(43+2)-9+3", oex);
            Assert.AreEqual(-131, ex.Value);
        }