You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/06/22 13:33:14 UTC

[commons-numbers] branch master updated (7b36cbf -> 860adcd)

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

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


    from 7b36cbf  Merge branch 'NUMBERS-116__heinrich'
     new 55e1ab8  NUMBERS-118: Extract common num-den-constructor and double-constructor test cases
     new 86f4b89  NUMBERS-118: Generalize test case types
     new b7d3c7f  NUMBERS-118: Organize population of test case lists into methods
     new 12a73b0  NUMBERS-118: Collect stray test cases for double constructor
     new 8b2ab21  NUMBERS-118: Extract common abs test cases and add some overall Javadoc
     new 9f66153  NUMBERS-118: Extract common reciprocal test cases and clarify Javadoc
     new 27a4aa1  NUMBERS-118: Extract common negate test cases
     new f15ac5b  NUMBERS-118: Make class CommonTestCases package-private and correct Javadoc mistake
     new 2d5783c  NUMBERS-118: Extract common add-fraction test cases
     new 19ef2b2  NUMBERS-118: Extract one more common add-fraction test case
     new 7427fd0  NUMBERS-118: Extract common divide-by-fraction test cases
     new 2e41297  NUMBERS-118: Extract common multiply-by-fraction test cases
     new c45802d  NUMBERS-118: Extract common subtract-fraction test cases
     new 625361b  NUMBERS-118: Format Javadoc and update comment not relevant for BigFraction
     new 860adcd  Merge branch 'NUMBERS-118__heinrich'

The 15 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/BigFractionTest.java  | 270 +++--------
 .../commons/numbers/fraction/CommonTestCases.java  | 507 +++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 268 ++---------
 3 files changed, 618 insertions(+), 427 deletions(-)
 create mode 100644 commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java


[commons-numbers] 14/15: NUMBERS-118: Format Javadoc and update comment not relevant for BigFraction

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

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

commit 625361b58b878aec5cddc2e23b2435ddc633854a
Author: Schamschi <he...@gmx.at>
AuthorDate: Fri Jun 21 15:17:08 2019 +0200

    NUMBERS-118: Format Javadoc and update comment not relevant for BigFraction
