You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2017/02/06 12:52:29 UTC
[08/13] commons-numbers git commit: NUMBERS-6: Remove specialized
exception from public API. FractionException becomes package private and
inherits from java.lang.ArithmeticException. Subclasses of FractionException
are eliminated.
NUMBERS-6: Remove specialized exception from public API.
FractionException becomes package private and inherits from java.lang.ArithmeticException. Subclasses of FractionException are eliminated.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/41e2f65b
Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/41e2f65b
Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/41e2f65b
Branch: refs/heads/master
Commit: 41e2f65b34c978f4377b2f043fec28a61402962d
Parents: fbb60fb
Author: Ray DeCampo <ra...@decampo.org>
Authored: Tue Jan 31 20:19:35 2017 -0500
Committer: Ray DeCampo <ra...@decampo.org>
Committed: Tue Jan 31 20:19:35 2017 -0500
----------------------------------------------------------------------
.../commons/numbers/fraction/BigFraction.java | 21 ++++----
.../commons/numbers/fraction/Fraction.java | 42 +++++++---------
.../fraction/FractionConversionException.java | 49 ------------------
.../numbers/fraction/FractionException.java | 7 ++-
.../numbers/fraction/FractionFormat.java | 4 +-
.../fraction/FractionOverflowException.java | 47 -----------------
.../fraction/FractionParseException.java | 9 +++-
.../fraction/ZeroDenominatorException.java | 53 --------------------
.../numbers/fraction/BigFractionFormatTest.java | 12 ++---
.../numbers/fraction/BigFractionTest.java | 22 ++++----
.../numbers/fraction/FractionFormatTest.java | 16 +++---
.../commons/numbers/fraction/FractionTest.java | 20 ++++----
12 files changed, 78 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
----------------------------------------------------------------------
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 4ba8e01..a5ab6f7 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
@@ -108,7 +108,7 @@ public class BigFraction
checkNotNull(num, "numerator");
checkNotNull(den, "denominator");
if (den.signum() == 0) {
- throw new ZeroDenominatorException();
+ throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
if (num.signum() == 0) {
numerator = BigInteger.ZERO;
@@ -214,8 +214,7 @@ public class BigFraction
* @see #BigFraction(double)
*/
public BigFraction(final double value, final double epsilon,
- final int maxIterations)
- throws FractionConversionException {
+ final int maxIterations) {
this(value, epsilon, Integer.MAX_VALUE, maxIterations);
}
@@ -254,14 +253,13 @@ public class BigFraction
* if the continued fraction failed to converge.
*/
private BigFraction(final double value, final double epsilon,
- final int maxDenominator, int maxIterations)
- throws FractionConversionException {
+ final int maxDenominator, int maxIterations) {
long overflow = Integer.MAX_VALUE;
double r0 = value;
long a0 = (long) Math.floor(r0);
if (Math.abs(a0) > overflow) {
- throw new FractionConversionException(value, a0, 1l);
+ throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, a0, 1l);
}
// check for (almost) integer arguments, which should not go
@@ -294,7 +292,7 @@ public class BigFraction
if (epsilon == 0.0 && Math.abs(q1) < maxDenominator) {
break;
}
- throw new FractionConversionException(value, p2, q2);
+ throw new FractionException(FractionException.ERROR_CONVERSION_OVERFLOW, value, p2, q2);
}
final double convergent = (double) p2 / (double) q2;
@@ -313,7 +311,7 @@ public class BigFraction
} while (!stop);
if (n >= maxIterations) {
- throw new FractionConversionException(value, maxIterations);
+ throw new FractionException(FractionException.ERROR_CONVERSION, value, maxIterations);
}
if (q2 < maxDenominator) {
@@ -342,8 +340,7 @@ public class BigFraction
* @throws FractionConversionException
* if the continued fraction failed to converge.
*/
- public BigFraction(final double value, final int maxDenominator)
- throws FractionConversionException {
+ public BigFraction(final double value, final int maxDenominator) {
this(value, 0, maxDenominator, 100);
}
@@ -625,7 +622,7 @@ public class BigFraction
public BigFraction divide(final BigInteger bg) {
checkNotNull(bg, "bg");
if (bg.signum() == 0) {
- throw new ZeroDenominatorException();
+ throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
if (numerator.signum() == 0) {
return ZERO;
@@ -674,7 +671,7 @@ public class BigFraction
public BigFraction divide(final BigFraction fraction) {
checkNotNull(fraction, "fraction");
if (fraction.numerator.signum() == 0) {
- throw new ZeroDenominatorException(fraction.denominator, fraction.numerator);
+ throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
if (numerator.signum() == 0) {
return ZERO;
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/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 005e6e6..31abd17 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
@@ -86,10 +86,10 @@ public class Fraction
/**
* Create a fraction given the double value.
* @param value the double value to convert to a fraction.
- * @throws FractionConversionException if the continued fraction failed to
+ * @throws IllegalArgumentException if the continued fraction failed to
* converge.
*/
- public Fraction(double value) throws FractionConversionException {
+ public Fraction(double value) {
this(value, DEFAULT_EPSILON, 100);
}
@@ -106,11 +106,10 @@ public class Fraction
* @param epsilon maximum error allowed. The resulting fraction is within
* {@code epsilon} of {@code value}, in absolute terms.
* @param maxIterations maximum number of convergents
- * @throws FractionConversionException if the continued fraction failed to
+ * @throws IllegalArgumentException if the continued fraction failed to
* converge.
*/
public Fraction(double value, double epsilon, int maxIterations)
- throws FractionConversionException
{
this(value, epsilon, Integer.MAX_VALUE, maxIterations);
}
@@ -126,11 +125,10 @@ public class Fraction
* </p>
* @param value the double value to convert to a fraction.
* @param maxDenominator The maximum allowed value for denominator
- * @throws FractionConversionException if the continued fraction failed to
+ * @throws IllegalArgumentException if the continued fraction failed to
* converge
*/
public Fraction(double value, int maxDenominator)
- throws FractionConversionException
{
this(value, 0, maxDenominator, 100);
}
@@ -163,17 +161,16 @@ public class Fraction
* {@code epsilon} of {@code value}, in absolute terms.
* @param maxDenominator maximum denominator value allowed.
* @param maxIterations maximum number of convergents
- * @throws FractionConversionException if the continued fraction failed to
+ * @throws IllegalArgumentException if the continued fraction failed to
* converge.
*/
private Fraction(double value, double epsilon, int maxDenominator, int maxIterations)
- throws FractionConversionException, FractionOverflowException
{
long overflow = Integer.MAX_VALUE;
double r0 = value;
long a0 = (long)Math.floor(r0);
if (Math.abs(a0) > overflow) {
- throw new FractionConversionException(value, a0, 1l);
+ throw new FractionException(FractionException.ERROR_CONVERSION, value, a0, 1l);
}
// check for (almost) integer arguments, which should not go to iterations.
@@ -206,7 +203,7 @@ public class Fraction
if (epsilon == 0.0 && Math.abs(q1) < maxDenominator) {
break;
}
- throw new FractionConversionException(value, p2, q2);
+ throw new FractionException(FractionException.ERROR_CONVERSION, value, p2, q2);
}
double convergent = (double)p2 / (double)q2;
@@ -223,7 +220,7 @@ public class Fraction
} while (!stop);
if (n >= maxIterations) {
- throw new FractionConversionException(value, maxIterations);
+ throw new FractionException(FractionException.ERROR_CONVERSION, value, maxIterations);
}
if (q2 < maxDenominator) {
@@ -250,16 +247,17 @@ public class Fraction
* reduced to lowest terms.
* @param num the numerator.
* @param den the denominator.
- * @throws FractionException if the denominator is {@code zero}
+ * @throws ArithmeticException if the denominator is {@code zero}
+ * or if integer overflow occurs
*/
public Fraction(int num, int den) {
if (den == 0) {
- throw new ZeroDenominatorException(num, den);
+ throw new ArithmeticException("division by zero");
}
if (den < 0) {
if (num == Integer.MIN_VALUE ||
den == Integer.MIN_VALUE) {
- throw new FractionOverflowException(num, den);
+ throw new FractionException("overflow in fraction {0}/{1}, cannot negate", num, den);
}
num = -num;
den = -den;
@@ -402,7 +400,7 @@ public class Fraction
*/
public Fraction negate() {
if (numerator==Integer.MIN_VALUE) {
- throw new FractionOverflowException(numerator, denominator);
+ throw new FractionException(FractionException.ERROR_NEGATION_OVERFLOW, numerator, denominator);
}
return new Fraction(-numerator, denominator);
}
@@ -510,7 +508,7 @@ public class Fraction
// result is (t/d2) / (u'/d1)(v'/d2)
BigInteger w = t.divide(BigInteger.valueOf(d2));
if (w.bitLength() > 31) {
- throw new FractionOverflowException(
+ throw new FractionException(
"overflow, numerator too large after multiply: {0}", w.toString(), "");
}
return new Fraction (w.intValue(),
@@ -558,10 +556,9 @@ public class Fraction
*
* @param fraction the fraction to divide by, must not be {@code null}
* @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 ArithmeticException if the resulting numerator or denominator exceeds
- * {@code Integer.MAX_VALUE}
+ * @throws ArithmeticException if the fraction to divide by is zero
+ * or if the resulting numerator or denominator
+ * exceeds {@code Integer.MAX_VALUE}
*/
public Fraction divide(Fraction fraction) {
if (fraction == null) {
@@ -608,7 +605,7 @@ public class Fraction
*/
public static Fraction getReducedFraction(int numerator, int denominator) {
if (denominator == 0) {
- throw new ZeroDenominatorException(numerator, denominator);
+ throw new FractionException(FractionException.ERROR_ZERO_DENOMINATOR);
}
if (numerator==0) {
return ZERO; // normalize zero.
@@ -620,7 +617,7 @@ public class Fraction
if (denominator < 0) {
if (numerator==Integer.MIN_VALUE ||
denominator==Integer.MIN_VALUE) {
- throw new FractionOverflowException(numerator, denominator);
+ throw new FractionException("overflow in fraction {0}/{1}, cannot negate", numerator, denominator);
}
numerator = -numerator;
denominator = -denominator;
@@ -658,5 +655,4 @@ public class Fraction
public FractionField getField() {
return FractionField.getInstance();
}
-
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java
deleted file mode 100644
index 9d705aa..0000000
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionConversionException.java
+++ /dev/null
@@ -1,49 +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.fraction;
-
-/**
- * Error thrown when a double value cannot be converted to a fraction
- * in the allowed number of iterations.
- */
-public class FractionConversionException extends FractionException {
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 201701181859L;
-
- /**
- * Constructs an exception with specified formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param value double value to convert
- * @param maxIterations maximal number of iterations allowed
- */
- public FractionConversionException(double value, int maxIterations) {
- super("Unable to convert {0} to fraction after {1} iterations", value, maxIterations);
- }
-
- /**
- * Constructs an exception with specified formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param value double value to convert
- * @param p current numerator
- * @param q current denominator
- */
- public FractionConversionException(double value, long p, long q) {
- super("Overflow trying to convert {0} to fraction ({1}/{2})", value, p, q);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/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 d0a3788..d5fb6df 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
@@ -19,11 +19,16 @@ package org.apache.commons.numbers.fraction;
/**
* Base class for all exceptions thrown in the module.
*/
-public class FractionException extends ArithmeticException {
+class FractionException extends ArithmeticException {
/** Serializable version identifier. */
private static final long serialVersionUID = 201701191744L;
+ public static final String ERROR_CONVERSION_OVERFLOW = "Overflow trying to convert {0} to fraction ({1}/{2})";
+ public static final String ERROR_CONVERSION = "Unable to convert {0} to fraction after {1} iterations";
+ public static final String ERROR_NEGATION_OVERFLOW = "overflow in fraction {0}/{1}, cannot negate";
+ public static final String ERROR_ZERO_DENOMINATOR = "denominator must be different from 0";
+
protected Object[] formatArguments;
public FractionException() {
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
index be63a7b..be6c8a2 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionFormat.java
@@ -163,8 +163,8 @@ public class FractionFormat extends AbstractFormat {
*/
@Override
public StringBuffer format(final Object obj,
- final StringBuffer toAppendTo, final FieldPosition pos)
- throws FractionConversionException, IllegalArgumentException {
+ final StringBuffer toAppendTo,
+ final FieldPosition pos) {
StringBuffer ret = null;
if (obj instanceof Fraction) {
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionOverflowException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionOverflowException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionOverflowException.java
deleted file mode 100644
index 08d6f81..0000000
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionOverflowException.java
+++ /dev/null
@@ -1,47 +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.fraction;
-
-/**
- * Error thrown when evaluating a fraction causes an overflow.
- */
-public class FractionOverflowException extends FractionException {
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 201701181869L;
-
- /**
- * Constructs an exception the default formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param p current numerator
- * @param q current denominator
- */
- public FractionOverflowException(long p, long q) {
- super("overflow in fraction {0}/{1}, cannot negate", p, q);
- }
-
- /**
- * Constructs an exception with specified formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param message the custom message
- * @param formatArguments arguments when formatting the message
- */
- public FractionOverflowException(String message, Object... formatArguments) {
- super(message, formatArguments);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
index 9c1d416..e48441d 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/FractionParseException.java
@@ -17,10 +17,13 @@
package org.apache.commons.numbers.fraction;
+import java.text.MessageFormat;
+import java.text.ParseException;
+
/**
* Error thrown when a string cannot be parsed into a fraction.
*/
-public class FractionParseException extends FractionException {
+public class FractionParseException extends ParseException {
/** Serializable version identifier. */
private static final long serialVersionUID = 201701181879L;
@@ -33,6 +36,8 @@ public class FractionParseException extends FractionException {
* @param type type of target object
*/
public FractionParseException(String source, int position, Class<?> type) {
- super("string \"{0}\" unparseable (from position {1}) as an object of type {2}", source, position, type);
+ super(MessageFormat.format("string \"{0}\" unparseable (from position {1}) as an object of type {2}",
+ source, position, type),
+ position);
}
}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ZeroDenominatorException.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ZeroDenominatorException.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ZeroDenominatorException.java
deleted file mode 100644
index e8940a3..0000000
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/ZeroDenominatorException.java
+++ /dev/null
@@ -1,53 +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.fraction;
-
-import java.math.BigInteger;
-
-/**
- * Error thrown when a fraction with a zero denominator is created.
- */
-public class ZeroDenominatorException extends FractionException {
-
- /** Serializable version identifier. */
- private static final long serialVersionUID = 201701191752L;
-
- public ZeroDenominatorException() {
- super("denominator must be different from 0");
- }
-
- /**
- * Constructs an exception with specified formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param p current numerator
- * @param q current denominator
- */
- public ZeroDenominatorException(long p, long q) {
- super("zero denominator in fraction {0}/{1}", p, q);
- }
-
- /**
- * Constructs an exception with specified formatted detail message.
- * Message formatting is delegated to {@link java.text.MessageFormat}.
- * @param p current numerator
- * @param q current denominator
- */
- public ZeroDenominatorException(BigInteger p, BigInteger q) {
- super("zero denominator in fraction {0}/{1}", p, q);
- }
-}
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
index fac1f54..b69663e 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionFormatTest.java
@@ -101,7 +101,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParse() {
+ public void testParse() throws Exception {
String source = "1 / 2";
{
@@ -118,7 +118,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParseInteger() {
+ public void testParseInteger() throws Exception {
String source = "10";
{
BigFraction c = properFormat.parse(source);
@@ -171,7 +171,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParseNegative() {
+ public void testParseNegative() throws Exception {
{
String source = "-1 / 2";
@@ -199,7 +199,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParseProper() {
+ public void testParseProper() throws Exception {
String source = "1 2 / 3";
{
@@ -218,7 +218,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParseProperNegative() {
+ public void testParseProperNegative() throws Exception {
String source = "-1 2 / 3";
{
BigFraction c = properFormat.parse(source);
@@ -254,7 +254,7 @@ public class BigFractionFormatTest {
}
@Test
- public void testParseBig() {
+ public void testParseBig() throws Exception {
BigFraction f1 =
improperFormat.parse("167213075789791382630275400487886041651764456874403" +
" / " +
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/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 b7ce258..55982ea 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
@@ -74,14 +74,14 @@ public class BigFractionTest {
}
try {
new BigFraction(BigInteger.ONE, BigInteger.ZERO);
- Assert.fail("Expecting ZeroDenominatorException");
- } catch (ZeroDenominatorException npe) {
+ Assert.fail("Expecting ArithmeticException");
+ } catch (ArithmeticException ignored) {
// expected
}
try {
new BigFraction(2.0 * Integer.MAX_VALUE, 1.0e-5, 100000);
- Assert.fail("Expecting FractionConversionException");
- } catch (FractionConversionException fce) {
+ Assert.fail("Expecting ArithmeticException");
+ } catch (ArithmeticException ignored) {
// expected
}
}
@@ -155,13 +155,13 @@ public class BigFractionTest {
}
// MATH-1029
- @Test(expected=FractionConversionException.class)
+ @Test(expected=ArithmeticException.class)
public void testPositiveValueOverflow() {
assertFraction((long) 1e10, 1, new BigFraction(1e10, 1000));
}
// MATH-1029
- @Test(expected=FractionConversionException.class)
+ @Test(expected=ArithmeticException.class)
public void testNegativeValueOverflow() {
assertFraction((long) -1e10, 1, new BigFraction(-1e10, 1000));
}
@@ -316,8 +316,8 @@ public class BigFractionTest {
f = new BigFraction(0, 3);
try {
f = f.reciprocal();
- Assert.fail("expecting ZeroDenominatorException");
- } catch (ZeroDenominatorException ex) {
+ Assert.fail("expecting ArithmeticException");
+ } catch (ArithmeticException ignored) {
}
// large values
@@ -584,8 +584,8 @@ public class BigFractionTest {
Assert.assertTrue(BigFraction.ZERO.equals(BigFraction.getReducedFraction(0, -1)));
try {
BigFraction.getReducedFraction(1, 0);
- Assert.fail("expecting ZeroDenominatorException");
- } catch (ZeroDenominatorException ex) {
+ Assert.fail("expecting ArithmeticException");
+ } catch (ArithmeticException ex) {
// expected
}
Assert.assertEquals(BigFraction.getReducedFraction(2, Integer.MIN_VALUE).getNumeratorAsInt(), -1);
@@ -621,7 +621,7 @@ public class BigFractionTest {
}
@Test
- public void testSerial() throws FractionConversionException {
+ public void testSerial() {
BigFraction[] fractions = {
new BigFraction(3, 4), BigFraction.ONE, BigFraction.ZERO,
new BigFraction(17), new BigFraction(Math.PI, 1000),
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
----------------------------------------------------------------------
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
index 2c9a398..af1f462 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/FractionFormatTest.java
@@ -118,7 +118,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseInteger() {
+ public void testParseInteger() throws Exception {
String source = "10";
{
Fraction c = properFormat.parse(source);
@@ -135,7 +135,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseOne1() {
+ public void testParseOne1() throws Exception {
String source = "1 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
@@ -144,7 +144,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseOne2() {
+ public void testParseOne2() throws Exception {
String source = "10 / 10";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
@@ -153,7 +153,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseZero1() {
+ public void testParseZero1() throws Exception {
String source = "0 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
@@ -162,7 +162,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseZero2() {
+ public void testParseZero2() throws Exception {
String source = "-0 / 1";
Fraction c = properFormat.parse(source);
Assert.assertNotNull(c);
@@ -209,7 +209,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseNegative() {
+ public void testParseNegative() throws Exception {
{
String source = "-1 / 2";
@@ -237,7 +237,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseProper() {
+ public void testParseProper() throws Exception {
String source = "1 2 / 3";
{
@@ -256,7 +256,7 @@ public class FractionFormatTest {
}
@Test
- public void testParseProperNegative() {
+ public void testParseProperNegative() throws Exception {
String source = "-1 2 / 3";
{
Fraction c = properFormat.parse(source);
http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/41e2f65b/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 a2c1f8e..d35092b 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
@@ -61,7 +61,7 @@ public class FractionTest {
assertFraction(15, 1, new Fraction(15.0000000000001));
}
- @Test(expected=FractionConversionException.class)
+ @Test(expected=ArithmeticException.class)
public void testGoldenRatio() {
// the golden ratio is notoriously a difficult number for continuous fraction
new Fraction((1 + Math.sqrt(5)) / 2, 1.0e-12, 25);
@@ -143,7 +143,7 @@ public class FractionTest {
Fraction f = new Fraction(a, 1.0e-12, 1000);
//System.out.println(f.getNumerator() + "/" + f.getDenominator());
Assert.fail("an exception should have been thrown");
- } catch (FractionConversionException ce) {
+ } catch (ArithmeticException ignored) {
// expected behavior
}
}
@@ -289,8 +289,8 @@ public class FractionTest {
f = new Fraction(0, 3);
try {
f = f.reciprocal();
- Assert.fail("expecting ZeroDenominatorException");
- } catch (ZeroDenominatorException ex) {}
+ Assert.fail("expecting ArithmeticException");
+ } catch (ArithmeticException ignored) {}
// large values
f = new Fraction(Integer.MAX_VALUE, 1);
@@ -387,7 +387,7 @@ public class FractionTest {
try {
f = f1.add(f2); // should overflow
Assert.fail("expecting ArithmeticException but got: " + f.toString());
- } catch (FractionOverflowException ex) {}
+ } catch (ArithmeticException ex) {}
try {
f= new Fraction(-Integer.MAX_VALUE, 1);
@@ -549,8 +549,8 @@ public class FractionTest {
f2 = new Fraction(1,5);
try {
f = f1.subtract(f2); // should overflow
- Assert.fail("expecting FractionOverflowException but got: " + f.toString());
- } catch (FractionOverflowException ex) {}
+ Assert.fail("expecting ArithmeticException but got: " + f.toString());
+ } catch (ArithmeticException ex) {}
try {
f= new Fraction(Integer.MIN_VALUE, 1);
@@ -593,8 +593,8 @@ public class FractionTest {
Assert.assertTrue(Fraction.ZERO.equals(Fraction.getReducedFraction(0, -1)));
try {
Fraction.getReducedFraction(1, 0);
- Assert.fail("expecting ZeroDenominatorException");
- } catch (ZeroDenominatorException ex) {
+ Assert.fail("expecting ArithmeticException");
+ } catch (ArithmeticException ignored) {
// expected
}
Assert.assertEquals(Fraction.getReducedFraction
@@ -611,7 +611,7 @@ public class FractionTest {
}
@Test
- public void testSerial() throws FractionConversionException {
+ public void testSerial() {
Fraction[] fractions = {
new Fraction(3, 4), Fraction.ONE, Fraction.ZERO,
new Fraction(17), new Fraction(Math.PI, 1000),