public void CustomFunction() { var functions = new string[] { "f(x) = x", "g(x) = f(x + 2)" }; CompileResult result = InvariantCompiler.Compile(functions); result.IsSuccess.Should().BeTrue(); result.Functions.Count.Should().Be(2); result.Functions[0].Should().NotBeNull(); Func <double, double> g = result.Functions[1]; g.Should().NotBeNull(); g(0).Should().Be(2); g(-2).Should().Be(0); g(2).Should().Be(4); result.Functions[1](2).Should().Be(result.Functions[0](4)); }
public void CircularReference_ParseErrors() { CompileResult result = InvariantCompiler.Compile("f = x + f(x)"); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(e => e.Type == ErrorType.CyclicFunctions); }
public void FunctionName_InvalidChars() { CompileResult result = InvariantCompiler.Compile("a!= x"); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(e => e.Type == ErrorType.InvalidFunctionName); }
public void EmptyFunctionCallWithNegation_ParseErrors() { CompileResult result = InvariantCompiler.Compile("tan(-)"); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(e => e.Type == ErrorType.InvalidTerm); }
public void UnknownIdentifier() { CompileResult result = InvariantCompiler.Compile("a"); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(); CompileError error = result.Errors.Single(); error.Position.Should().Be(0); error.Type.Should().Be(ErrorType.UnknownIdentifier); }
public void MultipleDecimals() { CompileResult result = InvariantCompiler.Compile("5.7.11"); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(); CompileError error = result.Errors.Single(); error.Position.Should().Be(3); error.Type.Should().Be(ErrorType.InvalidNumber); }
public void SingleDecimal() { CompileResult result = InvariantCompiler.Compile("."); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(); CompileError error = result.Errors.Single(); error.Position.Should().Be(0); error.Type.Should().Be(ErrorType.InvalidTerm); }
public void EndsWithDecimal() { CompileResult result = InvariantCompiler.Compile("14."); result.IsSuccess.Should().BeFalse(); result.Errors.Should().ContainSingle(); CompileError error = result.Errors.Single(); error.Position.Should().Be(2); error.Type.Should().Be(ErrorType.InvalidNumber); }
public void GetDependentFunctions_SimpleGraph() { var functions = new string[] { "f(x) = x", "g(x) = f(x) + f(x) + 2", "h(x) = g(x) / 2" }; CompileResult result = InvariantCompiler.Compile(functions); result.IsSuccess.Should().BeTrue(); string[] dependents = result.GetDependentFunctions("f").ToArray(); dependents.Should().Contain(new string[] { "f", "g", "h" }); }
public void FractionalExponent_Unsupported(string value) { CompileResult result = InvariantCompiler.Compile(value); result.IsSuccess.Should().BeFalse(); }