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/05/22 19:23:09 UTC

[commons-numbers] branch fraction-dev updated (3b21325 -> 92de0b4)

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

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


    from 3b21325  NUMBERS-97: restoring pow() method, lost in rebase
     new 092e816  NUMBERS-97: replacing pow method
     new 97683d5  NUMBERS-97: test for Fraction parse method
     new 3460841  NUMBERS-97: Added test of parse method in BigFractionTest, and updated outdated use of RoundingMode
     new 92de0b4  minor: login credentials test

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


Summary of changes:
 .../commons/numbers/fraction/BigFraction.java      | 27 +++++++++++++++++++
 .../commons/numbers/fraction/BigFractionTest.java  | 30 ++++++++++++++++++++--
 .../commons/numbers/fraction/FractionTest.java     |  4 +--
 3 files changed, 57 insertions(+), 4 deletions(-)


[commons-numbers] 01/04: NUMBERS-97: replacing pow method

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

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

commit 092e816b4e0bf369ff08c7d8b4e640b15ebeb47d
Author: Eric Barnhill <eb...@irhythmtech.com>
AuthorDate: Fri May 17 15:49:56 2019 -0700

    NUMBERS-97: replacing pow method
---
 .../commons/numbers/fraction/BigFraction.java      | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index 689228a..283475c 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -20,6 +20,8 @@ import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.math.RoundingMode;
