Example #1
0
        public void TestVariableMultiplication()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("10a")),
                                       new Dictionary <char, string> {
                { 'a', "2" }
            }
                                       );

            Assert.AreEqual("20", output);
        }
Example #2
0
        public void TestVariablePow()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("pow(2,a)")),
                                       new Dictionary <char, string> {
                { 'a', "2" }
            }
                                       );

            Assert.AreEqual("4", output);
        }
Example #3
0
        public void TestVariableComplement()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("~a")),
                                       new Dictionary <char, string> {
                { 'a', "5" }
            }
                                       );

            Assert.AreEqual("-6", output);
        }
Example #4
0
        public void TestMixture1()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("12+(0.5*a)-1")),
                                       new Dictionary <char, string> {
                { 'a', "2" }
            }
                                       );

            Assert.AreEqual("12", output);
        }
Example #5
0
        public void TestVariableXor()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("10^a")),
                                       new Dictionary <char, string> {
                { 'a', "5" }
            }
                                       );

            Assert.AreEqual("15", output);
        }
Example #6
0
        public void TestMixture5()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("a*5+(a/3)")),
                                       new Dictionary <char, string>
            {
                { 'a', "6" }
            });

            Assert.AreEqual("32", output);
        }
Example #7
0
        public void TestMixture6()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("a*2 - (-1)")),
                                       new Dictionary <char, string>
            {
                { 'a', "0.5" }
            });

            Assert.AreEqual("2", output);
        }
Example #8
0
 public void TestDecimalOnesCompl()
 {
     try
     {
         var obj = MathFunc.Eval(MathFunc.Parsing(TL.Scan("~0.5")));
     }
     catch (Exception ae)
     {
         Assert.AreEqual("Math Error: decimal numbers are incompatible with logic operations", ae.Message);
     }
 }
Example #9
0
        public void TestMixture4()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("pow(2,3)-sin(45)+5b")),
                                       new Dictionary <char, string>
            {
                { 'b', "2" }
            }
                                       );

            Assert.AreEqual("17.149096475465882", output);
        }
Example #10
0
 public void TestInvalidSymbol()
 {
     try
     {
         var obj = MathFunc.Eval(MathFunc.Parsing(TL.Scan("#")));
     }
     catch (Exception ae)
     {
         Assert.AreEqual("Unknown symbol while tokenizing", ae.Message);
     }
 }
Example #11
0
 public void TestEmptyString()
 {
     try
     {
         var obj = MathFunc.Eval(MathFunc.Parsing(TL.Scan(" ")));
     }
     catch (Exception ae)
     {
         Assert.AreEqual("Empty String", ae.Message);
     }
 }
Example #12
0
 public void TestDecimalXor()
 {
     try
     {
         var obj = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0.5^0.2")));
     }
     catch (Exception ae)
     {
         Assert.AreEqual("Invalid antiunitary operation", ae.Message);
     }
 }
Example #13
0
        public void TestMixture2()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("a+b-c*(d/e)")),
                                       new Dictionary <char, string>
            {
                { 'a', "2" },
                { 'b', "4" },
                { 'c', "7" },
                { 'd', "4" },
                { 'e', "2" }
            });

            Assert.AreEqual("-8", output);
        }
Example #14
0
        public void TestWholeDivision()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("5684/4")));

            Assert.AreEqual("1421", output);
        }
Example #15
0
        public void TestDecimalBrackets()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0.5*(1.5-0.3)")));

            Assert.AreEqual("0.6", output);
        }
Example #16
0
        public void TestDecimalSin()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("sin(0.5)")));

            Assert.AreEqual("0.479425538604203", output);
        }
Example #17
0
        public void TestDecimalCos()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("cos(0.5)")));

            Assert.AreEqual("0.8775825618903728", output);
        }
Example #18
0
        public void TestDecimalTan()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("tan(0.5)")));

            Assert.AreEqual("0.5463024898437905", output);
        }
Example #19
0
        public void TestDecimalDivision()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("1.6/0.5")));

            Assert.AreEqual("3.2", output);
        }
Example #20
0
        public void TestWholeSubstraction()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("1000-999")));

            Assert.AreEqual("1", output);
        }
Example #21
0
 public void TestWholeNumber()
 {
     Assert.AreEqual("1", MathFunc.Eval(MathFunc.Parsing(TL.Scan("1"))));
 }
Example #22
0
        public void TestDecimalZero()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0*0.55")));

            Assert.AreEqual("0", output);
        }
Example #23
0
        public void TestDecimalNegative()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("-0.5+1")));

            Assert.AreEqual("0.5", output);
        }
Example #24
0
        public void TestDecimalPow()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("pow(0.5,0.3)")));

            Assert.AreEqual("0.8122523963562356", output);
        }
Example #25
0
        public void TestWholeAddition()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("25+32")));

            Assert.AreEqual("57", output);
        }
Example #26
0
        public void TestDeciamlSubstraction()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0.6-0.4")));

            Assert.AreEqual("0.2", output);
        }
Example #27
0
        public void TestWholeMult()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("122*14")));

            Assert.AreEqual("1708", output);
        }
Example #28
0
        public void TestDecimalMult()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0.4*0.5")));

            Assert.AreEqual("0.2", output);
        }
Example #29
0
        public void TestWholeBrackets()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("2*(4-3)")));

            Assert.AreEqual("2", output);
        }
Example #30
0
        public void TestDecimalAddition()
        {
            var output = MathFunc.Eval(MathFunc.Parsing(TL.Scan("0.25+0.5")));

            Assert.AreEqual("0.75", output);
        }