示例#1
0
 public void ZeroTest()
 {
     using (var parser = ParserFactory.CreateDefault())
     {
         Assert.AreEqual("ноль", parser.SumProp(0, "М", "В"));
     }
 }
示例#2
0
 public void NegativeTest()
 {
     using (var parser = ParserFactory.CreateDefault())
     {
         Assert.AreEqual("минус ста пятьюдесятью четырьмя тысячами тремястами двадцатью тремя", parser.SumProp(-154323, "М", "Т"));
     }
 }
示例#3
0
 public void FunctionsTest()
 {
     using (var parser = ParserFactory.CreateDefault())
     {
         Assert.AreEqual(parser.Process("abs(-1)"), Math.Abs(-1));
         Assert.AreEqual(parser.Process("abs(22)"), Math.Abs(22));
     }
 }
示例#4
0
        public void RulesTest()
        {
            using (var parser = ParserFactory.CreateDefault())
            {
                Assert.AreEqual("тридцати одного", parser.SumProp(31, "М", "Р"));
                Assert.AreEqual("двадцатью двумя", parser.SumProp(22, "С", "Т"));
                Assert.AreEqual("сто пятьдесят четыре тысячи триста двадцать три", parser.SumProp(154323, "М", "И"));
                Assert.AreEqual("ста пятьюдесятью четырьмя тысячами тремястами двадцатью тремя", parser.SumProp(154323, "М", "Т"));


                Assert.AreEqual("ноль", parser.SumProp(0, "М", "В"));
            }
        }
示例#5
0
        public void ParenthesisTest()
        {
            using (var parser = ParserFactory.CreateDefault())
            {
                Assert.AreEqual(parser.Process("(10)"), (10));
                Assert.AreEqual(parser.Process("((10))"), ((10)));
                Assert.AreEqual(parser.Process("(((10)))"), (((10))));


                Assert.AreEqual(parser.Process("(-5)"), (-5));
                Assert.AreEqual(parser.Process("(-6.7)"), (-6.7));
            }
        }
示例#6
0
        public void DecimalPointTest()
        {
            using (var parser = ParserFactory.CreateDefault())
            {
                //decimal point depends on current culture; ',' for ru-RU
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU");
                Assert.AreEqual(parser.Process("1/0,5"), 1 / 0.5);
                Assert.AreEqual(parser.Process("-5,5"), -5.5);

                //'.' for en-GB
                CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
                Assert.AreEqual(parser.Process("1/0.5"), 1 / 0.5);
                Assert.AreEqual(parser.Process("-5.5"), -5.5);
            }
        }
示例#7
0
        public void OperationsTest()
        {
            using (var parser = ParserFactory.CreateDefault())
            {
                Assert.AreEqual(parser.Process("1+2"), 1 + 2);
                Assert.AreEqual(parser.Process("1-2"), 1 - 2);
                Assert.AreEqual(parser.Process("1*2"), 1 * 2);
                Assert.AreEqual(parser.Process("1/2"), 1 / 2.0);
                Assert.AreEqual(parser.Process("-1"), -1);
                Assert.AreEqual(parser.Process("-1,6"), -1.6);

                Assert.AreEqual(parser.Process("(1-(2))"), (1 - (2)));
                Assert.AreEqual(parser.Process("3+2*6-1"), 3 + 2 * 6 - 1);
                Assert.AreEqual(parser.Process("3-2*6-1"), 3 - 2 * 6 - 1);
                Assert.AreEqual(parser.Process("1-2-3-(4-(5-(6-7)))"), 1 - 2 - 3 - (4 - (5 - (6 - 7))));
                Assert.AreEqual(parser.Process("3-(5-6)-(2-(3-(1-2)))"), 3 - (5 - 6) - (2 - (3 - (1 - 2))));
                Assert.AreEqual(parser.Process("3-(5-6)-(2-(3-(1+2)))+2-(-1+7)*(9-2)/((16-3)-3)+15/2*5"),
                                3 - (5 - 6) - (2 - (3 - (1 + 2))) + 2 - (-1 + 7) * (9 - 2) / ((16.0 - 3) - 3.0) + 15 / 2.0 * 5);
                Assert.AreEqual(parser.Process("(-1+7)*(9-2)"), (-1 + 7) * (9 - 2));
                Assert.AreEqual(parser.Process("((16-3)-3)+15/2*5"), ((16 - 3) - 3) + 15 / 2.0 * 5);
                Assert.AreEqual(parser.Process("1+15/2*5"), 1 + 15 / 2.0 * 5);
                Assert.AreEqual(parser.Process("3-2/6-1,8"), 3 - 2 / 6.0 - 1.8);
            }
        }