|
| 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.Extensions; |
| 9 | +using Xunit; |
| 10 | +using static AngouriMath.Entity.Set; |
| 11 | + |
| 12 | +namespace AngouriMath.Tests.Algebra |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// An equation written as an equality <c>a = b</c> is solved as <c>a - b = 0</c> where an expression |
| 16 | + /// equal to zero is expected, as a statement's own solve reads it. Passed on as it stood, a system |
| 17 | + /// answered that it had no solution, and <see cref="MathS.SolveEquation"/> answered a set builder |
| 18 | + /// with a false condition in it, which is empty. |
| 19 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/1673">#1673</a> |
| 20 | + /// </summary> |
| 21 | + [Trait("Area", "Algebra")] |
| 22 | + public sealed class AnEqualityReadAsADifferenceTest |
| 23 | + { |
| 24 | + [Theory] |
| 25 | + [InlineData("x + y = 3", "x - y = 1")] |
| 26 | + [InlineData("x + y = 3", "x - y - 1")] |
| 27 | + [InlineData("x + y - 3", "x - y = 1")] |
| 28 | + [InlineData("x = 3 - y", "y = x - 1")] |
| 29 | + public void ASystemOfEqualitiesIsSolved(string first, string second) |
| 30 | + { |
| 31 | + var solution = MathS.Equations(first.ToEntity(), second.ToEntity()).Solve("x", "y"); |
| 32 | + Assert.NotNull(solution); |
| 33 | + Assert.Equal(1, solution!.RowCount); |
| 34 | + Assert.Equal(2, (int)solution[0, 0].EvalNumerical().RealPart); |
| 35 | + Assert.Equal(1, (int)solution[0, 1].EvalNumerical().RealPart); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public void ASystemPrintsEachEquationAsADifferenceEqualToZero() |
| 40 | + => Assert.Equal("x + y - 3 = 0\nx - y - 1 = 0", MathS.Equations("x + y = 3".ToEntity(), "x - y = 1".ToEntity()).ToString()); |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void OneEqualityIsSolvedInItsVariable() |
| 44 | + => Assert.Equal(new FiniteSet(2), MathS.SolveEquation("x + 1 = 3", "x")); |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void TheExtensionReadsAnEqualityTheSameWay() |
| 48 | + => Assert.Equal(new FiniteSet(-2, 2), "x^2 = 4".SolveEquation("x")); |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void AnEqualityWithAParameterIsSolvedForTheVariable() |
| 52 | + => Assert.Equal(new FiniteSet("b / a".ToEntity().InnerSimplified), "a * x = b".ToEntity().SolveEquation("x").InnerSimplified); |
| 53 | + } |
| 54 | +} |
0 commit comments