コード例 #1
0
        public void TestMethod20()
        {
            JswCalculator jswCalculator = new JswCalculator();

            jswCalculator.EvaluateExpression("a=1");
            Assert.AreEqual(3, jswCalculator.EvaluateExpression("2+a"));
        }
コード例 #2
0
        public void TestMethod21()
        {
            JswCalculator jswCalculator = new JswCalculator();

            jswCalculator.EvaluateExpression("a7=1 + 2 ^ 3 * 2 - (5 * 2)");
            Assert.AreEqual(574, jswCalculator.EvaluateExpression("(1 + (43+ a7 + 515 + 2) - 35) + (26 + 8)+a7"));
        }
コード例 #3
0
        public void TestMethod23()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens1       = jswCalculator.GetTokens("1.5+2.1");

            jswCalculator.EvaluateExpression(Tokens1);
            Assert.AreEqual(3.6m, jswCalculator.EvaluateExpression(Tokens1));
        }
コード例 #4
0
        public void TestMethod22()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens1       = jswCalculator.GetTokens("a7=1 + 2 ^ 3 * 2 - (5 * 2)");

            jswCalculator.EvaluateExpression(Tokens1);
            var Tokens2 = jswCalculator.GetTokens("a574=(1 + (43+ a7 + 515 + 2) - 35) + (26 + 8)+a7");

            jswCalculator.EvaluateExpression(Tokens2);
            var Tokens3 = jswCalculator.GetTokens("a595=a574 + 3*a7");

            Assert.AreEqual(595, jswCalculator.EvaluateExpression(Tokens3));
        }
コード例 #5
0
        public void TestMethod24()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("1*(1.349+2.33)*0.3-1.0*4");

            Assert.AreEqual(-2.8963m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #6
0
        public void TestMethod18()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("(2+3*5)%4");

            Assert.AreEqual(1, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #7
0
        public void TestMethod15()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("1+2^3*2-(5*2)");

            Assert.AreEqual(7, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #8
0
        public void TestMethod14()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("2^3");

            Assert.AreEqual(8, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #9
0
        public void TestMethod25()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("2.0^3.5");

            Assert.AreEqual(11.3137084989848m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #10
0
        public void TestMethod9()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("(1+2)*3-4");

            Assert.AreEqual(5, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #11
0
        public void TestMethod11()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("(1+(43+515 +2)- 35)+( 26 +8)");

            Assert.AreEqual(560, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #12
0
        public void TestMethod7()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("1+2*3+4");

            Assert.AreEqual(11, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #13
0
        public void TestMethod34()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("5*ABS(6-NEG(10))");

            Assert.AreEqual(80m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #14
0
        public void TestMethod36()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("1+SQRT(16)*2");

            Assert.AreEqual(9m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #15
0
        public void TestMethod33()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("ABS(NEG(3))");

            Assert.AreEqual(3m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #16
0
        public void TestMethod13()
        {
            JswCalculator jswCalculator = new JswCalculator();
            var           Tokens        = jswCalculator.GetTokens("2-4-(8+2-6+(8+4-(1)+8-10))");

            Assert.AreEqual(-15, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #17
0
        public void TestMethod27()
        {
            Dictionary <string, CalFunction> specialPrecedence = new Dictionary <string, CalFunction> {
                { "+", new CalFunction {
                      name = "+", precedence = 2, operandNumber = 2, f = tokens => new Token(tokens[1].val + tokens[0].val)
                  } },
                { "-", new CalFunction {
                      name = "-", precedence = 2, operandNumber = 2, f = tokens => new Token(tokens[1].val - tokens[0].val)
                  } },
                { "*", new CalFunction {
                      name = "*", precedence = 1, operandNumber = 2, f = tokens => new Token(tokens[1].val * tokens[0].val)
                  } },
                { "/", new CalFunction {
                      name = "/", precedence = 1, operandNumber = 2, f = tokens => new Token(tokens[1].val / tokens[0].val)
                  } },
                { "(", new CalFunction {
                      name = "(", precedence = 1000, operandNumber = 0, f = null
                  } },
                { ")", new CalFunction {
                      name = ")", precedence = -1000, operandNumber = 0, f = null
                  } },
            };
            JswCalculator jswCalculator = new JswCalculator(specialPrecedence, null, null);
            var           Tokens        = jswCalculator.GetTokens("1+2*3+4");

            Assert.AreEqual((1 + 2) * (3 + 4), jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #18
0
        public void TestMethod28()
        {
            string        syntax        = @"(?<val>\d+\.\d+)|(?<op>\+|\-|\*|\/|\(|\)|\^|%|=)|(?<var>[A-Za-z]\w*)";
            JswCalculator jswCalculator = new JswCalculator(null, syntax, null);
            var           Tokens        = jswCalculator.GetTokens("1+2*3+4");

            jswCalculator.EvaluateExpression(Tokens);
        }
コード例 #19
0
        public void TestMethod29()
        {
            string        syntax        = @"(?<val>\d+\.\d+)|(?<op>\+|\-|\*|\/|\(|\)|\^|%|=)|(?<var>[A-Za-z]\w*)";
            JswCalculator jswCalculator = new JswCalculator(null, syntax, null);
            var           Tokens        = jswCalculator.GetTokens("1.0+2.0*3.0+4.0");

            Assert.AreEqual(11m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #20
0
        public void TestMethod26()
        {
            Dictionary <string, decimal> saved = new Dictionary <string, decimal> {
                { "a", 1.1m }
            };
            JswCalculator jswCalculator = new JswCalculator(null, null, saved);
            var           Tokens        = jswCalculator.GetTokens("2+a");

            Assert.AreEqual(3.1m, jswCalculator.EvaluateExpression(Tokens));
        }
コード例 #21
0
        public void TestMethod38()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(0.0000814939159201454283421497m, jswCalculator.EvaluateExpression("((((19) / 61))) / (65 / 97 * 88 * 75 / 81 * (70))"));
        }
コード例 #22
0
        public void TestMethod47()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(-4m, jswCalculator.EvaluateExpression("-3-(1))"));
        }
コード例 #23
0
        public void TestMethod37()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(28.27433388230811m, jswCalculator.EvaluateExpression("pi*3^2"));
        }
コード例 #24
0
        public void TestMethod44()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(7m, jswCalculator.EvaluateExpression("7"));
        }
コード例 #25
0
        public void TestMethod42()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(108.94642857142857142857142857m, jswCalculator.EvaluateExpression("93 - 17 + 15 / 4 * ((6)) / (28) * 41"));
        }
コード例 #26
0
        public void TestMethod41()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(-299.68616600790513833992094861m, jswCalculator.EvaluateExpression("(89) - 5 * 63 - (14) / 46 - (86) / (95 - (40)) * 6 - ((64))"));
        }
コード例 #27
0
        public void TestMethod40()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(-37m, jswCalculator.EvaluateExpression("((61) - (((98))))"));
        }
コード例 #28
0
        public void TestMethod39()
        {
            JswCalculator jswCalculator = new JswCalculator();

            Assert.AreEqual(4.0807828945168009283518119874m, jswCalculator.EvaluateExpression("(59 * 32 + 69 + 72 / 86) / ((15 * 38) + (77) / 100 - 91)"));
        }