You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/04/09 11:34:42 UTC

[commons-numbers] branch master updated (424c6c3 -> c876c0c)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.


    from 424c6c3  Fraction: Add thrown exception to pow javadoc.
     new c572758  Add -0.0 to fraction constructor test cases.
     new 699897d  Added fraction power test cases
     new e0582a9  Remove BigFraction.pow(double).
     new 99c627e  Document and test for overflow in BigFraction.pow(int)
     new eea818d  Fraction: Add alternative zero to common test cases.
     new 6cabdbc  Fraction: Fix divide to return this if it is zero.
     new c876c0c  FractionTest: zero divide should be equal to Fraction.ZERO

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/numbers/fraction/BigFraction.java      |  13 +--
 .../apache/commons/numbers/fraction/Fraction.java  |   3 +
 .../commons/numbers/fraction/BigFractionTest.java  |  14 ++-
 .../commons/numbers/fraction/CommonTestCases.java  | 103 ++++++++++++++++++++-
 .../commons/numbers/fraction/FractionTest.java     |  23 ++---
 5 files changed, 122 insertions(+), 34 deletions(-)


[commons-numbers] 07/07: FractionTest: zero divide should be equal to Fraction.ZERO

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit c876c0c189061564905594111e336f7e588666a0
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:34:37 2020 +0100

    FractionTest: zero divide should be equal to Fraction.ZERO
    
    This relaxes the requirement that it is the same object as
    Fraction.ZERO.
---
 .../src/test/java/org/apache/commons/numbers/fraction/FractionTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
index 931b4c5..5644c72 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
@@ -314,7 +314,7 @@ public class FractionTest {
         Fraction f3 = Fraction.of(0, 5);
         Fraction f4 = Fraction.of(2, 7);
         Fraction f = f3.divide(f4);
-        Assertions.assertSame(Fraction.ZERO, f);
+        Assertions.assertEquals(Fraction.ZERO, f);
 
         final Fraction f5 = Fraction.of(Integer.MIN_VALUE, 1);
         Assertions.assertThrows(NullPointerException.class,


[commons-numbers] 04/07: Document and test for overflow in BigFraction.pow(int)

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 99c627e57e5bb14ada31f33809aa62356bfbb7bd
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:22:13 2020 +0100

    Document and test for overflow in BigFraction.pow(int)
---
 .../main/java/org/apache/commons/numbers/fraction/BigFraction.java | 1 +
 .../java/org/apache/commons/numbers/fraction/BigFractionTest.java  | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index ded343b..0d145fb 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -888,6 +888,7 @@ public final class BigFraction
      *
      * @param exponent exponent to which this {@code BigFraction} is to be raised.
      * @return <code>this<sup>exponent</sup></code>.
+     * @throws ArithmeticException if the intermediate result would overflow.
      */
     @Override
     public BigFraction pow(final int exponent) {
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 1f0f52e..40dc9e9 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -641,6 +641,13 @@ public class BigFractionTest {
             assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow(exponent));
         }
 
+        // Note: BigInteger magnitude is limited to 2^Integer.MAX_VALUE exclusive
+        // in the reference implementation (up to at least JDK 14).
+        Assertions.assertThrows(ArithmeticException.class, () -> BigFraction.of(2).pow(Integer.MAX_VALUE));
+        Assertions.assertThrows(ArithmeticException.class, () -> BigFraction.of(1, 2).pow(Integer.MAX_VALUE));
+        Assertions.assertThrows(ArithmeticException.class, () -> BigFraction.of(2).pow(-Integer.MAX_VALUE));
+        Assertions.assertThrows(ArithmeticException.class, () -> BigFraction.of(1, 2).pow(-Integer.MAX_VALUE));
+
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(13));
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(13L));
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(BigInteger.valueOf(13L)));


[commons-numbers] 06/07: Fraction: Fix divide to return this if it is zero.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 6cabdbc54d0af1976339e000217950a88b583e79
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:32:19 2020 +0100

    Fraction: Fix divide to return this if it is zero.
