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); }
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); }
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); }
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); }
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); }
public void UnaryOperatorPrecedence_Addition() { Func <double, double> function = InvariantCompiler.CompileFunction("-x+4+2"); double expectedValue = -10 + 4 + 2; function(10).Should().Be(expectedValue); }
public void UnaryOperatorPrecedence_Multiplication() { Func <double, double> function = InvariantCompiler.CompileFunction("-x*4+2"); double expectedValue = -2 * 4 + 2; function(2).Should().Be(expectedValue); }
public void UnaryOperatorPrecedence_Power() { Func <double, double> function = InvariantCompiler.CompileFunction("-2^x"); double expectedValue = -1 * Math.Pow(2, 10); function(10).Should().Be(expectedValue); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
public void ImpliedMultiplication_NumberFunction_NoSpace() { Func <double, double> function = InvariantCompiler.CompileFunction("2sin(x)"); function(0).Should().Be(0); }
public void FunctionCallWithMultiplArguments() { Func <double, double> function = InvariantCompiler.CompileFunction("log(x, 2)"); function(1).Should().Be(0); }
public void FunctionComposition() { Func <double, double> function = InvariantCompiler.CompileFunction("sin(cos(x))"); function.Should().NotBeNull(); }