commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-numbers] 06/06: Unit tests.
Date Fri, 01 Nov 2019 23:04:28 GMT
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 97eaea379c9f9b6a4ee752827badadc6cec12f83
Author: Gilles Sadowski <gilles@harfang.homelinux.org>
AuthorDate: Sat Nov 2 00:03:25 2019 +0100

    Unit tests.
---
 .../commons/numbers/fraction/BigFractionTest.java  | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 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 f44b123..2efa0f6 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
@@ -627,27 +627,43 @@ public class BigFractionTest {
         }
     }
 
-
     @Test
     public void testParse() {
         String[] validExpressions = new String[] {
                 "3",
                 "1 / 2",
+                "-1 / 2",
+                "1 / -2",
+                "-1 / -2",
                 "2147,483,647 / 2,147,483,648", //over largest int value
                 "9,223,372,036,854,775,807 / 9,223,372,036,854,775,808" //over largest long
value
         };
         BigFraction[] fractions = {
                 BigFraction.of(3),
                 BigFraction.of(1, 2),
+                BigFraction.of(-1, 2),
+                BigFraction.of(1, -2),
+                BigFraction.of(-1, -2),
                 BigFraction.of(2147483647, 2147483648L),
                 BigFraction.of(new BigInteger("9223372036854775807"),
-                        new BigInteger("9223372036854775808"))
+                               new BigInteger("9223372036854775808"))
         };
         int inc = 0;
         for (BigFraction fraction: fractions) {
             Assertions.assertEquals(fraction,
-                    BigFraction.parse(validExpressions[inc]));
+                                    BigFraction.parse(validExpressions[inc]));
             inc++;
         }
+
+        {
+            Assertions.assertThrows(NumberFormatException.class,
+                                    () -> BigFraction.parse("1 // 2"));
+            Assertions.assertThrows(NumberFormatException.class,
+                                    () -> BigFraction.parse("1 / z"));
+            Assertions.assertThrows(NumberFormatException.class,
+                                    () -> BigFraction.parse("1 / --2"));
+            Assertions.assertThrows(NumberFormatException.class,
+                                    () -> BigFraction.parse("x"));
+        }
     }
 }


Mime
View raw message