Repository: commons-numbers Updated Branches: refs/heads/fraction__NUMBERS-6 fe27e8ec9 -> dca007d22
NUMBERS-6: Make NumbersArithmeticException a private exception within ArithmeticUtils and change public API to reflect java.lang.ArithmeticException Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/dca007d2 Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/dca007d2 Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/dca007d2 Branch: refs/heads/fraction__NUMBERS-6 Commit: dca007d2226649a55bd3ee512580ca63d7354e56 Parents: fe27e8e Author: Ray DeCampo <r...@decampo.org> Authored: Sun Jan 29 10:14:14 2017 -0500 Committer: Ray DeCampo <r...@decampo.org> Committed: Sun Jan 29 10:14:14 2017 -0500 ---------------------------------------------------------------------- .../commons/numbers/core/ArithmeticUtils.java | 83 ++++++++++++++------ .../core/NumbersArithmeticException.java | 54 ------------- .../numbers/core/ArithmeticUtilsTest.java | 52 ++++++------ .../commons/numbers/fraction/Fraction.java | 12 +-- .../numbers/fraction/FractionException.java | 9 +-- .../numbers/fraction/BigFractionTest.java | 5 +- .../commons/numbers/fraction/FractionTest.java | 51 ++++++------ 7 files changed, 117 insertions(+), 149 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java index 4f1d6cf..ee502ca 100644 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java @@ -17,6 +17,7 @@ package org.apache.commons.numbers.core; import java.math.BigInteger; +import java.text.MessageFormat; /** * Some useful, arithmetics related, additions to the built-in functions in @@ -36,11 +37,11 @@ public final class ArithmeticUtils { * @param x an addend * @param y an addend * @return the sum {@code x+y} - * @throws NumbersArithmeticException if the result can not be represented + * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ public static int addAndCheck(int x, int y) - throws NumbersArithmeticException { + throws ArithmeticException { long s = (long)x + (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in addition: {0} + {1}", x, y); @@ -54,9 +55,9 @@ public final class ArithmeticUtils { * @param a an addend * @param b an addend * @return the sum {@code a+b} - * @throws NumbersArithmeticException if the result can not be represented as an long + * @throws ArithmeticException if the result can not be represented as an long */ - public static long addAndCheck(long a, long b) throws NumbersArithmeticException { + public static long addAndCheck(long a, long b) throws ArithmeticException { return addAndCheck(a, b, "overflow in addition: {0} + {1}"); } @@ -84,10 +85,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor (never negative). - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ - public static int gcd(int p, int q) throws NumbersArithmeticException { + public static int gcd(int p, int q) throws ArithmeticException { int a = p; int b = q; if (a == 0 || @@ -223,10 +224,10 @@ public final class ArithmeticUtils { * @param p Number. * @param q Number. * @return the greatest common divisor, never negative. - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code long} value. */ - public static long gcd(final long p, final long q) throws NumbersArithmeticException { + public static long gcd(final long p, final long q) throws ArithmeticException { long u = p; long v = q; if ((u == 0) || (v == 0)) { @@ -302,10 +303,10 @@ public final class ArithmeticUtils { * @param a Number. * @param b Number. * @return the least common multiple, never negative. - * @throws NumbersArithmeticException if the result cannot be represented as + * @throws ArithmeticException if the result cannot be represented as * a non-negative {@code int} value. */ - public static int lcm(int a, int b) throws NumbersArithmeticException { + public static int lcm(int a, int b) throws ArithmeticException { if (a == 0 || b == 0){ return 0; } @@ -335,10 +336,10 @@ public final class ArithmeticUtils { * @param a Number. * @param b Number. * @return the least common multiple, never negative. - * @throws NumbersArithmeticException if the result cannot be represented + * @throws ArithmeticException if the result cannot be represented * as a non-negative {@code long} value. */ - public static long lcm(long a, long b) throws NumbersArithmeticException { + public static long lcm(long a, long b) throws ArithmeticException { if (a == 0 || b == 0){ return 0; } @@ -356,10 +357,10 @@ public final class ArithmeticUtils { * @param x Factor. * @param y Factor. * @return the product {@code x * y}. - * @throws NumbersArithmeticException if the result can not be + * @throws ArithmeticException if the result can not be * represented as an {@code int}. */ - public static int mulAndCheck(int x, int y) throws NumbersArithmeticException { + public static int mulAndCheck(int x, int y) throws ArithmeticException { long m = ((long)x) * ((long)y); if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) { throw new NumbersArithmeticException(); @@ -373,10 +374,10 @@ public final class ArithmeticUtils { * @param a Factor. * @param b Factor. * @return the product {@code a * b}. - * @throws NumbersArithmeticException if the result can not be represented + * @throws ArithmeticException if the result can not be represented * as a {@code long}. */ - public static long mulAndCheck(long a, long b) throws NumbersArithmeticException { + public static long mulAndCheck(long a, long b) throws ArithmeticException { long ret; if (a > b) { // use symmetry to reduce boundary cases @@ -426,10 +427,10 @@ public final class ArithmeticUtils { * @param x Minuend. * @param y Subtrahend. * @return the difference {@code x - y}. - * @throws NumbersArithmeticException if the result can not be represented + * @throws ArithmeticException if the result can not be represented * as an {@code int}. */ - public static int subAndCheck(int x, int y) throws NumbersArithmeticException { + public static int subAndCheck(int x, int y) throws ArithmeticException { long s = (long)x - (long)y; if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) { throw new NumbersArithmeticException("overflow in subtraction: {0} - {1}", x, y); @@ -443,10 +444,10 @@ public final class ArithmeticUtils { * @param a Value. * @param b Value. * @return the difference {@code a - b}. - * @throws NumbersArithmeticException if the result can not be represented as a + * @throws ArithmeticException if the result can not be represented as a * {@code long}. */ - public static long subAndCheck(long a, long b) throws NumbersArithmeticException { + public static long subAndCheck(long a, long b) throws ArithmeticException { long ret; if (b == Long.MIN_VALUE) { if (a < 0) { @@ -468,11 +469,11 @@ public final class ArithmeticUtils { * @param e Exponent (must be positive or zero). * @return \( k^e \) * @throws IllegalArgumentException if {@code e < 0}. - * @throws NumbersArithmeticException if the result would overflow. + * @throws ArithmeticException if the result would overflow. */ public static int pow(final int k, final int e) - throws NumbersArithmeticException { + throws ArithmeticException { if (e < 0) { throw new IllegalArgumentException("negative exponent ({" + e + "})"); } @@ -503,11 +504,11 @@ public final class ArithmeticUtils { * @param e Exponent (must be positive or zero). * @return \( k^e \) * @throws IllegalArgumentException if {@code e < 0}. - * @throws NumbersArithmeticException if the result would overflow. + * @throws ArithmeticException if the result would overflow. */ public static long pow(final long k, final int e) - throws NumbersArithmeticException { + throws ArithmeticException { if (e < 0) { throw new IllegalArgumentException("negative exponent ({" + e + "})"); } @@ -607,10 +608,10 @@ public final class ArithmeticUtils { * @param b Addend. * @param pattern Pattern to use for any thrown exception. * @return the sum {@code a + b}. - * @throws NumbersArithmeticException if the result cannot be represented + * @throws ArithmeticException if the result cannot be represented * as a {@code long}. */ - private static long addAndCheck(long a, long b, String message) throws NumbersArithmeticException { + private static long addAndCheck(long a, long b, String message) throws ArithmeticException { final long result = a + b; if (!((a ^ b) < 0 || (a ^ result) >= 0)) { throw new NumbersArithmeticException(message, a, b); @@ -750,4 +751,34 @@ public final class ArithmeticUtils { return dividend >= 0L || dividend < divisor ? 0L : 1L; } + private static class NumbersArithmeticException extends ArithmeticException { + /** Serializable version Id. */ + private static final long serialVersionUID = -6024911025449780474L; + + private final Object[] formatArguments; + + /** + * Default constructor. + */ + public NumbersArithmeticException() { + this("arithmetic exception"); + } + + /** + * Constructor with a specific message. + * + * @param message Message pattern providing the specific context of + * the error. + * @param args Arguments. + */ + public NumbersArithmeticException(String message, Object ... args) { + super(message); + this.formatArguments = args; + } + + @Override + public String getMessage() { + return MessageFormat.format(super.getMessage(), formatArguments); + } + } } http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NumbersArithmeticException.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NumbersArithmeticException.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NumbersArithmeticException.java deleted file mode 100644 index a910e80..0000000 --- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NumbersArithmeticException.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.numbers.core; - -import java.text.MessageFormat; - -/** - * Base class for arithmetic exceptions. - */ -public class NumbersArithmeticException extends ArithmeticException { - /** Serializable version Id. */ - private static final long serialVersionUID = -6024911025449780474L; - - private final Object[] formatArguments; - - /** - * Default constructor. - */ - public NumbersArithmeticException() { - this("arithmetic exception"); - } - - /** - * Constructor with a specific message. - * - * @param message Message pattern providing the specific context of - * the error. - * @param args Arguments. - */ - public NumbersArithmeticException(String message, Object ... args) { - super(message); - this.formatArguments = args; - } - - @Override - public String getMessage() { - return MessageFormat.format(super.getMessage(), formatArguments); - } - -} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java index 500aca3..a7185da 100644 --- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java +++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java @@ -37,12 +37,12 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.addAndCheck(big, 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } try { ArithmeticUtils.addAndCheck(bigNeg, -1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } } @@ -99,21 +99,21 @@ public class ArithmeticUtilsTest { // gcd(Integer.MIN_VALUE, 0) > Integer.MAX_VALUE ArithmeticUtils.gcd(Integer.MIN_VALUE, 0); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } try { // gcd(0, Integer.MIN_VALUE) > Integer.MAX_VALUE ArithmeticUtils.gcd(0, Integer.MIN_VALUE); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } try { // gcd(Integer.MIN_VALUE, Integer.MIN_VALUE) > Integer.MAX_VALUE ArithmeticUtils.gcd(Integer.MIN_VALUE, Integer.MIN_VALUE); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } } @@ -173,21 +173,21 @@ public class ArithmeticUtilsTest { // gcd(Long.MIN_VALUE, 0) > Long.MAX_VALUE ArithmeticUtils.gcd(Long.MIN_VALUE, 0); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } try { // gcd(0, Long.MIN_VALUE) > Long.MAX_VALUE ArithmeticUtils.gcd(0, Long.MIN_VALUE); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } try { // gcd(Long.MIN_VALUE, Long.MIN_VALUE) > Long.MAX_VALUE ArithmeticUtils.gcd(Long.MIN_VALUE, Long.MIN_VALUE); Assert.fail("expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } } @@ -220,7 +220,7 @@ public class ArithmeticUtilsTest { // lcm == abs(MIN_VALUE) cannot be represented as a nonnegative int ArithmeticUtils.lcm(Integer.MIN_VALUE, 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } @@ -228,14 +228,14 @@ public class ArithmeticUtilsTest { // lcm == abs(MIN_VALUE) cannot be represented as a nonnegative int ArithmeticUtils.lcm(Integer.MIN_VALUE, 1<<20); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } try { ArithmeticUtils.lcm(Integer.MAX_VALUE, Integer.MAX_VALUE - 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } } @@ -269,7 +269,7 @@ public class ArithmeticUtilsTest { // lcm == abs(MIN_VALUE) cannot be represented as a nonnegative int ArithmeticUtils.lcm(Long.MIN_VALUE, 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } @@ -277,7 +277,7 @@ public class ArithmeticUtilsTest { // lcm == abs(MIN_VALUE) cannot be represented as a nonnegative int ArithmeticUtils.lcm(Long.MIN_VALUE, 1<<20); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } @@ -286,7 +286,7 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.lcm(Long.MAX_VALUE, Long.MAX_VALUE - 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException expected) { + } catch (ArithmeticException expected) { // expected } } @@ -299,12 +299,12 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.mulAndCheck(big, 2); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } try { ArithmeticUtils.mulAndCheck(bigNeg, 2); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } } @@ -340,12 +340,12 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.subAndCheck(big, -1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } try { ArithmeticUtils.subAndCheck(bigNeg, 1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { } } @@ -355,7 +355,7 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.subAndCheck(big, -1); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { Assert.assertTrue(ex.getMessage().length() > 1); } } @@ -444,7 +444,7 @@ public class ArithmeticUtilsTest { } - @Test(expected=NumbersArithmeticException.class) + @Test(expected=ArithmeticException.class) public void testPowIntOverflow() { ArithmeticUtils.pow(21, 8); } @@ -459,7 +459,7 @@ public class ArithmeticUtilsTest { ArithmeticUtils.pow(base, 7)); } - @Test(expected=NumbersArithmeticException.class) + @Test(expected=ArithmeticException.class) public void testPowNegativeIntOverflow() { ArithmeticUtils.pow(-21, 8); } @@ -492,7 +492,7 @@ public class ArithmeticUtilsTest { } } - @Test(expected=NumbersArithmeticException.class) + @Test(expected=ArithmeticException.class) public void testPowLongOverflow() { ArithmeticUtils.pow(21, 15); } @@ -507,7 +507,7 @@ public class ArithmeticUtilsTest { ArithmeticUtils.pow(base, 14)); } - @Test(expected=NumbersArithmeticException.class) + @Test(expected=ArithmeticException.class) public void testPowNegativeLongOverflow() { ArithmeticUtils.pow(-21L, 15); } @@ -558,7 +558,7 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.addAndCheck(a, b); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { // success } } @@ -567,7 +567,7 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.mulAndCheck(a, b); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { // success } } @@ -576,7 +576,7 @@ public class ArithmeticUtilsTest { try { ArithmeticUtils.subAndCheck(a, b); Assert.fail("Expecting ArithmeticException"); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { // success } } http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java ---------------------------------------------------------------------- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java index c000f2c..005e6e6 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java @@ -422,7 +422,7 @@ public class Fraction * @param fraction the fraction to add, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullPointerException if the fraction is {@code null} - * @throws NumbersArithmeticException if the resulting numerator or denominator exceeds + * @throws ArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction add(Fraction fraction) { @@ -445,7 +445,7 @@ public class Fraction * @param fraction the fraction to subtract, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullPointerException if the fraction is {@code null} - * @throws NumbersArithmeticException if the resulting numerator or denominator + * @throws ArithmeticException if the resulting numerator or denominator * cannot be represented in an {@code int}. */ public Fraction subtract(Fraction fraction) { @@ -468,7 +468,7 @@ public class Fraction * @param isAdd true to add, false to subtract * @return a {@code Fraction} instance with the resulting values * @throws NullPointerException if the fraction is {@code null} - * @throws NumbersArithmeticException if the resulting numerator or denominator + * @throws ArithmeticException if the resulting numerator or denominator * cannot be represented in an {@code int}. */ private Fraction addSub(Fraction fraction, boolean isAdd) { @@ -525,7 +525,7 @@ public class Fraction * @param fraction the fraction to multiply by, must not be {@code null} * @return a {@code Fraction} instance with the resulting values * @throws NullPointerException if the fraction is {@code null} - * @throws NumbersArithmeticException if the resulting numerator or denominator exceeds + * @throws ArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction multiply(Fraction fraction) { @@ -560,7 +560,7 @@ public class Fraction * @return a {@code Fraction} instance with the resulting values * @throws IllegalArgumentException if the fraction is {@code null} * @throws FractionException if the fraction to divide by is zero - * @throws NumbersArithmeticException if the resulting numerator or denominator exceeds + * @throws ArithmeticException if the resulting numerator or denominator exceeds * {@code Integer.MAX_VALUE} */ public Fraction divide(Fraction fraction) { @@ -604,7 +604,7 @@ public class Fraction * @param numerator the numerator, for example the three in 'three sevenths' * @param denominator the denominator, for example the seven in 'three sevenths' * @return a new fraction instance, with the numerator and denominator reduced - * @throws NumbersArithmeticException if the denominator is {@code zero} + * @throws ArithmeticException if the denominator is {@code zero} */ public static Fraction getReducedFraction(int numerator, int denominator) { if (denominator == 0) { http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java ---------------------------------------------------------------------- diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java index 6080981..d0a3788 100644 --- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java +++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionException.java @@ -16,12 +16,10 @@ */ package org.apache.commons.numbers.fraction; -import org.apache.commons.numbers.core.NumbersArithmeticException; - /** * Base class for all exceptions thrown in the module. */ -public class FractionException extends NumbersArithmeticException { +public class FractionException extends ArithmeticException { /** Serializable version identifier. */ private static final long serialVersionUID = 201701191744L; @@ -36,9 +34,4 @@ public class FractionException extends NumbersArithmeticException { this.formatArguments = formatArguments; } - public FractionException(String message, Throwable cause, Object... formatArguments) { - super(message, cause); - this.formatArguments = formatArguments; - } - } http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java ---------------------------------------------------------------------- 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 c4c3e12..b7ce258 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,7 +18,6 @@ package org.apache.commons.numbers.fraction; import java.math.BigDecimal; import java.math.BigInteger; -import org.apache.commons.numbers.core.NumbersArithmeticException; import org.apache.commons.numbers.core.TestUtils; import org.junit.Assert; @@ -435,8 +434,8 @@ public class BigFractionTest { BigFraction f2 = BigFraction.ZERO; try { f1.divide(f2); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) { + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) { } f1 = new BigFraction(0, 5); http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/dca007d2/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionTest.java ---------------------------------------------------------------------- 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 3b2c4cb..a2c1f8e 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 @@ -16,7 +16,6 @@ */ package org.apache.commons.numbers.fraction; -import org.apache.commons.numbers.core.NumbersArithmeticException; import org.apache.commons.numbers.core.TestUtils; import org.junit.Assert; import org.junit.Test; @@ -47,13 +46,13 @@ public class FractionTest { try { new Fraction(Integer.MIN_VALUE, -1); Assert.fail(); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { // success } try { new Fraction(1, Integer.MIN_VALUE); Assert.fail(); - } catch (NumbersArithmeticException ex) { + } catch (ArithmeticException ex) { // success } @@ -323,8 +322,8 @@ public class FractionTest { f = new Fraction(Integer.MIN_VALUE, 1); try { f = f.negate(); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} } @Test @@ -379,35 +378,35 @@ public class FractionTest { try { f = f.add(Fraction.ONE); // should overflow - Assert.fail("expecting NumbersArithmeticException but got: " + f.toString()); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException but got: " + f.toString()); + } catch (ArithmeticException ex) {} // denominator should not be a multiple of 2 or 3 to trigger overflow f1 = new Fraction(Integer.MIN_VALUE, 5); f2 = new Fraction(-1,5); try { f = f1.add(f2); // should overflow - Assert.fail("expecting NumbersArithmeticException but got: " + f.toString()); + Assert.fail("expecting ArithmeticException but got: " + f.toString()); } catch (FractionOverflowException ex) {} try { f= new Fraction(-Integer.MAX_VALUE, 1); f = f.add(f); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} try { f= new Fraction(-Integer.MAX_VALUE, 1); f = f.add(f); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} f1 = new Fraction(3,327680); f2 = new Fraction(2,59049); try { f = f1.add(f2); // should overflow - Assert.fail("expecting NumbersArithmeticException but got: " + f.toString()); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException but got: " + f.toString()); + } catch (ArithmeticException ex) {} } @Test @@ -457,13 +456,13 @@ public class FractionTest { try { f1 = new Fraction(1, Integer.MAX_VALUE); f = f1.divide(f1.reciprocal()); // should overflow - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} try { f1 = new Fraction(1, -Integer.MAX_VALUE); f = f1.divide(f1.reciprocal()); // should overflow - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} f1 = new Fraction(6, 35); f = f1.divide(15); @@ -542,8 +541,8 @@ public class FractionTest { f1 = new Fraction(1, Integer.MAX_VALUE); f2 = new Fraction(1, Integer.MAX_VALUE - 1); f = f1.subtract(f2); - Assert.fail("expecting NumbersArithmeticException"); //should overflow - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); //should overflow + } catch (ArithmeticException ex) {} // denominator should not be a multiple of 2 or 3 to trigger overflow f1 = new Fraction(Integer.MIN_VALUE, 5); @@ -556,21 +555,21 @@ public class FractionTest { try { f= new Fraction(Integer.MIN_VALUE, 1); f = f.subtract(Fraction.ONE); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} try { f= new Fraction(Integer.MAX_VALUE, 1); f = f.subtract(Fraction.ONE.negate()); - Assert.fail("expecting NumbersArithmeticException"); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException"); + } catch (ArithmeticException ex) {} f1 = new Fraction(3,327680); f2 = new Fraction(2,59049); try { f = f1.subtract(f2); // should overflow - Assert.fail("expecting NumbersArithmeticException but got: " + f.toString()); - } catch (NumbersArithmeticException ex) {} + Assert.fail("expecting ArithmeticException but got: " + f.toString()); + } catch (ArithmeticException ex) {} } @Test