Upgraded AngouriMath to v2.8.0 (#1235)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-25 18:45:24 +01:00
1 parent fae3ceb840
commit 506c06fbfc
24 files changed
+974 -105

No files matched your search

@@ -9,6 +9,19 @@ public sealed class MathExpressionReaderTests
{
private static string Refusal(string text, string argumentName = "expression") => Assert.Throws<MathComputationException>(() => MathExpressionReader.Read(text, argumentName))!.Message;
private static string? RefusalOrNull(string text)
{
try
{
MathExpressionReader.Read(text, "expression");
return null;
}
catch (MathComputationException exception)
{
return exception.Message;
}
}
[Test]
public void ReadsTheSyntaxOfTheTools()
{
@@ -38,6 +51,62 @@ public sealed class MathExpressionReaderTests
}
}
[Test]
public void ReadsTheFunctionsTheToolsReturn()
{
using (Assert.EnterMultipleScope())
{
Assert.That(MathExpressionReader.Read("lambertw(0, 2)", "expression"), Is.TypeOf<Entity.LambertWf>());
Assert.That(MathExpressionReader.Read("productlog(2)", "expression"), Is.TypeOf<Entity.LambertWf>());
Assert.That(MathExpressionReader.Read("gamma(2, 1)", "expression"), Is.TypeOf<Entity.IncompleteGammaf>());
Assert.That(MathExpressionReader.Read("polygamma(1, 1)", "expression"), Is.TypeOf<Entity.Polygammaf>());
Assert.That(MathExpressionReader.Read("digamma(1)", "expression"), Is.TypeOf<Entity.Polygammaf>());
Assert.That(MathExpressionReader.Read("real + zeta_2", "expression"), Is.TypeOf<Entity.Sumf>(), "A variable may carry the name of a function the tools do not support.");
}
}
[Test]
public void RefusesTheFunctionsTheToolsDoNotSupport()
{
using (Assert.EnterMultipleScope())
{
foreach (var name in MathExpressionReader.UNSUPPORTED_FUNCTIONS)
Assert.That(Refusal($"1 + {name}(2)"), Is.EqualTo($"Argument 'expression' uses the function '{name}', which the tool does not support."));
Assert.That(Refusal("det([[1, 2], [3, 4]])", "lower_bound"), Is.EqualTo("Argument 'lower_bound' uses the function 'det', which the tool does not support."), "AngouriMath computes the determinant of a matrix written out while it parses.");
Assert.That(Refusal("n!!"), Is.EqualTo("Argument 'expression' contains 'n!!', which the tool does not support."));
Assert.That(Refusal("A[1, 2] + 1"), Is.EqualTo("Argument 'expression' contains 'A[1, 2]', which the tool does not support."));
Assert.That(Refusal("product(k, k in { 1, 2, 3 })"), Is.EqualTo("Argument 'expression' contains 'product(k, k in { 1, 2, 3 })', which the tool does not support."));
}
}
[Test]
public void NamesAFunctionTheParserRefuses()
{
using (Assert.EnterMultipleScope())
{
Assert.That(Refusal("trunc(2.5)"), Is.EqualTo("Argument 'expression' uses the function 'trunc', which the tool does not support."));
Assert.That(Refusal("1 + arcsinh(1)"), Is.EqualTo("Argument 'expression' uses the function 'arcsinh', which the tool does not support."));
Assert.That(Refusal("φ(12)"), Is.EqualTo("Argument 'expression' uses the function 'φ', which the tool does not support."));
Assert.That(Refusal("x!!!"), Is.EqualTo("Argument 'expression' uses a function or an operator which the tool does not support."));
}
}
[Test]
public void NoRefusalNamesTheLibrary()
{
var texts = ParserVocabulary.FunctionNames().SelectMany(name => new[] { $"{name}(2)", $"{name}(2, 3)", $"{name}(x)" }).Concat(["x!!!", "φ(12)", "ϕ(12)", "trunc(2.5)", "arcsinh(1)"]);
using (Assert.EnterMultipleScope())
{
foreach (var text in texts)
{
var refusal = RefusalOrNull(text);
if (refusal is not null)
Assert.That(refusal, Does.Not.Contain("AngouriMath").And.Not.Contain("C#").And.Not.Contain(".Evaled").And.Not.Contain("Simplify()").And.Not.Contain("MathS"), text);
}
}
}
[Test]
public void NamesTheMissingOperator()
{