---
 .../commons/numbers/fraction/CommonTestCases.java  | 150 ++++++++++++---------
 1 file changed, 83 insertions(+), 67 deletions(-)

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 c35b018..3b71c72 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
@@ -5,10 +5,9 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- * A collection of test cases that can be applied both
- * to {@link Fraction} and {@link BigFraction}, e.g.
- * for operations and expected results that involve
- * numerators and denominators in the {@code int} range.
+ * A collection of test cases that can be applied both to {@link Fraction}
+ * and {@link BigFraction}, e.g. for operations and expected results that
+ * involve numerators and denominators in the {@code int} range.
  */
 class CommonTestCases {
     /**
@@ -69,8 +68,9 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #numDenConstructorTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in
+     * {@link #numDenConstructorTestCases()} and collects them into a {@code
+     * List}.
      * @return a list of test cases as described above
      */
     private static List<UnaryOperatorTestCase> collectNumDenConstructorTestCases() {
@@ -90,8 +90,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #doubleConstructorTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in
+     * {@link #doubleConstructorTestCases()} and collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<DoubleToFractionTestCase> collectDoubleConstructorTestCases() {
@@ -147,8 +147,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #absTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in {@link #absTestCases()} and
+     * collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<UnaryOperatorTestCase> collectAbsTestCases() {
@@ -162,8 +162,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #reciprocalTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in {@link #reciprocalTestCases()} and
+     * collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<UnaryOperatorTestCase> collectReciprocalTestCases() {
@@ -178,8 +178,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #negateTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in {@link #negateTestCases()} and
+     * collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<UnaryOperatorTestCase> collectNegateTestCases() {
@@ -193,8 +193,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #addFractionTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in {@link #addFractionTestCases()} and
+     * collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<BinaryOperatorTestCase> collectAddFractionTestCases() {
@@ -210,7 +210,7 @@ class CommonTestCases {
                 -2, 13*17*2,
                 -17 - 2*13*2, 13*13*17*2*2));
 
-        // if this fraction is added naively, it will overflow.
+        // if this fraction is added naively, it will overflow the int range.
         // check that it doesn't.
         testCases.add(new BinaryOperatorTestCase(
                 1, 32768 * 3,
@@ -231,8 +231,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #divideByFractionTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in
+     * {@link #divideByFractionTestCases()} and collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<BinaryOperatorTestCase> collectDivideByFractionTestCases() {
@@ -260,8 +260,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #multiplyByFractionTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in
+     * {@link #multiplyByFractionTestCases()} and collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<BinaryOperatorTestCase> collectMultiplyByFractionTestCases() {
@@ -281,8 +281,8 @@ class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #subtractFractionTestCases()} and collects
-     * them into a {@code List}.
+     * Defines test cases as described in
+     * {@link #subtractFractionTestCases()} and collects them into a {@code List}.
      * @return a list of test cases as described above
      */
     private static List<BinaryOperatorTestCase> collectSubtractFractionTestCases() {
@@ -293,7 +293,7 @@ class CommonTestCases {
         testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 1, 6));
         testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 0, 1));
 
-        // if this fraction is subtracted naively, it will overflow.
+        // if this fraction is subtracted naively, it will overflow the int range.
         // check that it doesn't.
         testCases.add(new BinaryOperatorTestCase(
                 1, 32768 * 3,
@@ -316,9 +316,10 @@ class CommonTestCases {
     }
 
     /**
-     * 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.
+     * 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() {
@@ -326,9 +327,10 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where a {@code double} value should be 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.
+     * Provides a list of test cases where a {@code double} value should be
+     * 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() {
@@ -336,10 +338,10 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where the absolute value of a fraction 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.
+     * Provides a list of test cases where the absolute value of a fraction
+     * 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> absTestCases() {
@@ -347,10 +349,11 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where the multiplicative inverse of a fraction 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.
+     * Provides a list of test cases where the multiplicative inverse of a
+     * fraction 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> reciprocalTestCases() {
@@ -358,10 +361,10 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where the additive inverse of a fraction 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.
+     * Provides a list of test cases where the additive inverse of a fraction
+     * 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() {
@@ -369,9 +372,10 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where two fractions, each created from a specified numerator and denominator
-     * in the {@code int} range, should be added, and the expected numerator and denominator of the resulting fraction
-     * are also in the {@code int} range.
+     * Provides a list of test cases where two fractions, each created from a
+     * specified numerator and denominator in the {@code int} range, should
+     * be added, 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<BinaryOperatorTestCase> addFractionTestCases() {
@@ -379,12 +383,15 @@ class CommonTestCases {
     }
 
     /**
-     * <p>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>
+     * <p>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>
      *
-     * <p>The first operand in each test case is the dividend and the second operand is the divisor.</p>
+     * <p>The first operand in each test case is the dividend and the second
+     * operand is the divisor.</p>
      *
      * @return a list of test cases as described above
      */
@@ -393,10 +400,12 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where a fraction, created from a specified numerator and denominator
-     * in the {@code int} range, should be multiplied 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.
+     * Provides a list of test cases where a fraction, created from a
+     * specified numerator and denominator in the {@code int} range, should
+     * be multiplied 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.
      * @return a list of test cases as described above
      */
     static List<BinaryOperatorTestCase> multiplyByFractionTestCases() {
@@ -404,12 +413,15 @@ class CommonTestCases {
     }
 
     /**
-     * <p>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>
+     * <p>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>
      *
-     * <p>The first operand in each test case is the minuend and the second operand is the subtrahend.</p>
+     * <p>The first operand in each test case is the minuend and the second
+     * operand is the subtrahend.</p>
      *
      * @return a list of test cases as described above
      */
@@ -418,9 +430,10 @@ class CommonTestCases {
     }
 
     /**
-     * Represents a test case where a unary operation should be performed on a specified combination
-     * of numerator and denominator, both in the {@code int} range, and the numerator and
-     * denominator of the expected result are also in the {@code int} range.
+     * Represents a test case where a unary operation should be performed on
+     * a specified combination of numerator and denominator, both in the
+     * {@code int} range, and the numerator and denominator of the expected
+     * result are also in the {@code int} range.
      */
     static class UnaryOperatorTestCase {
         final int operandNumerator;
@@ -441,9 +454,11 @@ class CommonTestCases {
     }
 
     /**
-     * Represents a test case where a binary operation should be performed on two specified combinations
-     * of numerator and denominator, with the numerator and denominator of each combination in the
-     * {@code int} range, and the numerator and denominator of the expected result are also in the {@code int} range.
+     * Represents a test case where a binary operation should be performed on
+     * two specified combinations of numerator and denominator, with the
+     * numerator and denominator of each combination in the {@code int}
+     * range, and the numerator and denominator of the expected result are
+     * also in the {@code int} range.
      */
     static class BinaryOperatorTestCase {
         final int firstOperandNumerator;
@@ -470,8 +485,9 @@ class CommonTestCases {
     }
 
     /**
-     * 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
+     * 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
      * are in the {@code int} range.
      */
     static class DoubleToFractionTestCase {


[commons-numbers] 09/15: NUMBERS-118: Extract common add-fraction test cases

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

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

commit 2d5783cb8a911fca8e886be57e74536e50eaf95c
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 17:05:12 2019 +0200

    NUMBERS-118: Extract common add-fraction test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  | 47 ++++--------
 .../commons/numbers/fraction/CommonTestCases.java  | 83 ++++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 40 ++---------
 3 files changed, 102 insertions(+), 68 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 1e17656..14422c2 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
@@ -286,8 +286,7 @@ public class BigFractionTest {
     public void testReciprocal() {
         for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.reciprocalTestCases()) {
             BigFraction f = BigFraction.of(testCase.operandNumerator, testCase.operandDenominator);
-            f = f.reciprocal();
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.reciprocal());
         }
 
         BigFraction f = BigFraction.of(0, 3);
@@ -302,20 +301,17 @@ public class BigFractionTest {
     public void testNegate() {
         for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.negateTestCases()) {
             BigFraction f = BigFraction.of(testCase.operandNumerator, testCase.operandDenominator);
-            f = f.negate();
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.negate());
         }
     }
 
     @Test
     public void testAdd() {
-        BigFraction a = BigFraction.of(1, 2);
-        BigFraction b = BigFraction.of(2, 3);
-
-        assertFraction(1, 1, a.add(a));
-        assertFraction(7, 6, a.add(b));
-        assertFraction(7, 6, b.add(a));
-        assertFraction(4, 3, b.add(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.addFractionTestCases()) {
+            BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            BigFraction f2 = BigFraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.add(f2));
+        }
 
         BigFraction f1 = BigFraction.of(Integer.MAX_VALUE - 1, 1);
         BigFraction f2 = BigFraction.ONE;
@@ -323,32 +319,13 @@ public class BigFractionTest {
         Assertions.assertEquals(Integer.MAX_VALUE, f.getNumeratorAsInt());
         Assertions.assertEquals(1, f.getDenominatorAsInt());
 
-        f1 = BigFraction.of(-1, 13 * 13 * 2 * 2);
-        f2 = BigFraction.of(-2, 13 * 17 * 2);
-        f = f1.add(f2);
-        Assertions.assertEquals(13 * 13 * 17 * 2 * 2, f.getDenominatorAsInt());
-        Assertions.assertEquals(-17 - 2 * 13 * 2, f.getNumeratorAsInt());
-
-        try {
-            f.add((BigFraction) null);
-            Assertions.fail("expecting NullPointerException");
-        } catch (NullPointerException ex) {
+        {
+            final BigFraction f3 = BigFraction.of(-17 - 2*13*2, 13*13*17*2*2);
+            Assertions.assertThrows(NullPointerException.class,
+                    () -> f3.add((BigFraction) null)
+            );
         }
 
-        // if this fraction is added naively, it will overflow.
-        // check that it doesn't.
-        f1 = BigFraction.of(1, 32768 * 3);
-        f2 = BigFraction.of(1, 59049);
-        f = f1.add(f2);
-        Assertions.assertEquals(52451, f.getNumeratorAsInt());
-        Assertions.assertEquals(1934917632, f.getDenominatorAsInt());
-
-        f1 = BigFraction.of(Integer.MIN_VALUE, 3);
-        f2 = BigFraction.of(1, 3);
-        f = f1.add(f2);
-        Assertions.assertEquals(Integer.MIN_VALUE + 1, f.getNumeratorAsInt());
-        Assertions.assertEquals(3, f.getDenominatorAsInt());
-
         f1 = BigFraction.of(Integer.MAX_VALUE - 1, 1);
         f = f1.add(BigInteger.ONE);
         Assertions.assertEquals(Integer.MAX_VALUE, f.getNumeratorAsInt());
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 17e3596..6208698 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
@@ -36,12 +36,18 @@ class CommonTestCases {
      */
     private static final List<UnaryOperatorTestCase> negateTestCasesList;
 
+    /**
+     * See {@link #addFractionTestCases()}
+     */
+    private static final List<BinaryOperatorTestCase> addFractionTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
         absTestCasesList = collectAbsTestCases();
         reciprocalTestCasesList = collectReciprocalTestCases();
         negateTestCasesList = collectNegateTestCases();
+        addFractionTestCasesList = collectAddFractionTestCases();
     }
 
     /**
@@ -169,6 +175,44 @@ class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in {@link #addFractionTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<BinaryOperatorTestCase> collectAddFractionTestCases() {
+        List<BinaryOperatorTestCase> testCases = new ArrayList<>();
+
+        {
+            int[] a = new int[]{1, 2};
+            int[] b = new int[]{2, 3};
+
+            testCases.add(new BinaryOperatorTestCase(a[0], a[1], a[0], a[1], 1, 1));
+            testCases.add(new BinaryOperatorTestCase(a[0], a[1], b[0], b[1], 7, 6));
+            testCases.add(new BinaryOperatorTestCase(b[0], b[1], a[0], a[1], 7, 6));
+            testCases.add(new BinaryOperatorTestCase(b[0], b[1], b[0], b[1], 4, 3));
+        }
+
+        testCases.add(new BinaryOperatorTestCase(
+                -1, 13*13*2*2,
+                -2, 13*17*2,
+                -17 - 2*13*2, 13*13*17*2*2));
+
+        // if this fraction is added naively, it will overflow.
+        // check that it doesn't.
+        testCases.add(new BinaryOperatorTestCase(
+                1, 32768 * 3,
+                1, 59049,
+                52451, 1934917632));
+
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MIN_VALUE, 3,
+                1, 3,
+                Integer.MIN_VALUE + 1, 3));
+
+        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.
@@ -222,6 +266,16 @@ class CommonTestCases {
     }
 
     /**
+     * Provides a list of test cases where two fractions, each created from a specified numerator and denominator
+     * in the {@code int} range, should be added, 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<BinaryOperatorTestCase> addFractionTestCases() {
+        return Collections.unmodifiableList(addFractionTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
@@ -245,6 +299,35 @@ class CommonTestCases {
     }
 
     /**
+     * Represents a test case where a binary operation should be performed on two specified combinations
+     * of numerator and denominator, with the numerator and denominator of each combination in the
+     * {@code int} range, and the numerator and denominator of the expected result are also in the {@code int} range.
+     */
+    static class BinaryOperatorTestCase {
+        final int firstOperandNumerator;
+        final int firstOperandDenominator;
+        final int secondOperandNumerator;
+        final int secondOperandDenominator;
+        final int expectedNumerator;
+        final int expectedDenominator;
+
+        BinaryOperatorTestCase(
+                int firstOperandNumerator,
+                int firstOperandDenominator,
+                int secondOperandNumerator,
+                int secondOperandDenominator,
+                int expectedNumerator,
+                int expectedDenominator) {
+            this.firstOperandNumerator = firstOperandNumerator;
+            this.firstOperandDenominator = firstOperandDenominator;
+            this.secondOperandNumerator = secondOperandNumerator;
+            this.secondOperandDenominator = secondOperandDenominator;
+            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
      * are in the {@code int} range.
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 521741b..3915d3e 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
@@ -212,8 +212,7 @@ public class FractionTest {
     public void testReciprocal() {
         for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.reciprocalTestCases()) {
             Fraction f = Fraction.of(testCase.operandNumerator, testCase.operandDenominator);
-            f = f.reciprocal();
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.reciprocal());
         }
 
         {
@@ -228,8 +227,7 @@ public class FractionTest {
     public void testNegate() {
         for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.negateTestCases()) {
             Fraction f = Fraction.of(testCase.operandNumerator, testCase.operandDenominator);
-            f = f.negate();
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.negate());
         }
 
         {
@@ -242,14 +240,10 @@ public class FractionTest {
 
     @Test
     public void testAdd() {
-        {
-            Fraction a = Fraction.of(1, 2);
-            Fraction b = Fraction.of(2, 3);
-
-            assertFraction(1, 1, a.add(a));
-            assertFraction(7, 6, a.add(b));
-            assertFraction(7, 6, b.add(a));
-            assertFraction(4, 3, b.add(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.addFractionTestCases()) {
+            Fraction f1 = Fraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            Fraction f2 = Fraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.add(f2));
         }
 
         {
@@ -266,33 +260,13 @@ public class FractionTest {
         }
 
         {
-            Fraction f1 = Fraction.of(-1, 13*13*2*2);
-            Fraction f2 = Fraction.of(-2, 13*17*2);
-            final Fraction f = f1.add(f2);
-            assertFraction(-17 - 2*13*2, 13*13*17*2*2, f);
-
+            final Fraction f = Fraction.of(-17 - 2*13*2, 13*13*17*2*2);
             Assertions.assertThrows(NullPointerException.class,
                     () -> f.add(null)
             );
         }
 
         {
-            // if this fraction is added naively, it will overflow.
-            // check that it doesn't.
-            Fraction f1 = Fraction.of(1, 32768 * 3);
-            Fraction f2 = Fraction.of(1, 59049);
-            Fraction f = f1.add(f2);
-            assertFraction(52451, 1934917632, f);
-        }
-
-        {
-            Fraction f1 = Fraction.of(Integer.MIN_VALUE, 3);
-            Fraction f2 = Fraction.of(1, 3);
-            Fraction f = f1.add(f2);
-            assertFraction(Integer.MIN_VALUE + 1, 3, f);
-        }
-
-        {
             Fraction f1 = Fraction.of(Integer.MAX_VALUE - 1, 1);
             Fraction f2 = Fraction.ONE;
             final Fraction f = f1.add(f2);


[commons-numbers] 11/15: NUMBERS-118: Extract common divide-by-fraction test cases

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

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

commit 7427fd0639557f25a2d7274597be70882527ffd0
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 22:16:16 2019 +0200

    NUMBERS-118: Extract common divide-by-fraction test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  | 42 +++++----------
 .../commons/numbers/fraction/CommonTestCases.java  | 59 ++++++++++++++++++----
 .../commons/numbers/fraction/FractionTest.java     | 31 ++----------
 3 files changed, 67 insertions(+), 65 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 3245544..a16d35d 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
@@ -314,9 +314,9 @@ public class BigFractionTest {
         }
 
         {
-            final BigFraction f3 = BigFraction.of(-17 - 2*13*2, 13*13*17*2*2);
+            final BigFraction f = BigFraction.of(-17 - 2*13*2, 13*13*17*2*2);
             Assertions.assertThrows(NullPointerException.class,
-                    () -> f3.add((BigFraction) null)
+                    () -> f.add((BigFraction) null)
             );
         }
 
@@ -351,13 +351,11 @@ public class BigFractionTest {
 
     @Test
     public void testDivide() {
-        BigFraction a = BigFraction.of(1, 2);
-        BigFraction b = BigFraction.of(2, 3);
-
-        assertFraction(1, 1, a.divide(a));
-        assertFraction(3, 4, a.divide(b));
-        assertFraction(4, 3, b.divide(a));
-        assertFraction(1, 1, b.divide(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.divideByFractionTestCases()) {
+            BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            BigFraction f2 = BigFraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.divide(f2));
+        }
 
         BigFraction f1 = BigFraction.of(3, 5);
         BigFraction f2 = BigFraction.ZERO;
@@ -372,27 +370,11 @@ public class BigFractionTest {
         BigFraction f = f1.divide(f2);
         Assertions.assertSame(BigFraction.ZERO, f);
 
-        f1 = BigFraction.of(2, 7);
-        f2 = BigFraction.ONE;
-        f = f1.divide(f2);
-        Assertions.assertEquals(2, f.getNumeratorAsInt());
-        Assertions.assertEquals(7, f.getDenominatorAsInt());
-
-        f1 = BigFraction.of(1, Integer.MAX_VALUE);
-        f = f1.divide(f1);
-        Assertions.assertEquals(1, f.getNumeratorAsInt());
-        Assertions.assertEquals(1, f.getDenominatorAsInt());
-
-        f1 = BigFraction.of(Integer.MIN_VALUE, Integer.MAX_VALUE);
-        f2 = BigFraction.of(1, Integer.MAX_VALUE);
-        f = f1.divide(f2);
-        Assertions.assertEquals(Integer.MIN_VALUE, f.getNumeratorAsInt());
-        Assertions.assertEquals(1, f.getDenominatorAsInt());
-
-        try {
-            f.divide((BigFraction) null);
-            Assertions.fail("expecting NullPointerException");
-        } catch (NullPointerException ex) {
+        {
+            final BigFraction f3 = BigFraction.of(Integer.MIN_VALUE, 1);
+            Assertions.assertThrows(NullPointerException.class,
+                    () -> f3.divide((BigFraction) null)
+            );
         }
 
         f1 = BigFraction.of(Integer.MIN_VALUE, Integer.MAX_VALUE);
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 e405b48..c91f6e3 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
@@ -41,6 +41,11 @@ class CommonTestCases {
      */
     private static final List<BinaryOperatorTestCase> addFractionTestCasesList;
 
+    /**
+     * See {@link #divideByFractionTestCases()}
+     */
+    private static final List<BinaryOperatorTestCase> divideByFractionTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
@@ -48,6 +53,7 @@ class CommonTestCases {
         reciprocalTestCasesList = collectReciprocalTestCases();
         negateTestCasesList = collectNegateTestCases();
         addFractionTestCasesList = collectAddFractionTestCases();
+        divideByFractionTestCasesList = collectDivideByFractionTestCases();
     }
 
     /**
@@ -182,15 +188,10 @@ class CommonTestCases {
     private static List<BinaryOperatorTestCase> collectAddFractionTestCases() {
         List<BinaryOperatorTestCase> testCases = new ArrayList<>();
 
-        {
-            int[] a = new int[]{1, 2};
-            int[] b = new int[]{2, 3};
-
-            testCases.add(new BinaryOperatorTestCase(a[0], a[1], a[0], a[1], 1, 1));
-            testCases.add(new BinaryOperatorTestCase(a[0], a[1], b[0], b[1], 7, 6));
-            testCases.add(new BinaryOperatorTestCase(b[0], b[1], a[0], a[1], 7, 6));
-            testCases.add(new BinaryOperatorTestCase(b[0], b[1], b[0], b[1], 4, 3));
-        }
+        testCases.add(new BinaryOperatorTestCase(1, 2, 1, 2, 1, 1));
+        testCases.add(new BinaryOperatorTestCase(1, 2, 2, 3, 7, 6));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 7, 6));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 4, 3));
 
         testCases.add(new BinaryOperatorTestCase(
                 -1, 13*13*2*2,
@@ -218,6 +219,35 @@ class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in {@link #divideByFractionTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<BinaryOperatorTestCase> collectDivideByFractionTestCases() {
+        List<BinaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new BinaryOperatorTestCase(1, 2, 1, 2, 1, 1));
+        testCases.add(new BinaryOperatorTestCase(1, 2, 2, 3, 3, 4));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 4, 3));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 1, 1));
+
+        testCases.add(new BinaryOperatorTestCase(
+                2, 7,
+                1, 1,
+                2, 7));
+        testCases.add(new BinaryOperatorTestCase(
+                1, Integer.MAX_VALUE,
+                1, Integer.MAX_VALUE,
+                1, 1));
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MIN_VALUE, Integer.MAX_VALUE,
+                1, Integer.MAX_VALUE,
+                Integer.MIN_VALUE, 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.
@@ -281,6 +311,17 @@ class CommonTestCases {
     }
 
     /**
+     * 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.
+     * @return a list of test cases as described above
+     */
+    static List<BinaryOperatorTestCase> divideByFractionTestCases() {
+        return Collections.unmodifiableList(divideByFractionTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 84f16d6..4d71a39 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
@@ -302,14 +302,10 @@ public class FractionTest {
 
     @Test
     public void testDivide() {
-        {
-            Fraction a = Fraction.of(1, 2);
-            Fraction b = Fraction.of(2, 3);
-
-            assertFraction(1, 1, a.divide(a));
-            assertFraction(3, 4, a.divide(b));
-            assertFraction(4, 3, b.divide(a));
-            assertFraction(1, 1, b.divide(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.divideByFractionTestCases()) {
+            Fraction f1 = Fraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            Fraction f2 = Fraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.divide(f2));
         }
 
         {
@@ -328,24 +324,7 @@ public class FractionTest {
         }
 
         {
-            Fraction f1 = Fraction.of(2, 7);
-            Fraction f2 = Fraction.ONE;
-            Fraction f = f1.divide(f2);
-            assertFraction(2, 7, f);
-        }
-
-        {
-            Fraction f1 = Fraction.of(1, Integer.MAX_VALUE);
-            Fraction f = f1.divide(f1);
-            assertFraction(1, 1, f);
-        }
-
-        {
-            Fraction f1 = Fraction.of(Integer.MIN_VALUE, Integer.MAX_VALUE);
-            Fraction f2 = Fraction.of(1, Integer.MAX_VALUE);
-            final Fraction f = f1.divide(f2);
-            assertFraction(Integer.MIN_VALUE, 1, f);
-
+            final Fraction f = Fraction.of(Integer.MIN_VALUE, 1);
             Assertions.assertThrows(NullPointerException.class,
                     () -> f.divide(null)
             );


[commons-numbers] 02/15: NUMBERS-118: Generalize test case types

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

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

commit 86f4b8946109d75b243443f1117203fa87d9c020
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 11:26:11 2019 +0200

    NUMBERS-118: Generalize test case types
---
 .../commons/numbers/fraction/BigFractionTest.java  |   8 +-
 .../commons/numbers/fraction/CommonTestCases.java  | 143 +++++++++++----------
 .../commons/numbers/fraction/FractionTest.java     |   8 +-
 3 files changed, 80 insertions(+), 79 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 8a5b9dd..ab79b07 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
@@ -39,11 +39,11 @@ public class BigFractionTest {
 
     @Test
     public void testConstructor() {
-        for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
             assertFraction(
                     testCase.expectedNumerator,
                     testCase.expectedDenominator,
-                    BigFraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+                    BigFraction.of(testCase.operandNumerator, testCase.operandDenominator)
             );
         }
 
@@ -98,11 +98,11 @@ public class BigFractionTest {
     // MATH-179
     @Test
     public void testDoubleConstructor() throws Exception {
-        for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+        for (CommonTestCases.DoubleToFractionTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
             assertFraction(
                     testCase.expectedNumerator,
                     testCase.expectedDenominator,
-                    BigFraction.from(testCase.constructorArgument, 1.0e-5, 100)
+                    BigFraction.from(testCase.operand, 1.0e-5, 100)
             );
         }
     }
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 cbaa029..cc6127f 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
@@ -11,111 +11,112 @@ import java.util.List;
  * numerators and denominators in the {@code int} range.
  */
 public class CommonTestCases {
-    private static final List<NumDenConstructorTestCase> numDenConstructorTestCasesList;
+    private static final List<UnaryOperatorTestCase> numDenConstructorTestCasesList;
 
-    private static final List<DoubleConstructorTestCase> doubleConstructorTestCasesList;
+    private static final List<DoubleToFractionTestCase> doubleConstructorTestCasesList;
 
     static {
         numDenConstructorTestCasesList = new ArrayList<>();
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 1, 0, 1));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 2, 0, 1));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, -1, 0, 1));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, 2, 1, 2));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, 4, 1, 2));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-1, 2, -1, 2));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, -2, -1, 2));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-2, 4, -1, 2));
-        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, -4, -1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 1, 0, 1));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 2, 0, 1));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, -1, 0, 1));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, 2, 1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, 4, 1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-1, 2, -1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, -2, -1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-2, 4, -1, 2));
+        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, -4, -1, 2));
 
         doubleConstructorTestCasesList = new ArrayList<>();
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/2d, 1, 2));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/3d, 1, 3));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/3d, 2, 3));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/4d, 1, 4));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/4d, 3, 4));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/5d, 1, 5));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/5d, 2, 5));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/5d, 3, 5));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/5d, 4, 5));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/6d, 1, 6));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/6d, 5, 6));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/7d, 1, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/7d, 2, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/7d, 3, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/7d, 4, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/7d, 5, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/7d, 6, 7));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/8d, 1, 8));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/8d, 3, 8));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/8d, 5, 8));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/8d, 7, 8));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/9d, 1, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/9d, 2, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/9d, 4, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/9d, 5, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/9d, 7, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/9d, 8, 9));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/10d, 1, 10));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/10d, 3, 10));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/10d, 7, 10));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/10d, 9, 10));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/11d, 1, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/11d, 2, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/11d, 3, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/11d, 4, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/11d, 5, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/11d, 6, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/11d, 7, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/11d, 8, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/11d, 9, 11));
-        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(10d/11d, 10, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/2d, 1, 2));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/3d, 1, 3));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/3d, 2, 3));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/4d, 1, 4));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/4d, 3, 4));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/5d, 1, 5));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/5d, 2, 5));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/5d, 3, 5));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/5d, 4, 5));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/6d, 1, 6));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/6d, 5, 6));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/7d, 1, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/7d, 2, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/7d, 3, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/7d, 4, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/7d, 5, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/7d, 6, 7));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/8d, 1, 8));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/8d, 3, 8));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/8d, 5, 8));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/8d, 7, 8));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/9d, 1, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/9d, 2, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/9d, 4, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/9d, 5, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/9d, 7, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/9d, 8, 9));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/10d, 1, 10));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/10d, 3, 10));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/10d, 7, 10));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/10d, 9, 10));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/11d, 1, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/11d, 2, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/11d, 3, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/11d, 4, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/11d, 5, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/11d, 6, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/11d, 7, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/11d, 8, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/11d, 9, 11));
+        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(10d/11d, 10, 11));
     }
 
