commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] 05/07: Fraction: Add alternative zero to common test cases.
Date Thu, 09 Apr 2020 11:34:47 GMT
This is an automated email from the ASF dual-hosted git repository.

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

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

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

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


Mime
View raw message