---
 .../src/main/java/org/apache/commons/numbers/fraction/Fraction.java    | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index fa7b377..c5a883d 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -633,6 +633,9 @@ public final class Fraction
         if (value.isZero()) {
             throw new FractionException(FractionException.ERROR_DIVIDE_BY_ZERO);
         }
+        if (isZero()) {
+            return this;
+        }
         return multiply(value.reciprocal());
     }
 


[commons-numbers] 03/07: Remove BigFraction.pow(double).

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit e0582a914b7901cfb840603a038e941fc975690c
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:12:38 2020 +0100

    Remove BigFraction.pow(double).
---
 .../org/apache/commons/numbers/fraction/BigFraction.java     | 12 ------------
 .../org/apache/commons/numbers/fraction/BigFractionTest.java |  1 -
 2 files changed, 13 deletions(-)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index a4a14a4..ded343b 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -954,18 +954,6 @@ public final class BigFraction
     }
 
     /**
-     * Returns a {@code double} whose value is
-     * <code>this<sup>exponent</sup></code>.
-     *
-     * @param exponent exponent to which this {@code BigFraction} is to be raised.
-     * @return <code>this<sup>exponent</sup></code> as a {@code double}.
-     */
-    public double pow(final double exponent) {
-        return Math.pow(numerator.doubleValue(),   exponent) /
-               Math.pow(denominator.doubleValue(), exponent);
-    }
-
-    /**
      * Returns the {@code String} representing this fraction.
      * Uses:
      * <ul>
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index a33cf1b..1f0f52e 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -653,7 +653,6 @@ public class BigFractionTest {
         Assertions.assertEquals(BigFraction.ZERO, BigFraction.of(0, 5).pow(123));
         Assertions.assertEquals(BigFraction.ZERO, BigFraction.of(0, 5).pow(123L));
         Assertions.assertEquals(BigFraction.ZERO, BigFraction.of(0, 5).pow(new BigInteger("112233445566778899")));
-        Assertions.assertEquals(Math.sqrt(2d / 3), BigFraction.of(2, 3).pow(0.5), 1e-15);
     }
 
     @Test


[commons-numbers] 05/07: Fraction: Add alternative zero to common test cases.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit eea818d1781314504e8de7fa6873005739117c7b
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:31:45 2020 +0100

    Fraction: Add alternative zero to common test cases.
    
    Zero can be 0 / 1 or 0 / -1.
    
    Zero divide is specified to return the original faction and not
    Fraction.ZERO.
---
 .../apache/commons/numbers/fraction/CommonTestCases.java    | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
index 3f1f343..efebc48 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
@@ -188,6 +188,8 @@ final class CommonTestCases {
         testCases.add(new UnaryOperatorTestCase(10, 21, 10, 21));
         testCases.add(new UnaryOperatorTestCase(-11, 23, 11, 23));
         testCases.add(new UnaryOperatorTestCase(13, -24, -13, -24));
+        testCases.add(new UnaryOperatorTestCase(0, 1, 0, 1));
+        testCases.add(new UnaryOperatorTestCase(0, -1, 0, -1));
 
         return testCases;
     }
@@ -220,6 +222,9 @@ final class CommonTestCases {
         testCases.add(new UnaryOperatorTestCase(-50, 75, 2, 3));
         testCases.add(new UnaryOperatorTestCase(Integer.MAX_VALUE - 1, Integer.MAX_VALUE, Integer.MIN_VALUE + 2, Integer.MAX_VALUE));
         testCases.add(new UnaryOperatorTestCase(1, Integer.MIN_VALUE, -1, Integer.MIN_VALUE));
+        // Negation of zero is a no-op
+        testCases.add(new UnaryOperatorTestCase(0, 1, 0, 1));
+        testCases.add(new UnaryOperatorTestCase(0, -1, 0, -1));
 
         // XXX Failed by "BigFraction" (whose implementation differs from "Fraction").
         // These are tested explicitly in FractionTest.
@@ -242,7 +247,9 @@ final class CommonTestCases {
         testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 7, 6));
         testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 4, 3));
         testCases.add(new BinaryOperatorTestCase(2, 3, 0, 5, 2, 3));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 0, -5, 2, 3));
         testCases.add(new BinaryOperatorTestCase(0, 7, 2, 3, 2, 3));
+        testCases.add(new BinaryOperatorTestCase(0, -7, 2, 3, 2, 3));
         testCases.add(new BinaryOperatorTestCase(2, 3, -2, 3, 0, 1));
 
         testCases.add(new BinaryOperatorTestCase(
@@ -290,6 +297,8 @@ final class CommonTestCases {
         testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 4, 3));
         testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 1, 1));
         testCases.add(new BinaryOperatorTestCase(0, 3, 2, 3, 0, 1));
+        // Return the original zero representation
+        testCases.add(new BinaryOperatorTestCase(0, -3, 2, 3, 0, -1));
 
         testCases.add(new BinaryOperatorTestCase(
                 2, 7,
@@ -320,7 +329,9 @@ final class CommonTestCases {
         testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 1, 3));
         testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 4, 9));
         testCases.add(new BinaryOperatorTestCase(0, 3, 2, 3, 0, 1));
+        testCases.add(new BinaryOperatorTestCase(0, -3, 2, 3, 0, 1));
         testCases.add(new BinaryOperatorTestCase(2, 3, 0, 3, 0, 1));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 0, -3, 0, 1));
 
         testCases.add(new BinaryOperatorTestCase(
                 Integer.MAX_VALUE, 1,
@@ -343,7 +354,9 @@ final class CommonTestCases {
         testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 1, 6));
         testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 0, 1));
         testCases.add(new BinaryOperatorTestCase(0, 3, 1, 5, -1, 5));
+        testCases.add(new BinaryOperatorTestCase(0, -3, 1, 5, -1, 5));
         testCases.add(new BinaryOperatorTestCase(2, 3, 0, 5, 2, 3));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 0, -5, 2, 3));
 
         // if this fraction is subtracted naively, it will overflow the int range.
         // check that it doesn't.


[commons-numbers] 01/07: Add -0.0 to fraction constructor test cases.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit c572758acfd7ddfc17554d42d89414a4574ed721
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 11:39:06 2020 +0100

    Add -0.0 to fraction constructor test cases.
---
 .../test/java/org/apache/commons/numbers/fraction/CommonTestCases.java   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
index a421421..f6b6a7f 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
@@ -166,6 +166,7 @@ final class CommonTestCases {
         testCases.add(new DoubleToFractionTestCase(0.40000000000001, 2, 5));
         testCases.add(new DoubleToFractionTestCase(15.0000000000001, 15, 1));
         testCases.add(new DoubleToFractionTestCase(0.0, 0, 1));
+        testCases.add(new DoubleToFractionTestCase(-0.0, 0, 1));
 
         return testCases;
     }


[commons-numbers] 02/07: Added fraction power test cases

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 699897ddf39225f27eff0baa06c27bbaa894d23f
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Apr 9 12:10:13 2020 +0100

    Added fraction power test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  |  6 ++
 .../commons/numbers/fraction/CommonTestCases.java  | 89 +++++++++++++++++++++-
 .../commons/numbers/fraction/FractionTest.java     | 21 ++---
 3 files changed, 96 insertions(+), 20 deletions(-)

diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index dfb104e..a33cf1b 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -635,6 +635,12 @@ public class BigFractionTest {
 
     @Test
     public void testPow() {
+        for (CommonTestCases.BinaryIntOperatorTestCase testCase : CommonTestCases.powFractionTestCases()) {
+            BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            int exponent = testCase.secondOperand;
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow(exponent));
+        }
+
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(13));
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(13L));
         Assertions.assertEquals(BigFraction.of(8192, 1594323), BigFraction.of(2, 3).pow(BigInteger.valueOf(13L)));
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
index f6b6a7f..3f1f343 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
@@ -72,6 +72,11 @@ final class CommonTestCases {
      */
     private static final List<BinaryOperatorTestCase> subtractFractionTestCasesList;
 
+    /**
+     * See {@link #powFractionTestCases()}
+     */
+    private static final List<BinaryIntOperatorTestCase> powFractionTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
@@ -82,6 +87,7 @@ final class CommonTestCases {
         divideByFractionTestCasesList = collectDivideByFractionTestCases();
         multiplyByFractionTestCasesList = collectMultiplyByFractionTestCases();
         subtractFractionTestCasesList = collectSubtractFractionTestCases();
+        powFractionTestCasesList = collectPowFractionTestCases();
     }
 
     private CommonTestCases() {}
@@ -362,10 +368,40 @@ final class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in
+     * {@link #powFractionTestCases()} and collects them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<BinaryIntOperatorTestCase> collectPowFractionTestCases() {
+        List<BinaryIntOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new BinaryIntOperatorTestCase(3, 7, 0, 1, 1));
+        testCases.add(new BinaryIntOperatorTestCase(3, 7, 1, 3, 7));
+        testCases.add(new BinaryIntOperatorTestCase(3, 7, -1, 7, 3));
+        testCases.add(new BinaryIntOperatorTestCase(3, 7, 2, 9, 49));
+        testCases.add(new BinaryIntOperatorTestCase(3, 7, -2, 49, 9));
+
+        testCases.add(new BinaryIntOperatorTestCase(3, -7, 0, 1, 1));
+        testCases.add(new BinaryIntOperatorTestCase(3, -7, 1, 3, -7));
+        testCases.add(new BinaryIntOperatorTestCase(3, -7, -1, -7, 3));
+        testCases.add(new BinaryIntOperatorTestCase(3, -7, 2, 9, 49));
+        testCases.add(new BinaryIntOperatorTestCase(3, -7, -2, 49, 9));
+
+        testCases.add(new BinaryIntOperatorTestCase(2, 3, 13, 8192, 1594323));
+        testCases.add(new BinaryIntOperatorTestCase(2, 3, -13, 1594323, 8192));
+
+        testCases.add(new BinaryIntOperatorTestCase(0, 1, Integer.MAX_VALUE, 0, 1));
+        testCases.add(new BinaryIntOperatorTestCase(0, -1, Integer.MAX_VALUE, 0, -1));
+
+        return testCases;
+    }
+
+    /**
      * Provides a list of test cases where a fraction should be created from
      * a specified numerator and denominator, both in the {@code int} range,
      * and the expected numerator and denominator of the created fraction are
      * also in the {@code int} range.
+     *
      * @return a list of test cases as described above
      */
     static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
