|
| 1 | +// |
| 2 | +// Copyright (c) 2019-2026 Angouri. |
| 3 | +// AngouriMath is licensed under MIT. |
| 4 | +// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md. |
| 5 | +// Website: https://am.angouri.org. |
| 6 | +// |
| 7 | + |
| 8 | +using AngouriMath; |
| 9 | +using AngouriMath.Extensions; |
| 10 | +using Xunit; |
| 11 | + |
| 12 | +namespace AngouriMath.Tests.Convenience |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// <c>max</c> and <c>min</c> are defined where both arguments are real, as their values are: the complex numbers are not |
| 16 | + /// ordered, and <c>max(i, i)</c> is <c>NaN</c>. Their condition said <c>True</c>, so <c>max(x, x)</c> simplified to |
| 17 | + /// <c>x</c>, which has a value at <c>x = i</c>. |
| 18 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/2256">#2256</a> |
| 19 | + /// </summary> |
| 20 | + [Trait("Area", "Convenience")] |
| 21 | + public sealed class MaxMinOffTheRealLineTest |
| 22 | + { |
| 23 | + [Theory] |
| 24 | + [InlineData("max(x, 2)", "i", false)] |
| 25 | + [InlineData("min(x, 2)", "1/2 + 6/5 * i", false)] |
| 26 | + [InlineData("max(x, 2)", "-3", true)] |
| 27 | + [InlineData("min(x, x)", "pi", true)] |
| 28 | + public void TheConditionIsWhereTheValueIs(string expression, string at, bool defined) |
| 29 | + { |
| 30 | + var condition = expression.ToEntity().DomainCondition.Substitute("x", at.ToEntity()).Evaled; |
| 31 | + Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition); |
| 32 | + // Where it is not defined, evaluation gives NaN or leaves the node, as max(i, 2) is left: no number. |
| 33 | + var value = expression.ToEntity().Substitute("x", at.ToEntity()).Evaled; |
| 34 | + Assert.Equal(defined, value is Entity.Number && !value.IsNaN); |
| 35 | + } |
| 36 | + |
| 37 | + [Theory] |
| 38 | + [InlineData("max(i, i)")] |
| 39 | + [InlineData("min(1 + i, 1 + i)")] |
| 40 | + public void OfAComplexNumberWithItselfItHasNoValue(string expression) |
| 41 | + { |
| 42 | + Assert.True(expression.ToEntity().Evaled.IsNaN, $"{expression} evaluates to {expression.ToEntity().Evaled}"); |
| 43 | + Assert.True(expression.ToEntity().Simplify().IsNaN, $"{expression} simplifies to {expression.ToEntity().Simplify()}"); |
| 44 | + } |
| 45 | + |
| 46 | + [Theory] |
| 47 | + [InlineData("max(x, x)")] |
| 48 | + [InlineData("min(x, x)")] |
| 49 | + public void ASimplificationHasNoValueWhereTheOriginalHasNone(string expression) |
| 50 | + { |
| 51 | + var simplified = expression.ToEntity().Simplify(); |
| 52 | + Assert.True(simplified.Substitute("x", "i".ToEntity()).Evaled.IsNaN, $"{simplified} at i"); |
| 53 | + Assert.Equal(Entity.Number.Integer.Create(3), simplified.Substitute("x", 3).Evaled); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments