|
| 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.Core; |
| 10 | +using AngouriMath.Extensions; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace AngouriMath.Tests.Convenience |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// A piecewise is defined under a reading where the case it takes is, as <see cref="Entity.DomainCondition"/> already |
| 17 | + /// reads it, where <see cref="Entity.DomainConditionIn(Domain)"/> asked every case to be defined: |
| 18 | + /// <c>tan(piecewise(pi / x provided x > 0, x / 2))</c> is 0 at 0, and its condition over the reals failed there. |
| 19 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/2256">#2256</a> |
| 20 | + /// </summary> |
| 21 | + [Trait("Area", "Convenience")] |
| 22 | + public sealed class PiecewiseConditionInAReadingTest |
| 23 | + { |
| 24 | + [Theory] |
| 25 | + [InlineData("tan(piecewise(pi / x provided x > 0, x / 2))", "0", true)] |
| 26 | + [InlineData("tan(piecewise(pi / x provided x > 0, x / 2))", "-2", true)] |
| 27 | + [InlineData("tan(piecewise(pi / x provided x > 0, x / 2))", "2", false)] |
| 28 | + [InlineData("piecewise(arccos(1 / x) provided x > 0, sec(sgn(x)))", "-1/2", true)] |
| 29 | + [InlineData("piecewise(arccos(1 / x) provided x > 0, sec(sgn(x)))", "1/2", false)] |
| 30 | + [InlineData("piecewise(sqrt(x) provided x > 0, 1)", "-4", true)] |
| 31 | + [InlineData("piecewise(sqrt(x - 1) provided x > 0, 1)", "1/2", false)] |
| 32 | + public void OverTheRealsItIsWhereTheCaseItTakesIs(string expression, string at, bool defined) |
| 33 | + { |
| 34 | + var condition = expression.ToEntity().DomainConditionIn(Domain.Real).Substitute("x", at.ToEntity()).Evaled; |
| 35 | + Assert.Equal(defined ? Entity.Boolean.True : Entity.Boolean.False, condition); |
| 36 | + } |
| 37 | + |
| 38 | + /// <summary>Over the complex numbers it is what <see cref="Entity.DomainCondition"/> says.</summary> |
| 39 | + [Theory] |
| 40 | + [InlineData("tan(piecewise(pi / x provided x > 0, x / 2))", "0")] |
| 41 | + [InlineData("tan(piecewise(pi / x provided x > 0, x / 2))", "2")] |
| 42 | + [InlineData("piecewise(sqrt(x - 1) provided x > 0, 1)", "1/2")] |
| 43 | + public void OverTheComplexNumbersItIsTheDomainCondition(string expression, string at) |
| 44 | + => Assert.Equal( |
| 45 | + expression.ToEntity().DomainCondition.Substitute("x", at.ToEntity()).Evaled, |
| 46 | + expression.ToEntity().DomainConditionIn(Domain.Complex).Substitute("x", at.ToEntity()).Evaled); |
| 47 | + } |
| 48 | +} |
0 commit comments