|
8 | 8 | using System; |
9 | 9 | using System.Linq; |
10 | 10 | using System.Threading.Tasks; |
| 11 | +using AngouriMath.Core.Exceptions; |
| 12 | +using AngouriMath.Core.Operations; |
11 | 13 | using AngouriMath.Extensions; |
12 | 14 | using PeterO.Numbers; |
13 | 15 | using Xunit; |
@@ -80,6 +82,50 @@ public void APowerOfALargePrimeHasItsTotient() |
80 | 82 | Within(() => "phi((2^89 - 1)^k)".ToEntity().Simplify())); |
81 | 83 | } |
82 | 84 |
|
| 85 | + /// <summary> |
| 86 | + /// An empty list is the factorisation of 1, so it answered 0, -1 and -12 as though each were 1. |
| 87 | + /// https://github.com/asc-community/AngouriMath/issues/2466 |
| 88 | + /// </summary> |
| 89 | + [Theory] |
| 90 | + [InlineData("0")] |
| 91 | + [InlineData("-1")] |
| 92 | + [InlineData("-12")] |
| 93 | + [InlineData("-18446744073709551616")] |
| 94 | + public void Issue2466_ANumberThatIsNotPositiveIsRefused(string number) |
| 95 | + { |
| 96 | + var integer = Integer.Create(EInteger.FromString(number)); |
| 97 | + Assert.Throws<InvalidNumberException>(() => MathS.NumberTheory.Factorize(integer)); |
| 98 | + Assert.Throws<InvalidNumberException>(() => integer.Factorize()); |
| 99 | + Assert.Throws<InvalidNumberException>(() => Catalogue.PrimeFactorization.Ask(integer)); |
| 100 | + } |
| 101 | + |
| 102 | + [Fact] |
| 103 | + public void Issue2466_OneIsTheEmptyProduct() |
| 104 | + => Assert.Empty(MathS.NumberTheory.Factorize(Integer.One)); |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// The functions of a factorisation do not ask <see cref="MathS.NumberTheory.Factorize"/>, and keep their |
| 108 | + /// own answers at 0 and below. https://github.com/asc-community/AngouriMath/issues/2466 |
| 109 | + /// </summary> |
| 110 | + [Theory] |
| 111 | + [InlineData("phi(0)", "0")] |
| 112 | + [InlineData("phi(-12)", "0")] |
| 113 | + [InlineData("divisorsigma(1, -12)", "NaN")] |
| 114 | + [InlineData("divisorsigma(1, 0)", "NaN")] |
| 115 | + [InlineData("mobius(-12)", "NaN")] |
| 116 | + [InlineData("primenu(-12)", "NaN")] |
| 117 | + [InlineData("primeomega(0)", "NaN")] |
| 118 | + [InlineData("valuation(-12, 2)", "2")] |
| 119 | + [InlineData("valuation(0, 2)", "+oo")] |
| 120 | + public void Issue2466_TheFunctionsOfAFactorisationKeepTheirAnswers(string input, string expected) |
| 121 | + => Assert.Equal(expected == "NaN" ? MathS.NaN : expected.ToEntity(), input.ToEntity().Evaled); |
| 122 | + |
| 123 | + [Theory] |
| 124 | + [InlineData("0")] |
| 125 | + [InlineData("-12")] |
| 126 | + public void Issue2466_DivisorsOfANumberThatIsNotPositiveStillCountZero(string number) |
| 127 | + => Assert.Equal(Integer.Zero, MathS.NumberTheory.CountDivisors(Integer.Create(EInteger.FromString(number)))); |
| 128 | + |
83 | 129 | private static T Within<T>(Func<T> evaluation) |
84 | 130 | { |
85 | 131 | var task = Task.Factory.StartNew(evaluation, TaskCreationOptions.LongRunning); |
|
0 commit comments