|
| 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 System.Linq; |
| 11 | +using Xunit; |
| 12 | +using static AngouriMath.Entity; |
| 13 | + |
| 14 | +namespace AngouriMath.Tests.Algebra.SolveTest |
| 15 | +{ |
| 16 | + /// <summary> |
| 17 | + /// Two branches of an elimination can reach one solution, and each was answered: two circles |
| 18 | + /// that meet at two points gave three rows, one of them the other again, and where the |
| 19 | + /// second branch went through Newton's method, again as a decimal. |
| 20 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/2138">#2138</a> |
| 21 | + /// </summary> |
| 22 | + [Trait("Area", "Algebra")] |
| 23 | + public sealed class DuplicateSystemRowTest |
| 24 | + { |
| 25 | + private static Matrix Solve(string first, string second) |
| 26 | + { |
| 27 | + var solved = MathS.Equations(first.ToEntity(), second.ToEntity()).Solve("x", "y"); |
| 28 | + Assert.NotNull(solved); |
| 29 | + return solved!; |
| 30 | + } |
| 31 | + |
| 32 | + private static bool HasRow(Matrix solutions, string x, string y) |
| 33 | + => Enumerable.Range(0, solutions.RowCount).Any(row => |
| 34 | + (solutions[row, 0] - x).Simplify() == 0 && (solutions[row, 1] - y).Simplify() == 0); |
| 35 | + |
| 36 | + [Theory] |
| 37 | + // the copy was a decimal: x = 1.4999999999999997 |
| 38 | + [InlineData("(x - 1/2)^2 + (y - sqrt(3)/2)^2 - 1", "0", "0", "3/2", "sqrt(3)/2")] |
| 39 | + // the copy was the same row again |
| 40 | + [InlineData("(x - 3/2)^2 + (y - sqrt(3)/2)^2 - 1", "1/2", "sqrt(3)/2", "2", "0")] |
| 41 | + public void TwoCirclesMeetingTwiceGiveTwoExactRows(string circle, string x1, string y1, string x2, string y2) |
| 42 | + { |
| 43 | + var solutions = Solve(circle, "(x - 1)^2 + y^2 - 1"); |
| 44 | + Assert.Equal(2, solutions.RowCount); |
| 45 | + Assert.True(HasRow(solutions, x1, y1), $"({x1}, {y1}) is not among {solutions}"); |
| 46 | + Assert.True(HasRow(solutions, x2, y2), $"({x2}, {y2}) is not among {solutions}"); |
| 47 | + Assert.DoesNotContain(solutions.Nodes, node => node is Number { IsExact: false }); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments