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:24 UTC

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

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());
                     }
             );
         }