|
| 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 System.Collections.Generic; |
| 9 | +using AngouriMath; |
| 10 | +using AngouriMath.Core; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace AngouriMath.Tests.Common |
| 14 | +{ |
| 15 | + /// <summary> |
| 16 | + /// Every member here takes both an <see cref="IEnumerable{T}"/> and a <c>params Entity[]</c>. |
| 17 | + /// While <c>Entity</c> also had an implicit conversion from <c>List<Entity></c>, a list |
| 18 | + /// argument matched the params overload in its expanded form as well, neither candidate was |
| 19 | + /// better than the other, and none of these calls compiled -- CS0121. The conversion is gone; |
| 20 | + /// this file failing to compile is what says it has not come back. |
| 21 | + /// </summary> |
| 22 | + [Trait("Area", "Common")] |
| 23 | + public sealed class ListArgumentOverloadTest |
| 24 | + { |
| 25 | + static List<Entity> Equations => new() { "x - 1", "y - 2" }; |
| 26 | + |
| 27 | + [Fact] |
| 28 | + public void EquationSystemTakesAList() |
| 29 | + { |
| 30 | + var solutions = new EquationSystem(Equations).Solve("x", "y"); |
| 31 | + Assert.NotNull(solutions); |
| 32 | + Assert.Equal(1, solutions.RowCount); |
| 33 | + Assert.Equal(2, solutions.ColumnCount); |
| 34 | + } |
| 35 | + |
| 36 | + [Fact] |
| 37 | + public void MathSEquationsTakesAList() |
| 38 | + { |
| 39 | + var solutions = MathS.Equations(Equations).Solve("x", "y"); |
| 40 | + Assert.NotNull(solutions); |
| 41 | + Assert.Equal(1, solutions.RowCount); |
| 42 | + } |
| 43 | + |
| 44 | + [Fact] |
| 45 | + public void FiniteSetTakesAList() |
| 46 | + { |
| 47 | + var set = new Entity.Set.FiniteSet(new List<Entity> { 1, 2, 3 }); |
| 48 | + Assert.Equal(3, set.Count); |
| 49 | + } |
| 50 | + |
| 51 | + /// <summary>The array and variadic forms were never ambiguous, and must stay that way.</summary> |
| 52 | + [Fact] |
| 53 | + public void ArrayAndVariadicFormsStillBind() |
| 54 | + { |
| 55 | + Entity[] equations = { "x - 1", "y - 2" }; |
| 56 | + Assert.NotNull(new EquationSystem(equations).Solve("x", "y")); |
| 57 | + Assert.NotNull(new EquationSystem("x - 1", "y - 2").Solve("x", "y")); |
| 58 | + Assert.Equal(3, new Entity.Set.FiniteSet(1, 2, 3).Count); |
| 59 | + } |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// The conversion from an array is deliberately kept, so an array in an |
| 63 | + /// <c>Entity</c> position is still a set. |
| 64 | + /// </summary> |
| 65 | + [Fact] |
| 66 | + public void ArrayStillConvertsToASet() |
| 67 | + { |
| 68 | + Entity set = new Entity[] { 1, 2, 3 }; |
| 69 | + Assert.Equal(new Entity.Set.FiniteSet(1, 2, 3), set); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments