This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
commit 0ac40c969eb22fca48e27cba295b68309e5e818e Author: Gary Gregory <[email protected]> AuthorDate: Sun Nov 15 07:58:13 2026 -0500 Expand Fraction power test coverage Test reduced and unreduced negative bases with positive and negative odd/even exponents, and -1 raised to both integer exponent limits. Verify that canonical and unreduced zero raised to zero return ONE. Assisted-By: OpenAI Codex --- .../apache/commons/lang3/math/FractionTest.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/math/FractionTest.java b/src/test/java/org/apache/commons/lang3/math/FractionTest.java index 7279cee7f..5b99be896 100644 --- a/src/test/java/org/apache/commons/lang3/math/FractionTest.java +++ b/src/test/java/org/apache/commons/lang3/math/FractionTest.java @@ -1141,6 +1141,40 @@ void testPow() { assertThrows(ArithmeticException.class, () -> Fraction.getFraction(65536, 1).pow(2)); } + @ParameterizedTest(name = "[{index}] ({0}/{1})^{2}") + @CsvSource({ + "-2, 3, 2, 4, 9", + "-2, 3, 3, -8, 27", + "-2, 3, -2, 9, 4", + "-2, 3, -3, -27, 8", + "-4, 6, 2, 4, 9", + "-4, 6, 3, -8, 27", + "-4, 6, -2, 9, 4", + "-4, 6, -3, -27, 8" + }) + void testPowNegativeBase(final int numerator, final int denominator, final int power, final int expectedNumerator, final int expectedDenominator) { + final Fraction result = Fraction.getFraction(numerator, denominator).pow(power); + assertEquals(expectedNumerator, result.getNumerator()); + assertEquals(expectedDenominator, result.getDenominator()); + } + + @ParameterizedTest(name = "[{index}] (-1)^{0}") + @CsvSource({ + "-2147483648, 1", + "2147483647, -1" + }) + void testPowNegativeOne(final int power, final int expectedNumerator) { + final Fraction result = Fraction.getFraction(-1, 1).pow(power); + assertEquals(expectedNumerator, result.getNumerator()); + assertEquals(1, result.getDenominator()); + } + + @Test + void testPowZeroToZero() { + assertSame(Fraction.ONE, Fraction.ZERO.pow(0)); + assertSame(Fraction.ONE, Fraction.getFraction(0, 5).pow(0)); + } + @Test void testReduce() { Fraction f;
