|
| 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 | + |
| 11 | +namespace AngouriMath.Tests.Convenience |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// round of a rational is the nearest integer, exactly, and the even one at a tie, and an infinity is its own: through |
| 15 | + /// EDecimal a rational of more digits than the precision was rounded onto the integer beside it first, and |
| 16 | + /// round(10^120 + 2/3) came out 10^120, while round(+oo) threw OverflowException. floor and ceil had both defects and |
| 17 | + /// were fixed in #830 and #1807. |
| 18 | + /// <a href="https://github.com/asc-community/AngouriMath/issues/2282">#2282</a> |
| 19 | + /// </summary> |
| 20 | + [Trait("Area", "Convenience")] |
| 21 | + public sealed class RoundIsExactTest |
| 22 | + { |
| 23 | + [Theory] |
| 24 | + [InlineData("round(10^120 + 2/3)", "10^120 + 1")] |
| 25 | + [InlineData("round(10^120 - 2/3)", "10^120 - 1")] |
| 26 | + [InlineData("round(10^120 + 3/2)", "10^120 + 2")] |
| 27 | + [InlineData("round(10^120 + 1/2)", "10^120")] |
| 28 | + [InlineData("round(-10^120 - 2/3)", "-10^120 - 1")] |
| 29 | + [InlineData("round(-10^400 + 1/3)", "-10^400")] |
| 30 | + [InlineData("round(2/3)", "1")] |
| 31 | + [InlineData("round(5/2)", "2")] |
| 32 | + [InlineData("round(7/2)", "4")] |
| 33 | + [InlineData("round(-5/2)", "-2")] |
| 34 | + [InlineData("round(-7/2)", "-4")] |
| 35 | + [InlineData("round(+oo)", "+oo")] |
| 36 | + [InlineData("round(-oo)", "-oo")] |
| 37 | + public void ItIsTheNearestInteger(string input, string expected) |
| 38 | + { |
| 39 | + Assert.Equal(expected.ToEntity().InnerSimplified, input.ToEntity().InnerSimplified); |
| 40 | + Assert.Equal(expected.ToEntity().InnerSimplified, input.ToEntity().Evaled); |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments