Пример #1
0
        public void TestMissmatchedParen()
        {
            var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
            var result    = converter.Convert("1+2)");

            Console.WriteLine(result);
        }
Пример #2
0
        public void TestDecimal()
        {
            var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
            var result    = string.Join(" ", converter.Convert("1.02 + 2.3 + 4"));
            var expected  = "1.02 2.3 + 4 +";

            Assert.AreEqual(expected, result);
        }
Пример #3
0
        public void TestBasicConvert()
        {
            var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
            var result    = string.Join(" ", converter.Convert("1+2"));
            var expected  = "1 2 +";

            Assert.AreEqual(expected, result);
        }
Пример #4
0
        public void TestMultipleParenthesis()
        {
            var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
            var result    = string.Join(" ", converter.Convert("7 * ((2 + 3) * 4)"));
            var expected  = "7 2 3 + 4 * *";

            Assert.AreEqual(expected, result);
        }
Пример #5
0
        public void TestOperatorPrecedence()
        {
            var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));

            var resultWithoutParen   = string.Join(" ", converter.Convert("1+2*3"));
            var expectedWithoutParen = "1 2 3 * +";

            var resultWithParen   = string.Join(" ", converter.Convert("(1+2)*3"));
            var expectedWithParen = "1 2 + 3 *";

            Assert.AreEqual(expectedWithoutParen, resultWithoutParen);
            Assert.AreEqual(expectedWithParen, resultWithParen);
        }
Пример #6
0
        public void TestArgumentSeparator()
        {
            var operators = new List <IEvaluatable <double> >
            {
                new Operator <double>("f", 2, Associativity.L, (a, b) => a * b),
                new Operator <double>("+", 2, Associativity.B, (a, b) => a * b)
            };

            var converter = new PostFixConverter(new EvaluatableCollection <double>(operators));
            var result    = string.Join(" ", converter.Convert("f(3+2,5)"));
            var expected  = "3 2 + 5 f";

            Assert.AreEqual(expected, result);
        }
Пример #7
0
        public void TestMultiMatchedOperator()
        {
            var operators = new List <IEvaluatable <double> >
            {
                new Operator <double>("*", 2, Associativity.B, (a, b) => a * b),
                new Operator <double>("**", 2, Associativity.B, (a, b) => a * b)
            };

            var converter = new PostFixConverter(new EvaluatableCollection <double>(operators));
            var result    = string.Join(" ", converter.Convert("2**3*5"));
            var expected  = "2 3 ** 5 *";

            Assert.AreEqual(expected, result);
        }
Пример #8
0
        public void TestMultiCharOperator()
        {
            var operators = new List <IEvaluatable <double> >
            {
                new Operator <double>("+", 1, Associativity.B, (a, b) => a * b, false),
                new Operator <double>("*", 2, Associativity.B, (a, b) => a * b, false),
                new Operator <double>("sin", 1, Associativity.R, Math.Sin)
            };
            var converter = new PostFixConverter(new EvaluatableCollection <double>(operators));
            var result    = string.Join(" ", converter.Convert("2+sin(2)"));
            var expected  = "2 2 sin +";

            Assert.AreEqual(expected, result);
        }
Пример #9
0
 public void TestUnknownOperator()
 {
     var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
     var result    = converter.Convert("5hello5");
 }
Пример #10
0
 public void TestMultipleDecimalPoints()
 {
     var converter = new PostFixConverter(new EvaluatableCollection <double>(Ops));
     var result    = converter.Convert("1.00.2 + 5");
 }