public void CanNegate(string expression) { var original = MathElement.Parse(expression); var copy = original.Negated(); Assert.AreNotSame(original, copy); Assert.AreNotEqual(original.ToString(), copy.ToString()); var reverted = copy.Negated(); Assert.AreNotSame(original, reverted); Assert.AreEqual(original.ToString(), reverted.ToString()); }
public void NewtonMethodTests(string expression, double multiplicity, double startingPoint, double expected) { // Only testing the real part, as it makes it simpler to pass compile-time // inputs. The outcome should be the same for complex numbers, especially // given that the Complex library already existed var element = MathElement.Parse(expression); var newton = element.ToNewtonFunction(new Complex(multiplicity, 0)); var func = newton.ToFunc(); var options = new NewtonOptions { MaxIterations = 50, Precision = 1e-3, StartingPoint = new Complex(startingPoint, 0), }; var result = MathUtils.NewtonMethod(func, options); Assert.AreEqual(expected, result.Solution.Real, 1e-2); }
public string CanFormatExpression(string expression) { var element = MathElement.Parse(expression); return(element.ToString()); }
public void CanDetectMalformedExpressions(string expression) { Assert.Throws <ParseException>(() => MathElement.Parse(expression)); }