コード例 #1
0
        public void ParameterAddition()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("x + 1");

            function(0).Should().Be(1);
            function(1).Should().Be(2);
            function(-1).Should().Be(0);
        }
コード例 #2
0
        public void FunctionCallWithVariable_SinFunction()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("sin(x)");

            function(0).Should().Be(0);
            function(0.5 * Math.PI).Should().BeApproximately(1, 1E-15);
            function(Math.PI).Should().BeApproximately(0, 1E-15);
        }
コード例 #3
0
        public void VariableOnly_LinearFunction()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("x");

            function(0).Should().Be(0);
            function(1).Should().Be(1);
            function(-1).Should().Be(-1);
        }
コード例 #4
0
        public void ImpliedMultiplication_NumberVariable(string expression)
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(expression);

            function(0).Should().Be(0);
            function(1).Should().Be(2);
            function(-1).Should().Be(-2);
        }
コード例 #5
0
        public void Constant(double value)
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(value.ToString());

            function(0).Should().Be(value);
            function(-100).Should().Be(value);
            function(100).Should().Be(value);
        }
コード例 #6
0
        public void UnaryOperatorPrecedence_Addition()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("-x+4+2");

            double expectedValue = -10 + 4 + 2;

            function(10).Should().Be(expectedValue);
        }
コード例 #7
0
        public void UnaryOperatorPrecedence_Multiplication()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("-x*4+2");

            double expectedValue = -2 * 4 + 2;

            function(2).Should().Be(expectedValue);
        }
コード例 #8
0
        public void UnaryOperatorPrecedence_Power()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("-2^x");

            double expectedValue = -1 * Math.Pow(2, 10);

            function(10).Should().Be(expectedValue);
        }
コード例 #9
0
        public void ConstantAddition(string expression, double expectedValue)
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(expression);

            function(0).Should().Be(expectedValue);
            function(-100).Should().Be(expectedValue);
            function(100).Should().Be(expectedValue);
        }
コード例 #10
0
        public void UnaryMinus_Whitespace()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(" -  x ");

            function(0).Should().Be(0);
            function(1).Should().Be(-1);
            function(-1).Should().Be(1);
        }
コード例 #11
0
        public void UnaryMinus_Number()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(" -  5.3 ");

            const double expectedValue = -5.3;

            function(0).Should().Be(expectedValue);
            function(1).Should().Be(expectedValue);
            function(-1).Should().Be(expectedValue);
        }
コード例 #12
0
        public void Pi()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("pi");

            const double expectedValue = Math.PI;

            function(0).Should().Be(expectedValue);
            function(5).Should().Be(expectedValue);
            function(-5).Should().Be(expectedValue);
        }
コード例 #13
0
        public void NegativeExponent()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("-4E-10");

            const double expectedValue = -4E-10;

            function(0).Should().Be(expectedValue);
            function(5).Should().Be(expectedValue);
            function(-5).Should().Be(expectedValue);
        }
コード例 #14
0
        public void PositiveExponent(string value)
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(value);

            const double expectedValue = 1E10;

            function(0).Should().Be(expectedValue);
            function(500).Should().Be(expectedValue);
            function(-500).Should().Be(expectedValue);
        }
コード例 #15
0
        public void BeginsWithDecimal()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(".5");

            const double expectedValue = 0.5;

            function(0).Should().Be(expectedValue);
            function(1).Should().Be(expectedValue);
            function(-1).Should().Be(expectedValue);
        }
コード例 #16
0
        public void E()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("e");

            const double expectedValue = Math.E;

            function(0).Should().Be(expectedValue);
            function(0.1).Should().Be(expectedValue);
            function(-0.1).Should().Be(expectedValue);
        }
コード例 #17
0
        public void ConstantMultiplication(string expression, double expectedValue)
        {
            Func <double, double> function = InvariantCompiler.CompileFunction(expression);

            const double precision = 10E-6;

            function(0).Should().BeApproximately(expectedValue, precision);
            function(-5).Should().BeApproximately(expectedValue, precision);
            function(5).Should().BeApproximately(expectedValue, precision);
        }
コード例 #18
0
        public void OrderOfOperations()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("2^3+5*2-6/3");

            const double expectedValue = 16;

            function(0).Should().Be(expectedValue);
            function(100).Should().Be(expectedValue);
            function(-100).Should().Be(expectedValue);
        }
コード例 #19
0
        public void Exponents_RightAssociative()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("4^3^2");

            const double expectedValue = 262144;

            function(0).Should().Be(expectedValue);
            function(1).Should().Be(expectedValue);
            function(-1).Should().Be(expectedValue);
        }
コード例 #20
0
        public void ImpliedMultiplication_NumberFunction_NoSpace()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("2sin(x)");

            function(0).Should().Be(0);
        }
コード例 #21
0
        public void FunctionCallWithMultiplArguments()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("log(x, 2)");

            function(1).Should().Be(0);
        }
コード例 #22
0
        public void FunctionComposition()
        {
            Func <double, double> function = InvariantCompiler.CompileFunction("sin(cos(x))");

            function.Should().NotBeNull();
        }