+import java.text.NumberFormat;
+
 import org.apache.commons.numbers.core.ArithmeticUtils;
 
 /**
@@ -1173,6 +1175,31 @@ public class BigFraction
         }
         return str;
     }
+    
+    
+    /**
+     * Parses a string that would be produced by {@link #toString()}
+     * and instantiates the corresponding object.
+     *
+     * @param s String representation.
+     * @return an instance.
+     * @throws FractionException if the string does not
+     * conform to the specification.
+     */
+    public static BigFraction parse(String s) {
+        s = s.replace(",", "");
+        final int slashLoc = s.indexOf("/");
+        // if no slash, parse as single number
+        if (slashLoc == -1) {
+            return BigFraction.of(new BigInteger(s.trim()));
+        } else {
+            final BigInteger num = new BigInteger(
+                    s.substring(0, slashLoc).trim());
+            final BigInteger denom = new BigInteger(s.substring(slashLoc + 1).trim());
+            return of(num, denom);
+        }
+    }
+
 
     /**
      * Check that the argument is not null and throw a NullPointerException


[commons-numbers] 04/04: minor: login credentials test

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

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

commit 92de0b4d31ce534948c316125606565be9517354
Author: Eric Barnhill <eb...@irhythmtech.com>
AuthorDate: Wed May 22 11:43:25 2019 -0700

    minor: login credentials test
---
 .../test/java/org/apache/commons/numbers/fraction/BigFractionTest.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 9069e2b..9453dbe 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -653,7 +653,7 @@ public class BigFractionTest {
     
     
     @Test
-    public void testParse() {
+    public void testParse() { 
         String[] validExpressions = new String[] {
                 "3", 
                 "1 / 2", 


[commons-numbers] 02/04: NUMBERS-97: test for Fraction parse method

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

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

commit 97683d53ed0b05241c7da1e92fa820664fd29258
Author: Eric Barnhill <eb...@irhythmtech.com>
AuthorDate: Fri May 17 15:51:59 2019 -0700

    NUMBERS-97: test for Fraction parse method
---
 .../test/java/org/apache/commons/numbers/fraction/FractionTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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 a3ea0cb..10c3a20 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
@@ -631,13 +631,13 @@ public class FractionTest {
     @Test
     public void testParse() {
         String[] validExpressions = new String[] {
-                "1 / 2", "15 / 16", "-2 / 3", "8 / 7", 
+                "1 / 2", "15 / 16", "-2 / 3", "8 / 7"
         };
         Fraction[] fractions = {
                 Fraction.of(1, 2),
                 Fraction.of(15, 16),
                 Fraction.of(-2, 3),
-                Fraction.of(8, 7)
+                Fraction.of(8, 7),
         };
         int inc = 0;
         for (Fraction fraction: fractions) {


Re: [commons-numbers] branch fraction-dev updated (3b21325 -> 92de0b4)

Posted by Eric Barnhill <er...@gmail.com>.
Yes I regret that I did not finish up the last mile on Fraction before this
ticket was submitted. It would haved saved time as maybe I have fixed
someof those already. But, I will integrate these suggestions after I
finish my edits, all that is left to look at in my branch is the
checkstyle.

On Wed, May 22, 2019 at 3:04 PM Gilles Sadowski <gi...@gmail.com>
wrote:

> Hi Eric.
>
> Will you have look a NUMBERS-100:
>    https://issues.apache.org/jira/browse/NUMBERS-100
>
> I've just thought that it might interfere with your changes in the
> "fraction-dev" branch.
>
> Regards,
> Gilles
>
>
> Le mer. 22 mai 2019 à 21:23, <er...@apache.org> a écrit :
> >
> > This is an automated email from the ASF dual-hosted git repository.
> >
> > ericbarnhill pushed a change to branch fraction-dev
> > in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.
> >
> >
> >     from 3b21325  NUMBERS-97: restoring pow() method, lost in rebase
> >      new 092e816  NUMBERS-97: replacing pow method
> >      new 97683d5  NUMBERS-97: test for Fraction parse method
> >      new 3460841  NUMBERS-97: Added test of parse method in
> BigFractionTest, and updated outdated use of RoundingMode
> >      new 92de0b4  minor: login credentials test
> >
> > The 4 revisions listed above as "new" are entirely new to this
> > repository and will be described in separate emails.  The revisions
> > listed as "add" were already present in the repository and have only
> > been added to this reference.
> >
> >
> > Summary of changes:
> >  .../commons/numbers/fraction/BigFraction.java      | 27
> +++++++++++++++++++
> >  .../commons/numbers/fraction/BigFractionTest.java  | 30
> ++++++++++++++++++++--
> >  .../commons/numbers/fraction/FractionTest.java     |  4 +--
> >  3 files changed, 57 insertions(+), 4 deletions(-)
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: [commons-numbers] branch fraction-dev updated (3b21325 -> 92de0b4)

Posted by Gilles Sadowski <gi...@gmail.com>.
Hi Eric.

Will you have look a NUMBERS-100:
   https://issues.apache.org/jira/browse/NUMBERS-100

I've just thought that it might interfere with your changes in the
"fraction-dev" branch.

Regards,
Gilles


Le mer. 22 mai 2019 à 21:23, <er...@apache.org> a écrit :
>
> This is an automated email from the ASF dual-hosted git repository.
>
> ericbarnhill pushed a change to branch fraction-dev
> in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.
>
>
>     from 3b21325  NUMBERS-97: restoring pow() method, lost in rebase
>      new 092e816  NUMBERS-97: replacing pow method
>      new 97683d5  NUMBERS-97: test for Fraction parse method
>      new 3460841  NUMBERS-97: Added test of parse method in BigFractionTest, and updated outdated use of RoundingMode
>      new 92de0b4  minor: login credentials test
>
> The 4 revisions listed above as "new" are entirely new to this
> repository and will be described in separate emails.  The revisions
> listed as "add" were already present in the repository and have only
> been added to this reference.
>
>
> Summary of changes:
>  .../commons/numbers/fraction/BigFraction.java      | 27 +++++++++++++++++++
>  .../commons/numbers/fraction/BigFractionTest.java  | 30 ++++++++++++++++++++--
>  .../commons/numbers/fraction/FractionTest.java     |  4 +--
>  3 files changed, 57 insertions(+), 4 deletions(-)
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[commons-numbers] 03/04: NUMBERS-97: Added test of parse method in BigFractionTest, and updated outdated use of RoundingMode

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

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

commit 346084171c7e4ef3a0706378c7c0fda5d684bdf8
Author: Eric Barnhill <eb...@irhythmtech.com>
AuthorDate: Fri May 17 15:54:19 2019 -0700

    NUMBERS-97: Added test of parse method in BigFractionTest, and updated outdated use of RoundingMode
---
 .../commons/numbers/fraction/BigFractionTest.java  | 30 ++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 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 d15d78f..9069e2b 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
@@ -18,6 +18,8 @@ package org.apache.commons.numbers.fraction;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.math.RoundingMode;
+
 import org.apache.commons.numbers.core.TestUtils;
 
 import org.junit.Assert;
@@ -580,8 +582,8 @@ public class BigFractionTest {
     public void testBigDecimalValue() {
         Assert.assertEquals(new BigDecimal(0.5), BigFraction.of(1, 2).bigDecimalValue());
         Assert.assertEquals(new BigDecimal("0.0003"), BigFraction.of(3, 10000).bigDecimalValue());
-        Assert.assertEquals(new BigDecimal("0"), BigFraction.of(1, 3).bigDecimalValue(BigDecimal.ROUND_DOWN));
-        Assert.assertEquals(new BigDecimal("0.333"), BigFraction.of(1, 3).bigDecimalValue(3, BigDecimal.ROUND_DOWN));
+        Assert.assertEquals(new BigDecimal("0"), BigFraction.of(1, 3).bigDecimalValue(RoundingMode.DOWN));
+        Assert.assertEquals(new BigDecimal("0.333"), BigFraction.of(1, 3).bigDecimalValue(3, RoundingMode.DOWN));
     }
 
     @Test
@@ -648,4 +650,28 @@ public class BigFractionTest {
             Assert.assertEquals(fraction, TestUtils.serializeAndRecover(fraction));
         }
     }
+    
+    
+    @Test
+    public void testParse() {
+        String[] validExpressions = new String[] {
+                "3", 
+                "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(2147483647, 2147483648L),
+                BigFraction.of(new BigInteger("9223372036854775807"),
+                        new BigInteger("9223372036854775808"))
+        };
+        int inc = 0;
+        for (BigFraction fraction: fractions) {
+            Assert.assertEquals(fraction, 
+                    BigFraction.parse(validExpressions[inc]));
+            inc++;
+        }
+    }
 }