@@ -377,6 +413,7 @@ final class CommonTestCases {
      * converted to a fraction with a certain amount of absolute error
      * allowed, and the expected numerator and denominator of the resulting
      * fraction are in the {@code int} range.
+     *
      * @return a list of test cases as described above
      */
     static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
@@ -400,6 +437,7 @@ final class CommonTestCases {
      * the {@code int} range, should be calculated, and the expected
      * numerator and denominator of the resulting fraction are also in the
      * {@code int} range.
+     *
      * @return a list of test cases as described above
      */
     static List<UnaryOperatorTestCase> reciprocalTestCases() {
@@ -411,6 +449,7 @@ final class CommonTestCases {
      * created from a specified numerator and denominator, both in the {@code
      * int} range, should be calculated, and the expected numerator and
      * denominator of the resulting fraction are also in the {@code int} range.
+     *
      * @return a list of test cases as described above
      */
     static List<UnaryOperatorTestCase> negateTestCases() {
@@ -429,12 +468,12 @@ final class CommonTestCases {
     }
 
     /**
-     * <p>Provides a list of test cases where a fraction, created from a
+     * Provides a list of test cases where a fraction, created from a
      * specified numerator and denominator in the {@code int} range, should
      * be divided by another fraction, also created from a specified
      * numerator and denominator in the {@code int} range, and the expected
      * numerator and denominator of the resulting fraction are in the {@code
-     * int} range as well.</p>
+     * int} range as well.
      *
      * <p>The first operand in each test case is the dividend and the second
      * operand is the divisor.</p>
@@ -452,6 +491,7 @@ final class CommonTestCases {
      * numerator and denominator in the {@code int} range, and the expected
      * numerator and denominator of the resulting fraction are in the {@code
      * int} range as well.
+     *
      * @return a list of test cases as described above
      */
     static List<BinaryOperatorTestCase> multiplyByFractionTestCases() {
@@ -459,12 +499,12 @@ final class CommonTestCases {
     }
 
     /**
-     * <p>Provides a list of test cases where a fraction, created from a
+     * Provides a list of test cases where a fraction, created from a
      * specified numerator and denominator in the {@code int} range, should
      * be subtracted from another fraction, also created from a specified
      * numerator and denominator in the {@code int} range, and the expected
      * numerator and denominator of the resulting fraction are in the {@code
-     * int} range as well.</p>
+     * int} range as well.
      *
      * <p>The first operand in each test case is the minuend and the second
      * operand is the subtrahend.</p>
@@ -475,6 +515,19 @@ final class CommonTestCases {
         return Collections.unmodifiableList(subtractFractionTestCasesList);
     }
 
+    /**
+     * Provides a list of test cases where a fraction, created from a
+     * specified numerator and denominator in the {@code int} range, should
+     * be raised to a specified power specified in the {@code int} range,
+     * and the expected numerator and denominator of the resulting fraction
+     * are in the {@code int} range as well.
+     *
+     * @return a list of test cases as described above
+     */
+    static List<BinaryIntOperatorTestCase> powFractionTestCases() {
+        return Collections.unmodifiableList(powFractionTestCasesList);
+    }
+
     // CHECKSTYLE: stop VisibilityModifier
 
     /**
@@ -533,6 +586,34 @@ final class CommonTestCases {
     }
 
     /**
+     * Represents a test case where a binary operation should be performed on
+     * a specified combination of numerator and denominator and a integer argument,
+     * with the numerator and denominator in the {@code int}
+     * range, and the numerator and denominator of the expected result are
+     * also in the {@code int} range.
+     */
+    static class BinaryIntOperatorTestCase {
+        final int firstOperandNumerator;
+        final int firstOperandDenominator;
+        final int secondOperand;
+        final int expectedNumerator;
+        final int expectedDenominator;
+
+        BinaryIntOperatorTestCase(
+                int firstOperandNumerator,
+                int firstOperandDenominator,
+                int secondOperand,
+                int expectedNumerator,
+                int expectedDenominator) {
+            this.firstOperandNumerator = firstOperandNumerator;
+            this.firstOperandDenominator = firstOperandDenominator;
+            this.secondOperand = secondOperand;
+            this.expectedNumerator = expectedNumerator;
+            this.expectedDenominator = expectedDenominator;
+        }
+    }
+
+    /**
      * Represents a test case where an operation that yields a fraction
      * should be performed on a {@code double} value and the numerator and
      * denominator of the expected result
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
index 2a5d5f1..931b4c5 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java
@@ -360,22 +360,11 @@ public class FractionTest {
 
     @Test
     public void testPow() {
-        Fraction a = Fraction.of(3, 7);
-        assertFraction(1, 1, a.pow(0));
-        assertFraction(3, 7, a.pow(1));
-        assertFraction(7, 3, a.pow(-1));
-        assertFraction(9, 49, a.pow(2));
-        assertFraction(49, 9, a.pow(-2));
-
-        Fraction b = Fraction.of(3, -7);
-        assertFraction(1, 1, b.pow(0));
-        assertFraction(3, -7, b.pow(1));
-        assertFraction(-7, 3, b.pow(-1));
-        assertFraction(9, 49, b.pow(2));
-        assertFraction(49, 9, b.pow(-2));
-
-        Fraction c = Fraction.of(0, -11);
-        assertFraction(0, -1, c.pow(Integer.MAX_VALUE));
+        for (CommonTestCases.BinaryIntOperatorTestCase testCase : CommonTestCases.powFractionTestCases()) {
+            Fraction f1 = Fraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            int exponent = testCase.secondOperand;
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow(exponent));
+        }
 
         Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(Integer.MAX_VALUE).pow(2));
         Assertions.assertThrows(ArithmeticException.class, () -> Fraction.of(1, Integer.MAX_VALUE).pow(2));