-    public static List<NumDenConstructorTestCase> numDenConstructorTestCases() {
+    public static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
         return Collections.unmodifiableList(numDenConstructorTestCasesList);
     }
 
-    public static List<DoubleConstructorTestCase> doubleConstructorTestCases() {
+    public static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
         return Collections.unmodifiableList(doubleConstructorTestCasesList);
     }
 
     /**
-     * Represents a test case where a fraction should be created from a
-     * specified numerator and denominator, both in the {@code int} range.
+     * Represents a test case where a unary operation should be performed on a specified combination
+     * of numerator and denominator, both in the {@code int} range, and the numerator and
+     * denominator of the expected result are also in the {@code int} range.
      */
-    public static class NumDenConstructorTestCase {
-        public final int constructorNumerator;
-        public final int constructorDenominator;
+    public static class UnaryOperatorTestCase {
+        public final int operandNumerator;
+        public final int operandDenominator;
         public final int expectedNumerator;
         public final int expectedDenominator;
 
-        public NumDenConstructorTestCase(
-                int constructorNumerator,
-                int constructorDenominator,
+        public UnaryOperatorTestCase(
+                int operandNumerator,
+                int operandDenominator,
                 int expectedNumerator,
                 int expectedDenominator) {
-            this.constructorNumerator = constructorNumerator;
-            this.constructorDenominator = constructorDenominator;
+            this.operandNumerator = operandNumerator;
+            this.operandDenominator = operandDenominator;
             this.expectedNumerator = expectedNumerator;
             this.expectedDenominator = expectedDenominator;
         }
     }
 
     /**
-     * Represents a test case where a fraction should be created from a
-     * {@code double} value and the expected numerator and denominator
+     * 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
      * are in the {@code int} range.
      */
-    public static class DoubleConstructorTestCase {
-        public final double constructorArgument;
+    public static class DoubleToFractionTestCase {
+        public final double operand;
         public final int expectedNumerator;
         public final int expectedDenominator;
 
-        public DoubleConstructorTestCase(
-                double constructorArgument,
+        public DoubleToFractionTestCase(
+                double operand,
                 int expectedNumerator,
                 int expectedDenominator) {
-            this.constructorArgument = constructorArgument;
+            this.operand = operand;
             this.expectedNumerator = expectedNumerator;
             this.expectedDenominator = expectedDenominator;
         }
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 293ffbd..c47d51a 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
@@ -33,11 +33,11 @@ public class FractionTest {
 
     @Test
     public void testConstructor() {
-        for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
             assertFraction(
                     testCase.expectedNumerator,
                     testCase.expectedDenominator,
-                    Fraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+                    Fraction.of(testCase.operandNumerator, testCase.operandDenominator)
             );
         }
 
@@ -65,11 +65,11 @@ public class FractionTest {
     // MATH-179
     @Test
     public void testDoubleConstructor() throws Exception  {
-        for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+        for (CommonTestCases.DoubleToFractionTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
             assertFraction(
                     testCase.expectedNumerator,
                     testCase.expectedDenominator,
-                    Fraction.from(testCase.constructorArgument)
+                    Fraction.from(testCase.operand)
             );
         }
     }


[commons-numbers] 04/15: NUMBERS-118: Collect stray test cases for double constructor

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

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

commit 12a73b0eebd7ddade7e2370a40e219d8d9d0dca0
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 12:02:54 2019 +0200

    NUMBERS-118: Collect stray test cases for double constructor
---
 .../java/org/apache/commons/numbers/fraction/BigFractionTest.java     | 4 ----
 .../java/org/apache/commons/numbers/fraction/CommonTestCases.java     | 4 ++++
 .../test/java/org/apache/commons/numbers/fraction/FractionTest.java   | 4 ----
 3 files changed, 4 insertions(+), 8 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 ab79b07..6e050d2 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
@@ -52,10 +52,6 @@ public class BigFractionTest {
         assertFraction(11, 1, BigFraction.of(11l));
         assertFraction(11, 1, BigFraction.of(new BigInteger("11")));
 
-        assertFraction(0, 1, BigFraction.from(0.00000000000001, 1.0e-5, 100));
-        assertFraction(2, 5, BigFraction.from(0.40000000000001, 1.0e-5, 100));
-        assertFraction(15, 1, BigFraction.from(15.0000000000001, 1.0e-5, 100));
-
         Assertions.assertEquals(0.00000000000001, BigFraction.from(0.00000000000001).doubleValue(), 0.0);
         Assertions.assertEquals(0.40000000000001, BigFraction.from(0.40000000000001).doubleValue(), 0.0);
         Assertions.assertEquals(15.0000000000001, BigFraction.from(15.0000000000001).doubleValue(), 0.0);
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 cd68373..0a82549 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
@@ -81,6 +81,10 @@ public class CommonTestCases {
         testCases.add(new DoubleToFractionTestCase(9d/11d, 9, 11));
         testCases.add(new DoubleToFractionTestCase(10d/11d, 10, 11));
 
+        testCases.add(new DoubleToFractionTestCase(0.00000000000001, 0, 1));
+        testCases.add(new DoubleToFractionTestCase(0.40000000000001, 2, 5));
+        testCases.add(new DoubleToFractionTestCase(15.0000000000001, 15, 1));
+
         return testCases;
     }
 
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 c47d51a..510e4c3 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
@@ -48,10 +48,6 @@ public class FractionTest {
         Assertions.assertThrows(ArithmeticException.class,
                 () -> Fraction.of(1, Integer.MIN_VALUE)
         );
-
-        assertFraction(0, 1, Fraction.from(0.00000000000001));
-        assertFraction(2, 5, Fraction.from(0.40000000000001));
-        assertFraction(15, 1, Fraction.from(15.0000000000001));
     }
 
     @Test


[commons-numbers] 05/15: NUMBERS-118: Extract common abs test cases and add some overall Javadoc

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

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

commit 8b2ab21d8bc4e08ae6291339418487d9424da88f
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 13:18:53 2019 +0200

    NUMBERS-118: Extract common abs test cases and add some overall Javadoc
---
 .../commons/numbers/fraction/BigFractionTest.java  | 11 ++--
 .../commons/numbers/fraction/CommonTestCases.java  | 59 ++++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 11 ++--
 3 files changed, 67 insertions(+), 14 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 6e050d2..cd23162 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
@@ -276,13 +276,10 @@ public class BigFractionTest {
 
     @Test
     public void testAbs() {
-        BigFraction a = BigFraction.of(10, 21);
-        BigFraction b = BigFraction.of(-10, 21);
-        BigFraction c = BigFraction.of(10, -21);
-
-        assertFraction(10, 21, a.abs());
-        assertFraction(10, 21, b.abs());
-        assertFraction(10, 21, c.abs());
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.absTestCases()) {
+            BigFraction f = BigFraction.of(testCase.operandNumerator, testCase.operandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.abs());
+        }
     }
 
     @Test
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 0a82549..be03b21 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
@@ -11,15 +11,32 @@ import java.util.List;
  * numerators and denominators in the {@code int} range.
  */
 public class CommonTestCases {
+    /**
+     * See {@link #numDenConstructorTestCases()}
+     */
     private static final List<UnaryOperatorTestCase> numDenConstructorTestCasesList;
 
+    /**
+     * See {@link #doubleConstructorTestCases()}
+     */
     private static final List<DoubleToFractionTestCase> doubleConstructorTestCasesList;
 
+    /**
+     * See {@link #absTestCases()}
+     */
+    private static final List<UnaryOperatorTestCase> absTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
+        absTestCasesList = collectAbsTestCases();
     }
 
+    /**
+     * Defines test cases as described in {@link #numDenConstructorTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
     private static List<UnaryOperatorTestCase> collectNumDenConstructorTestCases() {
         List<UnaryOperatorTestCase> testCases = new ArrayList<>();
 
@@ -36,6 +53,11 @@ public class CommonTestCases {
         return testCases;
     }
 
+    /**
+     * Defines test cases as described in {@link #doubleConstructorTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
     private static List<DoubleToFractionTestCase> collectDoubleConstructorTestCases() {
         List<DoubleToFractionTestCase> testCases = new ArrayList<>();
 
@@ -88,15 +110,52 @@ public class CommonTestCases {
         return testCases;
     }
 
+    /**
+     * Defines test cases as described in {@link #collectAbsTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<UnaryOperatorTestCase> collectAbsTestCases() {
+        List<UnaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new UnaryOperatorTestCase(10, 21, 10, 21));
+        testCases.add(new UnaryOperatorTestCase(-10, 21, 10, 21));
+        testCases.add(new UnaryOperatorTestCase(10, -21, 10, 21));
+
+        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
+     */
     public static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
         return Collections.unmodifiableList(numDenConstructorTestCasesList);
     }
 
+    /**
+     * Provides a list of test cases where a {@code double} value should be 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
+     */
     public static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
         return Collections.unmodifiableList(doubleConstructorTestCasesList);
     }
 
     /**
+     * Provides a list of test cases where the absolute value of a fraction should be
+     * calculated, with both the operand's and the expected result's numerator and denominator
+     * in the {@code int} range.
+     * @return a list of test cases as described above
+     */
+    public static List<UnaryOperatorTestCase> absTestCases() {
+        return Collections.unmodifiableList(absTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 510e4c3..aa0daff 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
@@ -187,13 +187,10 @@ public class FractionTest {
 
     @Test
     public void testAbs() {
-        Fraction a = Fraction.of(10, 21);
-        Fraction b = Fraction.of(-10, 21);
-        Fraction c = Fraction.of(10, -21);
-
-        assertFraction(10, 21, a.abs());
-        assertFraction(10, 21, b.abs());
-        assertFraction(10, 21, c.abs());
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.absTestCases()) {
+            Fraction f = Fraction.of(testCase.operandNumerator, testCase.operandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f.abs());
+        }
     }
 
     @Test


[commons-numbers] 10/15: NUMBERS-118: Extract one more common add-fraction test case

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

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

commit 19ef2b25df3ef263159df7203df6ef32c190a400
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 20:30:05 2019 +0200

    NUMBERS-118: Extract one more common add-fraction test case
    
    In the process, remove a duplicate test case in FractionTest
---
 .../commons/numbers/fraction/BigFractionTest.java   | 10 ++--------
 .../commons/numbers/fraction/CommonTestCases.java   |  5 +++++
 .../commons/numbers/fraction/FractionTest.java      | 21 +++++----------------
 3 files changed, 12 insertions(+), 24 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 14422c2..3245544 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
@@ -313,12 +313,6 @@ public class BigFractionTest {
             assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.add(f2));
         }
 
-        BigFraction f1 = BigFraction.of(Integer.MAX_VALUE - 1, 1);
-        BigFraction f2 = BigFraction.ONE;
-        BigFraction f = f1.add(f2);
-        Assertions.assertEquals(Integer.MAX_VALUE, f.getNumeratorAsInt());
-        Assertions.assertEquals(1, f.getDenominatorAsInt());
-
         {
             final BigFraction f3 = BigFraction.of(-17 - 2*13*2, 13*13*17*2*2);
             Assertions.assertThrows(NullPointerException.class,
@@ -326,8 +320,8 @@ public class BigFractionTest {
             );
         }
 
-        f1 = BigFraction.of(Integer.MAX_VALUE - 1, 1);
-        f = f1.add(BigInteger.ONE);
+        BigFraction f1 = BigFraction.of(Integer.MAX_VALUE - 1, 1);
+        BigFraction f = f1.add(BigInteger.ONE);
         Assertions.assertEquals(Integer.MAX_VALUE, f.getNumeratorAsInt());
         Assertions.assertEquals(1, f.getDenominatorAsInt());
 
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 6208698..e405b48 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
@@ -209,6 +209,11 @@ class CommonTestCases {
                 1, 3,
                 Integer.MIN_VALUE + 1, 3));
 
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MAX_VALUE - 1, 1,
+                1, 1,
+                Integer.MAX_VALUE, 1));
+
         return testCases;
     }
 
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 3915d3e..84f16d6 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
@@ -248,15 +248,8 @@ public class FractionTest {
 
         {
             Fraction f1 = Fraction.of(Integer.MAX_VALUE - 1, 1);
-            {
-                Fraction f2 = Fraction.ONE;
-                Fraction f = f1.add(f2);
-                assertFraction(Integer.MAX_VALUE, 1, f);
-            }
-            {
-                Fraction f = f1.add(1);
-                assertFraction(Integer.MAX_VALUE, 1, f);
-            }
+            Fraction f = f1.add(1);
+            assertFraction(Integer.MAX_VALUE, 1, f);
         }
 
         {
@@ -267,15 +260,11 @@ public class FractionTest {
         }
 
         {
-            Fraction f1 = Fraction.of(Integer.MAX_VALUE - 1, 1);
-            Fraction f2 = Fraction.ONE;
-            final Fraction f = f1.add(f2);
-            assertFraction(Integer.MAX_VALUE, 1, f);
-
+            final Fraction f1 = Fraction.of(Integer.MAX_VALUE, 1);
             Assertions.assertThrows(ArithmeticException.class,
                     () -> {
-                        Fraction f3 = f.add(Fraction.ONE); // should overflow
-                        Assertions.fail("expecting ArithmeticException but got: " + f3.toString());
+                        Fraction f = f1.add(Fraction.ONE); // should overflow
+                        Assertions.fail("expecting ArithmeticException but got: " + f.toString());
                     }
             );
         }


[commons-numbers] 07/15: NUMBERS-118: Extract common negate test cases

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

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

commit 27a4aa18af2f5c27e82a2e93a8f67d4ea35f5162
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 14:51:22 2019 +0200

    NUMBERS-118: Extract common negate test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  | 23 ++++------------
 .../commons/numbers/fraction/CommonTestCases.java  | 32 ++++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 19 ++-----------
 3 files changed, 40 insertions(+), 34 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 857a385..1e17656 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
@@ -300,24 +300,11 @@ public class BigFractionTest {
 
     @Test
     public void testNegate() {
-        BigFraction f = null;
-
-        f = BigFraction.of(50, 75);
-        f = f.negate();
-        Assertions.assertEquals(-2, f.getNumeratorAsInt());
-        Assertions.assertEquals(3, f.getDenominatorAsInt());
-
-        f = BigFraction.of(-50, 75);
-        f = f.negate();
-        Assertions.assertEquals(2, f.getNumeratorAsInt());
-        Assertions.assertEquals(3, f.getDenominatorAsInt());
-
-        // large values
-        f = BigFraction.of(Integer.MAX_VALUE - 1, Integer.MAX_VALUE);
-        f = f.negate();
-        Assertions.assertEquals(Integer.MIN_VALUE + 2, f.getNumeratorAsInt());
-        Assertions.assertEquals(Integer.MAX_VALUE, f.getDenominatorAsInt());
-
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.negateTestCases()) {
+            BigFraction f = BigFraction.of(testCase.operandNumerator, testCase.operandDenominator);
+            f = f.negate();
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+        }
     }
 
     @Test
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 82cb1e2..ad6e917 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
@@ -31,11 +31,17 @@ public class CommonTestCases {
      */
     private static final List<UnaryOperatorTestCase> reciprocalTestCasesList;
 
+    /**
+     * See {@link #negateTestCases()}
+     */
+    private static final List<UnaryOperatorTestCase> negateTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
         absTestCasesList = collectAbsTestCases();
         reciprocalTestCasesList = collectReciprocalTestCases();
+        negateTestCasesList = collectNegateTestCases();
     }
 
     /**
@@ -148,6 +154,21 @@ public class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in {@link #negateTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<UnaryOperatorTestCase> collectNegateTestCases() {
+        List<UnaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new UnaryOperatorTestCase(50, 75, -2, 3));
+        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));
+
+        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.
@@ -190,6 +211,17 @@ public class CommonTestCases {
     }
 
     /**
+     * Provides a list of test cases where the additive inverse of a fraction 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
+     */
+    public static List<UnaryOperatorTestCase> negateTestCases() {
+        return Collections.unmodifiableList(negateTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 543a06e..521741b 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
@@ -226,23 +226,10 @@ public class FractionTest {
 
     @Test
     public void testNegate() {
-        {
-            Fraction f = Fraction.of(50, 75);
-            f = f.negate();
-            assertFraction(-2, 3, f);
-        }
-
-        {
-            Fraction f = Fraction.of(-50, 75);
-            f = f.negate();
-            assertFraction(2, 3, f);
-        }
-
-        // large values
-        {
-            Fraction f = Fraction.of(Integer.MAX_VALUE - 1, Integer.MAX_VALUE);
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.negateTestCases()) {
+            Fraction f = Fraction.of(testCase.operandNumerator, testCase.operandDenominator);
             f = f.negate();
-            assertFraction(Integer.MIN_VALUE + 2, Integer.MAX_VALUE, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
         }
 
         {


[commons-numbers] 06/15: NUMBERS-118: Extract common reciprocal test cases and clarify Javadoc

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

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

commit 9f6615301679650cb0ec23a1549c0ea7dc8f6e87
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 14:08:35 2019 +0200

    NUMBERS-118: Extract common reciprocal test cases and clarify Javadoc
---
 .../commons/numbers/fraction/BigFractionTest.java  | 29 ++++------------
 .../commons/numbers/fraction/CommonTestCases.java  | 40 ++++++++++++++++++++--
 .../commons/numbers/fraction/FractionTest.java     | 25 ++------------
 3 files changed, 46 insertions(+), 48 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 cd23162..857a385 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
@@ -284,35 +284,18 @@ public class BigFractionTest {
 
     @Test
     public void testReciprocal() {
-        BigFraction f = null;
-
-        f = BigFraction.of(50, 75);
-        f = f.reciprocal();
-        Assertions.assertEquals(3, f.getNumeratorAsInt());
-        Assertions.assertEquals(2, f.getDenominatorAsInt());
-
-        f = BigFraction.of(4, 3);
-        f = f.reciprocal();
-        Assertions.assertEquals(3, f.getNumeratorAsInt());
-        Assertions.assertEquals(4, f.getDenominatorAsInt());
-
-        f = BigFraction.of(-15, 47);
-        f = f.reciprocal();
-        Assertions.assertEquals(-47, f.getNumeratorAsInt());
-        Assertions.assertEquals(15, f.getDenominatorAsInt());
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.reciprocalTestCases()) {
+            BigFraction f = BigFraction.of(testCase.operandNumerator, testCase.operandDenominator);
+            f = f.reciprocal();
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
+        }
 
-        f = BigFraction.of(0, 3);
+        BigFraction f = BigFraction.of(0, 3);
         try {
             f = f.reciprocal();
             Assertions.fail("expecting ArithmeticException");
         } catch (ArithmeticException ignored) {
         }
-
-        // large values
-        f = BigFraction.of(Integer.MAX_VALUE, 1);
-        f = f.reciprocal();
-        Assertions.assertEquals(1, f.getNumeratorAsInt());
-        Assertions.assertEquals(Integer.MAX_VALUE, f.getDenominatorAsInt());
     }
 
     @Test
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 be03b21..82cb1e2 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
@@ -26,10 +26,16 @@ public class CommonTestCases {
      */
     private static final List<UnaryOperatorTestCase> absTestCasesList;
 
+    /**
+     * See {@link #reciprocalTestCases()}
+     */
+    private static final List<UnaryOperatorTestCase> reciprocalTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
         absTestCasesList = collectAbsTestCases();
+        reciprocalTestCasesList = collectReciprocalTestCases();
     }
 
     /**
@@ -126,6 +132,22 @@ public class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in {@link #reciprocalTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<UnaryOperatorTestCase> collectReciprocalTestCases() {
+        List<UnaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new UnaryOperatorTestCase(50, 75, 3, 2));
+        testCases.add(new UnaryOperatorTestCase(4, 3, 3, 4));
+        testCases.add(new UnaryOperatorTestCase(-15, 47, -47, 15));
+        testCases.add(new UnaryOperatorTestCase(Integer.MAX_VALUE, 1, 1, Integer.MAX_VALUE));
+
+        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.
@@ -146,9 +168,10 @@ public class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where the absolute value of a fraction should be
-     * calculated, with both the operand's and the expected result's numerator and denominator
-     * in the {@code int} range.
+     * Provides a list of test cases where the absolute value of a fraction 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
      */
     public static List<UnaryOperatorTestCase> absTestCases() {
@@ -156,6 +179,17 @@ public class CommonTestCases {
     }
 
     /**
+     * Provides a list of test cases where the multiplicative inverse of a fraction 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
+     */
+    public static List<UnaryOperatorTestCase> reciprocalTestCases() {
+        return Collections.unmodifiableList(reciprocalTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 aa0daff..543a06e 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
@@ -210,22 +210,10 @@ public class FractionTest {
 
     @Test
     public void testReciprocal() {
-        {
-            Fraction f = Fraction.of(50, 75);
-            f = f.reciprocal();
-            assertFraction(3, 2, f);
-        }
-
-        {
-            Fraction f = Fraction.of(4, 3);
-            f = f.reciprocal();
-            assertFraction(3, 4, f);
-        }
-
-        {
-            Fraction f = Fraction.of(-15, 47);
+        for (CommonTestCases.UnaryOperatorTestCase testCase : CommonTestCases.reciprocalTestCases()) {
+            Fraction f = Fraction.of(testCase.operandNumerator, testCase.operandDenominator);
             f = f.reciprocal();
-            assertFraction(-47, 15, f);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f);
         }
 
         {
@@ -234,13 +222,6 @@ public class FractionTest {
                     f::reciprocal
             );
         }
-
-        {
-            // large values
-            Fraction f = Fraction.of(Integer.MAX_VALUE, 1);
-            f = f.reciprocal();
-            assertFraction(1, Integer.MAX_VALUE, f);
-        }
     }
 
     @Test


[commons-numbers] 08/15: NUMBERS-118: Make class CommonTestCases package-private and correct Javadoc mistake

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

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

commit f15ac5b1906a4fe3c76d94986538d8916cb9cb5f
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 15:05:31 2019 +0200

    NUMBERS-118: Make class CommonTestCases package-private and correct Javadoc mistake
---
 .../commons/numbers/fraction/CommonTestCases.java  | 36 +++++++++++-----------
 1 file changed, 18 insertions(+), 18 deletions(-)

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 ad6e917..17e3596 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
@@ -10,7 +10,7 @@ import java.util.List;
  * for operations and expected results that involve
  * numerators and denominators in the {@code int} range.
  */
-public class CommonTestCases {
+class CommonTestCases {
     /**
      * See {@link #numDenConstructorTestCases()}
      */
@@ -123,7 +123,7 @@ public class CommonTestCases {
     }
 
     /**
-     * Defines test cases as described in {@link #collectAbsTestCases()} and collects
+     * Defines test cases as described in {@link #absTestCases()} and collects
      * them into a {@code List}.
      * @return a list of test cases as described above
      */
@@ -174,7 +174,7 @@ public class CommonTestCases {
      * numerator and denominator of the created fraction are also in the {@code int} range.
      * @return a list of test cases as described above
      */
-    public static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
+    static List<UnaryOperatorTestCase> numDenConstructorTestCases() {
         return Collections.unmodifiableList(numDenConstructorTestCasesList);
     }
 
@@ -184,7 +184,7 @@ public class CommonTestCases {
      * numerator and denominator of the resulting fraction are in the {@code int} range.
      * @return a list of test cases as described above
      */
-    public static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
+    static List<DoubleToFractionTestCase> doubleConstructorTestCases() {
         return Collections.unmodifiableList(doubleConstructorTestCasesList);
     }
 
@@ -195,7 +195,7 @@ public class CommonTestCases {
      * numerator and denominator of the resulting fraction are also in the {@code int} range.
      * @return a list of test cases as described above
      */
-    public static List<UnaryOperatorTestCase> absTestCases() {
+    static List<UnaryOperatorTestCase> absTestCases() {
         return Collections.unmodifiableList(absTestCasesList);
     }
 
@@ -206,7 +206,7 @@ public class CommonTestCases {
      * numerator and denominator of the resulting fraction are also in the {@code int} range.
      * @return a list of test cases as described above
      */
-    public static List<UnaryOperatorTestCase> reciprocalTestCases() {
+    static List<UnaryOperatorTestCase> reciprocalTestCases() {
         return Collections.unmodifiableList(reciprocalTestCasesList);
     }
 
@@ -217,7 +217,7 @@ public class CommonTestCases {
      * numerator and denominator of the resulting fraction are also in the {@code int} range.
      * @return a list of test cases as described above
      */
-    public static List<UnaryOperatorTestCase> negateTestCases() {
+    static List<UnaryOperatorTestCase> negateTestCases() {
         return Collections.unmodifiableList(negateTestCasesList);
     }
 
@@ -226,13 +226,13 @@ public class CommonTestCases {
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
      */
-    public static class UnaryOperatorTestCase {
-        public final int operandNumerator;
-        public final int operandDenominator;
-        public final int expectedNumerator;
-        public final int expectedDenominator;
+    static class UnaryOperatorTestCase {
+        final int operandNumerator;
+        final int operandDenominator;
+        final int expectedNumerator;
+        final int expectedDenominator;
 
-        public UnaryOperatorTestCase(
+        UnaryOperatorTestCase(
                 int operandNumerator,
                 int operandDenominator,
                 int expectedNumerator,
@@ -249,12 +249,12 @@ public class CommonTestCases {
      * on a {@code double} value and the numerator and denominator of the expected result
      * are in the {@code int} range.
      */
-    public static class DoubleToFractionTestCase {
-        public final double operand;
-        public final int expectedNumerator;
-        public final int expectedDenominator;
+    static class DoubleToFractionTestCase {
+        final double operand;
+        final int expectedNumerator;
+        final int expectedDenominator;
 
-        public DoubleToFractionTestCase(
+        DoubleToFractionTestCase(
                 double operand,
                 int expectedNumerator,
                 int expectedDenominator) {


[commons-numbers] 15/15: Merge branch 'NUMBERS-118__heinrich'

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

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

commit 860adcdb865842f673ba5010ebcbfd501abcff8b
Merge: 7b36cbf 625361b
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Sat Jun 22 15:31:39 2019 +0200

    Merge branch 'NUMBERS-118__heinrich'
    
    Closes #55.

 .../commons/numbers/fraction/BigFractionTest.java  | 270 +++--------
 .../commons/numbers/fraction/CommonTestCases.java  | 507 +++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 268 ++---------
 3 files changed, 618 insertions(+), 427 deletions(-)


[commons-numbers] 13/15: NUMBERS-118: Extract common subtract-fraction test cases

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

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

commit c45802dc9c202c50e014e64522e98e5dbba08e23
Author: Schamschi <he...@gmx.at>
AuthorDate: Fri Jun 21 13:28:49 2019 +0200

    NUMBERS-118: Extract common subtract-fraction test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  | 33 ++---------
 .../commons/numbers/fraction/CommonTestCases.java  | 67 +++++++++++++++++++++-
 .../commons/numbers/fraction/FractionTest.java     | 39 ++-----------
 3 files changed, 76 insertions(+), 63 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 26fc8a1..0990357 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
@@ -421,13 +421,11 @@ public class BigFractionTest {
 
     @Test
     public void testSubtract() {
-        BigFraction a = BigFraction.of(1, 2);
-        BigFraction b = BigFraction.of(2, 3);
-
-        assertFraction(0, 1, a.subtract(a));
-        assertFraction(-1, 6, a.subtract(b));
-        assertFraction(1, 6, b.subtract(a));
-        assertFraction(0, 1, b.subtract(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.subtractFractionTestCases()) {
+            BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            BigFraction f2 = BigFraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.subtract(f2));
+        }
 
         BigFraction f = BigFraction.of(1, 1);
         try {
@@ -435,27 +433,6 @@ public class BigFractionTest {
             Assertions.fail("expecting NullPointerException");
         } catch (NullPointerException ex) {
         }
-
-        // if this fraction is subtracted naively, it will overflow.
-        // check that it doesn't.
-        BigFraction f1 = BigFraction.of(1, 32768 * 3);
-        BigFraction f2 = BigFraction.of(1, 59049);
-        f = f1.subtract(f2);
-        Assertions.assertEquals(-13085, f.getNumeratorAsInt());
-        Assertions.assertEquals(1934917632, f.getDenominatorAsInt());
-
-        f1 = BigFraction.of(Integer.MIN_VALUE, 3);
-        f2 = BigFraction.of(1, 3).negate();
-        f = f1.subtract(f2);
-        Assertions.assertEquals(Integer.MIN_VALUE + 1, f.getNumeratorAsInt());
-        Assertions.assertEquals(3, f.getDenominatorAsInt());
-
-        f1 = BigFraction.of(Integer.MAX_VALUE, 1);
-        f2 = BigFraction.ONE;
-        f = f1.subtract(f2);
-        Assertions.assertEquals(Integer.MAX_VALUE - 1, f.getNumeratorAsInt());
-        Assertions.assertEquals(1, f.getDenominatorAsInt());
-
     }
 
     @Test
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 be19fdb..c35b018 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
@@ -51,6 +51,11 @@ class CommonTestCases {
      */
     private static final List<BinaryOperatorTestCase> multiplyByFractionTestCasesList;
 
+    /**
+     * See {@link #subtractFractionTestCases()}
+     */
+    private static final List<BinaryOperatorTestCase> subtractFractionTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
@@ -60,6 +65,7 @@ class CommonTestCases {
         addFractionTestCasesList = collectAddFractionTestCases();
         divideByFractionTestCasesList = collectDivideByFractionTestCases();
         multiplyByFractionTestCasesList = collectMultiplyByFractionTestCases();
+        subtractFractionTestCasesList = collectSubtractFractionTestCases();
     }
 
     /**
@@ -253,6 +259,11 @@ class CommonTestCases {
         return testCases;
     }
 
+    /**
+     * Defines test cases as described in {@link #multiplyByFractionTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
     private static List<BinaryOperatorTestCase> collectMultiplyByFractionTestCases() {
         List<BinaryOperatorTestCase> testCases = new ArrayList<>();
 
@@ -270,6 +281,41 @@ class CommonTestCases {
     }
 
     /**
+     * Defines test cases as described in {@link #subtractFractionTestCases()} and collects
+     * them into a {@code List}.
+     * @return a list of test cases as described above
+     */
+    private static List<BinaryOperatorTestCase> collectSubtractFractionTestCases() {
+        List<BinaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new BinaryOperatorTestCase(1, 2, 1, 2, 0, 1));
+        testCases.add(new BinaryOperatorTestCase(1, 2, 2, 3, -1, 6));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 1, 6));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 0, 1));
+
+        // if this fraction is subtracted naively, it will overflow.
+        // check that it doesn't.
+        testCases.add(new BinaryOperatorTestCase(
+                1, 32768 * 3,
+                1, 59049,
+                -13085, 1934917632));
+
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MIN_VALUE, 3,
+                -1, 3,
+                Integer.MIN_VALUE + 1, 3
+        ));
+
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MAX_VALUE, 1,
+                1, 1,
+                Integer.MAX_VALUE-1, 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.
@@ -333,10 +379,13 @@ class CommonTestCases {
     }
 
     /**
-     * Provides a list of test cases where a fraction, created from a specified numerator and denominator
+     * <p>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.
+     * are in the {@code int} range as well.</p>
+     *
+     * <p>The first operand in each test case is the dividend and the second operand is the divisor.</p>
+     *
      * @return a list of test cases as described above
      */
     static List<BinaryOperatorTestCase> divideByFractionTestCases() {
@@ -355,6 +404,20 @@ class CommonTestCases {
     }
 
     /**
+     * <p>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>
+     *
+     * <p>The first operand in each test case is the minuend and the second operand is the subtrahend.</p>
+     *
+     * @return a list of test cases as described above
+     */
+    static List<BinaryOperatorTestCase> subtractFractionTestCases() {
+        return Collections.unmodifiableList(subtractFractionTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 977e702..42c1b35 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
@@ -401,14 +401,10 @@ public class FractionTest {
 
     @Test
     public void testSubtract() {
-        {
-            Fraction a = Fraction.of(1, 2);
-            Fraction b = Fraction.of(2, 3);
-
-            assertFraction(0, 1, a.subtract(a));
-            assertFraction(-1, 6, a.subtract(b));
-            assertFraction(1, 6, b.subtract(a));
-            assertFraction(0, 1, b.subtract(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.subtractFractionTestCases()) {
+            Fraction f1 = Fraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            Fraction f2 = Fraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.subtract(f2));
         }
 
         {
@@ -419,32 +415,9 @@ public class FractionTest {
         }
 
         {
-            // if this fraction is subtracted naively, it will overflow.
-            // check that it doesn't.
-            Fraction f1 = Fraction.of(1, 32768 * 3);
-            Fraction f2 = Fraction.of(1, 59049);
-            Fraction f = f1.subtract(f2);
-            assertFraction(-13085, 1934917632, f);
-        }
-
-        {
-            Fraction f1 = Fraction.of(Integer.MIN_VALUE, 3);
-            Fraction f2 = Fraction.of(1, 3).negate();
-            Fraction f = f1.subtract(f2);
-            assertFraction(Integer.MIN_VALUE + 1, 3, f);
-        }
-
-        {
             Fraction f1 = Fraction.of(Integer.MAX_VALUE, 1);
-            {
-                Fraction f2 = Fraction.ONE;
-                Fraction f = f1.subtract(f2);
-                assertFraction(Integer.MAX_VALUE-1, 1, f);
-            }
-            {
-                Fraction f = f1.subtract(1);
-                assertFraction(Integer.MAX_VALUE-1, 1, f);
-            }
+            Fraction f = f1.subtract(1);
+            assertFraction(Integer.MAX_VALUE-1, 1, f);
         }
 
         {


[commons-numbers] 01/15: NUMBERS-118: Extract common num-den-constructor and double-constructor test cases

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

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

commit 55e1ab819ad098b4b26ae750db498f3e2ec0820e
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 00:43:41 2019 +0200

    NUMBERS-118: Extract common num-den-constructor and double-constructor test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  |  64 +++--------
 .../commons/numbers/fraction/CommonTestCases.java  | 123 +++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     |  64 +++--------
 3 files changed, 152 insertions(+), 99 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 039e8a6..8a5b9dd 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
@@ -39,15 +39,15 @@ public class BigFractionTest {
 
     @Test
     public void testConstructor() {
-        assertFraction(0, 1, BigFraction.of(0, 1));
+        for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+            assertFraction(
+                    testCase.expectedNumerator,
+                    testCase.expectedDenominator,
+                    BigFraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+            );
+        }
+
         assertFraction(0, 1, BigFraction.of(0l, 2l));
-        assertFraction(0, 1, BigFraction.of(0, -1));
-        assertFraction(1, 2, BigFraction.of(1, 2));
-        assertFraction(1, 2, BigFraction.of(2, 4));
-        assertFraction(-1, 2, BigFraction.of(-1, 2));
-        assertFraction(-1, 2, BigFraction.of(1, -2));
-        assertFraction(-1, 2, BigFraction.of(-2, 4));
-        assertFraction(-1, 2, BigFraction.of(2, -4));
         assertFraction(11, 1, BigFraction.of(11));
         assertFraction(11, 1, BigFraction.of(11l));
         assertFraction(11, 1, BigFraction.of(new BigInteger("11")));
@@ -98,47 +98,13 @@ public class BigFractionTest {
     // MATH-179
     @Test
     public void testDoubleConstructor() throws Exception {
-        assertFraction(1, 2, BigFraction.from((double) 1 / (double) 2, 1.0e-5, 100));
-        assertFraction(1, 3, BigFraction.from((double) 1 / (double) 3, 1.0e-5, 100));
-        assertFraction(2, 3, BigFraction.from((double) 2 / (double) 3, 1.0e-5, 100));
-        assertFraction(1, 4, BigFraction.from((double) 1 / (double) 4, 1.0e-5, 100));
-        assertFraction(3, 4, BigFraction.from((double) 3 / (double) 4, 1.0e-5, 100));
-        assertFraction(1, 5, BigFraction.from((double) 1 / (double) 5, 1.0e-5, 100));
-        assertFraction(2, 5, BigFraction.from((double) 2 / (double) 5, 1.0e-5, 100));
-        assertFraction(3, 5, BigFraction.from((double) 3 / (double) 5, 1.0e-5, 100));
-        assertFraction(4, 5, BigFraction.from((double) 4 / (double) 5, 1.0e-5, 100));
-        assertFraction(1, 6, BigFraction.from((double) 1 / (double) 6, 1.0e-5, 100));
-        assertFraction(5, 6, BigFraction.from((double) 5 / (double) 6, 1.0e-5, 100));
-        assertFraction(1, 7, BigFraction.from((double) 1 / (double) 7, 1.0e-5, 100));
-        assertFraction(2, 7, BigFraction.from((double) 2 / (double) 7, 1.0e-5, 100));
-        assertFraction(3, 7, BigFraction.from((double) 3 / (double) 7, 1.0e-5, 100));
-        assertFraction(4, 7, BigFraction.from((double) 4 / (double) 7, 1.0e-5, 100));
-        assertFraction(5, 7, BigFraction.from((double) 5 / (double) 7, 1.0e-5, 100));
-        assertFraction(6, 7, BigFraction.from((double) 6 / (double) 7, 1.0e-5, 100));
-        assertFraction(1, 8, BigFraction.from((double) 1 / (double) 8, 1.0e-5, 100));
-        assertFraction(3, 8, BigFraction.from((double) 3 / (double) 8, 1.0e-5, 100));
-        assertFraction(5, 8, BigFraction.from((double) 5 / (double) 8, 1.0e-5, 100));
-        assertFraction(7, 8, BigFraction.from((double) 7 / (double) 8, 1.0e-5, 100));
-        assertFraction(1, 9, BigFraction.from((double) 1 / (double) 9, 1.0e-5, 100));
-        assertFraction(2, 9, BigFraction.from((double) 2 / (double) 9, 1.0e-5, 100));
-        assertFraction(4, 9, BigFraction.from((double) 4 / (double) 9, 1.0e-5, 100));
-        assertFraction(5, 9, BigFraction.from((double) 5 / (double) 9, 1.0e-5, 100));
-        assertFraction(7, 9, BigFraction.from((double) 7 / (double) 9, 1.0e-5, 100));
-        assertFraction(8, 9, BigFraction.from((double) 8 / (double) 9, 1.0e-5, 100));
-        assertFraction(1, 10, BigFraction.from((double) 1 / (double) 10, 1.0e-5, 100));
-        assertFraction(3, 10, BigFraction.from((double) 3 / (double) 10, 1.0e-5, 100));
-        assertFraction(7, 10, BigFraction.from((double) 7 / (double) 10, 1.0e-5, 100));
-        assertFraction(9, 10, BigFraction.from((double) 9 / (double) 10, 1.0e-5, 100));
-        assertFraction(1, 11, BigFraction.from((double) 1 / (double) 11, 1.0e-5, 100));
-        assertFraction(2, 11, BigFraction.from((double) 2 / (double) 11, 1.0e-5, 100));
-        assertFraction(3, 11, BigFraction.from((double) 3 / (double) 11, 1.0e-5, 100));
-        assertFraction(4, 11, BigFraction.from((double) 4 / (double) 11, 1.0e-5, 100));
-        assertFraction(5, 11, BigFraction.from((double) 5 / (double) 11, 1.0e-5, 100));
-        assertFraction(6, 11, BigFraction.from((double) 6 / (double) 11, 1.0e-5, 100));
-        assertFraction(7, 11, BigFraction.from((double) 7 / (double) 11, 1.0e-5, 100));
-        assertFraction(8, 11, BigFraction.from((double) 8 / (double) 11, 1.0e-5, 100));
-        assertFraction(9, 11, BigFraction.from((double) 9 / (double) 11, 1.0e-5, 100));
-        assertFraction(10, 11, BigFraction.from((double) 10 / (double) 11, 1.0e-5, 100));
+        for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+            assertFraction(
+                    testCase.expectedNumerator,
+                    testCase.expectedDenominator,
+                    BigFraction.from(testCase.constructorArgument, 1.0e-5, 100)
+            );
+        }
     }
 
     // MATH-181
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
new file mode 100644
index 0000000..cbaa029
--- /dev/null
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/CommonTestCases.java
@@ -0,0 +1,123 @@
+package org.apache.commons.numbers.fraction;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A collection of test cases that can be applied both
+ * to {@link Fraction} and {@link BigFraction}, e.g.
+ * for operations and expected results that involve
+ * numerators and denominators in the {@code int} range.
+ */
+public class CommonTestCases {
+    private static final List<NumDenConstructorTestCase> numDenConstructorTestCasesList;
+
+    private static final List<DoubleConstructorTestCase> doubleConstructorTestCasesList;
+
+    static {
+        numDenConstructorTestCasesList = new ArrayList<>();
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 1, 0, 1));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, 2, 0, 1));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(0, -1, 0, 1));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, 2, 1, 2));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, 4, 1, 2));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-1, 2, -1, 2));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(1, -2, -1, 2));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(-2, 4, -1, 2));
+        numDenConstructorTestCasesList.add(new NumDenConstructorTestCase(2, -4, -1, 2));
+
+        doubleConstructorTestCasesList = new ArrayList<>();
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/2d, 1, 2));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/3d, 1, 3));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/3d, 2, 3));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/4d, 1, 4));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/4d, 3, 4));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/5d, 1, 5));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/5d, 2, 5));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/5d, 3, 5));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/5d, 4, 5));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/6d, 1, 6));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/6d, 5, 6));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/7d, 1, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/7d, 2, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/7d, 3, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/7d, 4, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/7d, 5, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/7d, 6, 7));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/8d, 1, 8));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/8d, 3, 8));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/8d, 5, 8));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/8d, 7, 8));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/9d, 1, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/9d, 2, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/9d, 4, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/9d, 5, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/9d, 7, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/9d, 8, 9));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/10d, 1, 10));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/10d, 3, 10));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/10d, 7, 10));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/10d, 9, 10));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(1d/11d, 1, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(2d/11d, 2, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(3d/11d, 3, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(4d/11d, 4, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(5d/11d, 5, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(6d/11d, 6, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(7d/11d, 7, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(8d/11d, 8, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(9d/11d, 9, 11));
+        doubleConstructorTestCasesList.add(new DoubleConstructorTestCase(10d/11d, 10, 11));
+    }
+
+    public static List<NumDenConstructorTestCase> numDenConstructorTestCases() {
+        return Collections.unmodifiableList(numDenConstructorTestCasesList);
+    }
+
+    public static List<DoubleConstructorTestCase> doubleConstructorTestCases() {
+        return Collections.unmodifiableList(doubleConstructorTestCasesList);
+    }
+
+    /**
+     * Represents a test case where a fraction should be created from a
+     * specified numerator and denominator, both in the {@code int} range.
+     */
+    public static class NumDenConstructorTestCase {
+        public final int constructorNumerator;
+        public final int constructorDenominator;
+        public final int expectedNumerator;
+        public final int expectedDenominator;
+
+        public NumDenConstructorTestCase(
+                int constructorNumerator,
+                int constructorDenominator,
+                int expectedNumerator,
+                int expectedDenominator) {
+            this.constructorNumerator = constructorNumerator;
+            this.constructorDenominator = constructorDenominator;
+            this.expectedNumerator = expectedNumerator;
+            this.expectedDenominator = expectedDenominator;
+        }
+    }
+
+    /**
+     * Represents a test case where a fraction should be created from a
+     * {@code double} value and the expected numerator and denominator
+     * are in the {@code int} range.
+     */
+    public static class DoubleConstructorTestCase {
+        public final double constructorArgument;
+        public final int expectedNumerator;
+        public final int expectedDenominator;
+
+        public DoubleConstructorTestCase(
+                double constructorArgument,
+                int expectedNumerator,
+                int expectedDenominator) {
+            this.constructorArgument = constructorArgument;
+            this.expectedNumerator = expectedNumerator;
+            this.expectedDenominator = expectedDenominator;
+        }
+    }
+}
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 f6c224c..293ffbd 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
@@ -33,15 +33,13 @@ public class FractionTest {
 
     @Test
     public void testConstructor() {
-        assertFraction(0, 1, Fraction.of(0, 1));
-        assertFraction(0, 1, Fraction.of(0, 2));
-        assertFraction(0, 1, Fraction.of(0, -1));
-        assertFraction(1, 2, Fraction.of(1, 2));
-        assertFraction(1, 2, Fraction.of(2, 4));
-        assertFraction(-1, 2, Fraction.of(-1, 2));
-        assertFraction(-1, 2, Fraction.of(1, -2));
-        assertFraction(-1, 2, Fraction.of(-2, 4));
-        assertFraction(-1, 2, Fraction.of(2, -4));
+        for (CommonTestCases.NumDenConstructorTestCase testCase : CommonTestCases.numDenConstructorTestCases()) {
+            assertFraction(
+                    testCase.expectedNumerator,
+                    testCase.expectedDenominator,
+                    Fraction.of(testCase.constructorNumerator, testCase.constructorDenominator)
+            );
+        }
 
         // overflow
         Assertions.assertThrows(ArithmeticException.class,
@@ -67,47 +65,13 @@ public class FractionTest {
     // MATH-179
     @Test
     public void testDoubleConstructor() throws Exception  {
-        assertFraction(1, 2, Fraction.from((double)1 / (double)2));
-        assertFraction(1, 3, Fraction.from((double)1 / (double)3));
-        assertFraction(2, 3, Fraction.from((double)2 / (double)3));
-        assertFraction(1, 4, Fraction.from((double)1 / (double)4));
-        assertFraction(3, 4, Fraction.from((double)3 / (double)4));
-        assertFraction(1, 5, Fraction.from((double)1 / (double)5));
-        assertFraction(2, 5, Fraction.from((double)2 / (double)5));
-        assertFraction(3, 5, Fraction.from((double)3 / (double)5));
-        assertFraction(4, 5, Fraction.from((double)4 / (double)5));
-        assertFraction(1, 6, Fraction.from((double)1 / (double)6));
-        assertFraction(5, 6, Fraction.from((double)5 / (double)6));
-        assertFraction(1, 7, Fraction.from((double)1 / (double)7));
-        assertFraction(2, 7, Fraction.from((double)2 / (double)7));
-        assertFraction(3, 7, Fraction.from((double)3 / (double)7));
-        assertFraction(4, 7, Fraction.from((double)4 / (double)7));
-        assertFraction(5, 7, Fraction.from((double)5 / (double)7));
-        assertFraction(6, 7, Fraction.from((double)6 / (double)7));
-        assertFraction(1, 8, Fraction.from((double)1 / (double)8));
-        assertFraction(3, 8, Fraction.from((double)3 / (double)8));
-        assertFraction(5, 8, Fraction.from((double)5 / (double)8));
-        assertFraction(7, 8, Fraction.from((double)7 / (double)8));
-        assertFraction(1, 9, Fraction.from((double)1 / (double)9));
-        assertFraction(2, 9, Fraction.from((double)2 / (double)9));
-        assertFraction(4, 9, Fraction.from((double)4 / (double)9));
-        assertFraction(5, 9, Fraction.from((double)5 / (double)9));
-        assertFraction(7, 9, Fraction.from((double)7 / (double)9));
-        assertFraction(8, 9, Fraction.from((double)8 / (double)9));
-        assertFraction(1, 10, Fraction.from((double)1 / (double)10));
-        assertFraction(3, 10, Fraction.from((double)3 / (double)10));
-        assertFraction(7, 10, Fraction.from((double)7 / (double)10));
-        assertFraction(9, 10, Fraction.from((double)9 / (double)10));
-        assertFraction(1, 11, Fraction.from((double)1 / (double)11));
-        assertFraction(2, 11, Fraction.from((double)2 / (double)11));
-        assertFraction(3, 11, Fraction.from((double)3 / (double)11));
-        assertFraction(4, 11, Fraction.from((double)4 / (double)11));
-        assertFraction(5, 11, Fraction.from((double)5 / (double)11));
-        assertFraction(6, 11, Fraction.from((double)6 / (double)11));
-        assertFraction(7, 11, Fraction.from((double)7 / (double)11));
-        assertFraction(8, 11, Fraction.from((double)8 / (double)11));
-        assertFraction(9, 11, Fraction.from((double)9 / (double)11));
-        assertFraction(10, 11, Fraction.from((double)10 / (double)11));
+        for (CommonTestCases.DoubleConstructorTestCase testCase : CommonTestCases.doubleConstructorTestCases()) {
+            assertFraction(
+                    testCase.expectedNumerator,
+                    testCase.expectedDenominator,
+                    Fraction.from(testCase.constructorArgument)
+            );
+        }
     }
 
     // MATH-181


[commons-numbers] 12/15: NUMBERS-118: Extract common multiply-by-fraction test cases

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

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

commit 2e41297bccccf685e84e56783afeab11e59a114b
Author: Schamschi <he...@gmx.at>
AuthorDate: Fri Jun 21 00:43:14 2019 +0200

    NUMBERS-118: Extract common multiply-by-fraction test cases
---
 .../commons/numbers/fraction/BigFractionTest.java  | 19 ++++---------
 .../commons/numbers/fraction/CommonTestCases.java  | 33 ++++++++++++++++++++++
 .../commons/numbers/fraction/FractionTest.java     | 18 ++++--------
 3 files changed, 44 insertions(+), 26 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 a16d35d..26fc8a1 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
@@ -396,21 +396,14 @@ public class BigFractionTest {
 
     @Test
     public void testMultiply() {
-        BigFraction a = BigFraction.of(1, 2);
-        BigFraction b = BigFraction.of(2, 3);
-
-        assertFraction(1, 4, a.multiply(a));
-        assertFraction(1, 3, a.multiply(b));
-        assertFraction(1, 3, b.multiply(a));
-        assertFraction(4, 9, b.multiply(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.multiplyByFractionTestCases()) {
+            BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            BigFraction f2 = BigFraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.multiply(f2));
+        }
 
-        BigFraction f1 = BigFraction.of(Integer.MAX_VALUE, 1);
         BigFraction f2 = BigFraction.of(Integer.MIN_VALUE, Integer.MAX_VALUE);
-        BigFraction f = f1.multiply(f2);
-        Assertions.assertEquals(Integer.MIN_VALUE, f.getNumeratorAsInt());
-        Assertions.assertEquals(1, f.getDenominatorAsInt());
-
-        f = f2.multiply(Integer.MAX_VALUE);
+        BigFraction f = f2.multiply(Integer.MAX_VALUE);
         Assertions.assertEquals(Integer.MIN_VALUE, f.getNumeratorAsInt());
         Assertions.assertEquals(1, f.getDenominatorAsInt());
 
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 c91f6e3..be19fdb 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
@@ -46,6 +46,11 @@ class CommonTestCases {
      */
     private static final List<BinaryOperatorTestCase> divideByFractionTestCasesList;
 
+    /**
+     * See {@link #multiplyByFractionTestCases()}
+     */
+    private static final List<BinaryOperatorTestCase> multiplyByFractionTestCasesList;
+
     static {
         numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
         doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
@@ -54,6 +59,7 @@ class CommonTestCases {
         negateTestCasesList = collectNegateTestCases();
         addFractionTestCasesList = collectAddFractionTestCases();
         divideByFractionTestCasesList = collectDivideByFractionTestCases();
+        multiplyByFractionTestCasesList = collectMultiplyByFractionTestCases();
     }
 
     /**
@@ -247,6 +253,22 @@ class CommonTestCases {
         return testCases;
     }
 
+    private static List<BinaryOperatorTestCase> collectMultiplyByFractionTestCases() {
+        List<BinaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new BinaryOperatorTestCase(1, 2, 1, 2, 1, 4));
+        testCases.add(new BinaryOperatorTestCase(1, 2, 2, 3, 1, 3));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 1, 2, 1, 3));
+        testCases.add(new BinaryOperatorTestCase(2, 3, 2, 3, 4, 9));
+
+        testCases.add(new BinaryOperatorTestCase(
+                Integer.MAX_VALUE, 1,
+                Integer.MIN_VALUE, Integer.MAX_VALUE,
+                Integer.MIN_VALUE, 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
@@ -322,6 +344,17 @@ class CommonTestCases {
     }
 
     /**
+     * Provides a list of test cases where a fraction, created from a specified numerator and denominator
+     * in the {@code int} range, should be multiplied 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.
+     * @return a list of test cases as described above
+     */
+    static List<BinaryOperatorTestCase> multiplyByFractionTestCases() {
+        return Collections.unmodifiableList(multiplyByFractionTestCasesList);
+    }
+
+    /**
      * Represents a test case where a unary operation should be performed on a specified combination
      * of numerator and denominator, both in the {@code int} range, and the numerator and
      * denominator of the expected result are also in the {@code int} range.
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 4d71a39..977e702 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
@@ -353,22 +353,14 @@ public class FractionTest {
 
     @Test
     public void testMultiply() {
-        {
-            Fraction a = Fraction.of(1, 2);
-            Fraction b = Fraction.of(2, 3);
-
-            assertFraction(1, 4, a.multiply(a));
-            assertFraction(1, 3, a.multiply(b));
-            assertFraction(1, 3, b.multiply(a));
-            assertFraction(4, 9, b.multiply(b));
+        for (CommonTestCases.BinaryOperatorTestCase testCase : CommonTestCases.multiplyByFractionTestCases()) {
+            Fraction f1 = Fraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
+            Fraction f2 = Fraction.of(testCase.secondOperandNumerator, testCase.secondOperandDenominator);
+            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.multiply(f2));
         }
 
         {
-            Fraction f1 = Fraction.of(Integer.MAX_VALUE, 1);
-            Fraction f2 = Fraction.of(Integer.MIN_VALUE, Integer.MAX_VALUE);
-            final Fraction f = f1.multiply(f2);
-            assertFraction(Integer.MIN_VALUE, 1, f);
-
+            final Fraction f = Fraction.of(Integer.MIN_VALUE, 1);
             Assertions.assertThrows(NullPointerException.class,
                     () -> f.multiply(null)
             );


[commons-numbers] 03/15: NUMBERS-118: Organize population of test case lists into methods

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

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

commit b7d3c7f7c428bcdfc68273e3eff0e17de15bdef3
Author: Schamschi <he...@gmx.at>
AuthorDate: Thu Jun 20 11:39:15 2019 +0200

    NUMBERS-118: Organize population of test case lists into methods
---
 .../commons/numbers/fraction/CommonTestCases.java  | 119 ++++++++++++---------
 1 file changed, 66 insertions(+), 53 deletions(-)

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 cc6127f..cd68373 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
@@ -16,59 +16,72 @@ public class CommonTestCases {
     private static final List<DoubleToFractionTestCase> doubleConstructorTestCasesList;
 
     static {
-        numDenConstructorTestCasesList = new ArrayList<>();
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 1, 0, 1));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, 2, 0, 1));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(0, -1, 0, 1));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, 2, 1, 2));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, 4, 1, 2));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-1, 2, -1, 2));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(1, -2, -1, 2));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(-2, 4, -1, 2));
-        numDenConstructorTestCasesList.add(new UnaryOperatorTestCase(2, -4, -1, 2));
-
-        doubleConstructorTestCasesList = new ArrayList<>();
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/2d, 1, 2));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/3d, 1, 3));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/3d, 2, 3));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/4d, 1, 4));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/4d, 3, 4));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/5d, 1, 5));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/5d, 2, 5));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/5d, 3, 5));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/5d, 4, 5));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/6d, 1, 6));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/6d, 5, 6));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/7d, 1, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/7d, 2, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/7d, 3, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/7d, 4, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/7d, 5, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/7d, 6, 7));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/8d, 1, 8));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/8d, 3, 8));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/8d, 5, 8));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/8d, 7, 8));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/9d, 1, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/9d, 2, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/9d, 4, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/9d, 5, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/9d, 7, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/9d, 8, 9));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/10d, 1, 10));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/10d, 3, 10));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/10d, 7, 10));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/10d, 9, 10));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(1d/11d, 1, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(2d/11d, 2, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(3d/11d, 3, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(4d/11d, 4, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(5d/11d, 5, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(6d/11d, 6, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(7d/11d, 7, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(8d/11d, 8, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(9d/11d, 9, 11));
-        doubleConstructorTestCasesList.add(new DoubleToFractionTestCase(10d/11d, 10, 11));
+        numDenConstructorTestCasesList = collectNumDenConstructorTestCases();
+        doubleConstructorTestCasesList = collectDoubleConstructorTestCases();
+    }
+
+    private static List<UnaryOperatorTestCase> collectNumDenConstructorTestCases() {
+        List<UnaryOperatorTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new UnaryOperatorTestCase(0, 1, 0, 1));
+        testCases.add(new UnaryOperatorTestCase(0, 2, 0, 1));
+        testCases.add(new UnaryOperatorTestCase(0, -1, 0, 1));
+        testCases.add(new UnaryOperatorTestCase(1, 2, 1, 2));
+        testCases.add(new UnaryOperatorTestCase(2, 4, 1, 2));
+        testCases.add(new UnaryOperatorTestCase(-1, 2, -1, 2));
+        testCases.add(new UnaryOperatorTestCase(1, -2, -1, 2));
+        testCases.add(new UnaryOperatorTestCase(-2, 4, -1, 2));
+        testCases.add(new UnaryOperatorTestCase(2, -4, -1, 2));
+
+        return testCases;
+    }
+
+    private static List<DoubleToFractionTestCase> collectDoubleConstructorTestCases() {
+        List<DoubleToFractionTestCase> testCases = new ArrayList<>();
+
+        testCases.add(new DoubleToFractionTestCase(1d/2d, 1, 2));
+        testCases.add(new DoubleToFractionTestCase(1d/3d, 1, 3));
+        testCases.add(new DoubleToFractionTestCase(2d/3d, 2, 3));
+        testCases.add(new DoubleToFractionTestCase(1d/4d, 1, 4));
+        testCases.add(new DoubleToFractionTestCase(3d/4d, 3, 4));
+        testCases.add(new DoubleToFractionTestCase(1d/5d, 1, 5));
+        testCases.add(new DoubleToFractionTestCase(2d/5d, 2, 5));
+        testCases.add(new DoubleToFractionTestCase(3d/5d, 3, 5));
+        testCases.add(new DoubleToFractionTestCase(4d/5d, 4, 5));
+        testCases.add(new DoubleToFractionTestCase(1d/6d, 1, 6));
+        testCases.add(new DoubleToFractionTestCase(5d/6d, 5, 6));
+        testCases.add(new DoubleToFractionTestCase(1d/7d, 1, 7));
+        testCases.add(new DoubleToFractionTestCase(2d/7d, 2, 7));
+        testCases.add(new DoubleToFractionTestCase(3d/7d, 3, 7));
+        testCases.add(new DoubleToFractionTestCase(4d/7d, 4, 7));
+        testCases.add(new DoubleToFractionTestCase(5d/7d, 5, 7));
+        testCases.add(new DoubleToFractionTestCase(6d/7d, 6, 7));
+        testCases.add(new DoubleToFractionTestCase(1d/8d, 1, 8));
+        testCases.add(new DoubleToFractionTestCase(3d/8d, 3, 8));
+        testCases.add(new DoubleToFractionTestCase(5d/8d, 5, 8));
+        testCases.add(new DoubleToFractionTestCase(7d/8d, 7, 8));
+        testCases.add(new DoubleToFractionTestCase(1d/9d, 1, 9));
+        testCases.add(new DoubleToFractionTestCase(2d/9d, 2, 9));
+        testCases.add(new DoubleToFractionTestCase(4d/9d, 4, 9));
+        testCases.add(new DoubleToFractionTestCase(5d/9d, 5, 9));
+        testCases.add(new DoubleToFractionTestCase(7d/9d, 7, 9));
+        testCases.add(new DoubleToFractionTestCase(8d/9d, 8, 9));
+        testCases.add(new DoubleToFractionTestCase(1d/10d, 1, 10));
+        testCases.add(new DoubleToFractionTestCase(3d/10d, 3, 10));
+        testCases.add(new DoubleToFractionTestCase(7d/10d, 7, 10));
+        testCases.add(new DoubleToFractionTestCase(9d/10d, 9, 10));
+        testCases.add(new DoubleToFractionTestCase(1d/11d, 1, 11));
+        testCases.add(new DoubleToFractionTestCase(2d/11d, 2, 11));
+        testCases.add(new DoubleToFractionTestCase(3d/11d, 3, 11));
+        testCases.add(new DoubleToFractionTestCase(4d/11d, 4, 11));
+        testCases.add(new DoubleToFractionTestCase(5d/11d, 5, 11));
+        testCases.add(new DoubleToFractionTestCase(6d/11d, 6, 11));
+        testCases.add(new DoubleToFractionTestCase(7d/11d, 7, 11));
+        testCases.add(new DoubleToFractionTestCase(8d/11d, 8, 11));
+        testCases.add(new DoubleToFractionTestCase(9d/11d, 9, 11));
+        testCases.add(new DoubleToFractionTestCase(10d/11d, 10, 11));
+
+        return testCases;
     }
 
     public static List<UnaryOperatorTestCase> numDenConstructorTestCases() {