commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject git commit: Added proper checking of expected exception in FastMath tests.
Date Tue, 07 Oct 2014 14:33:15 GMT
Repository: commons-math
Updated Branches:
  refs/heads/master deb5e5298 -> 9d14fe21a


Added proper checking of expected exception in FastMath tests.

Some of the new functions trigger exceptions in the data range used for
tests (overflows near range end, divisions by zero). The FastMath
implementation throws compatible exception in the same cases, this is
now tested correctly.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/9d14fe21
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/9d14fe21
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/9d14fe21

Branch: refs/heads/master
Commit: 9d14fe21a4044dafc984e1626ac5f465e35179ee
Parents: deb5e52
Author: Luc Maisonobe <luc@apache.org>
Authored: Tue Oct 7 16:32:59 2014 +0200
Committer: Luc Maisonobe <luc@apache.org>
Committed: Tue Oct 7 16:32:59 2014 +0200

----------------------------------------------------------------------
 .../util/FastMathStrictComparisonTest.java      | 22 +++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/9d14fe21/src/test/java/org/apache/commons/math3/util/FastMathStrictComparisonTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/util/FastMathStrictComparisonTest.java
b/src/test/java/org/apache/commons/math3/util/FastMathStrictComparisonTest.java
index 6f0483e..0a4cef5 100644
--- a/src/test/java/org/apache/commons/math3/util/FastMathStrictComparisonTest.java
+++ b/src/test/java/org/apache/commons/math3/util/FastMathStrictComparisonTest.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.math3.exception.MathArithmeticException;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -159,12 +160,23 @@ public class FastMathStrictComparisonTest {
     }
 
     private static void callMethods(Method mathMethod, Method fastMethod,
-            Object[] params, int[] entries) throws IllegalAccessException,
-            InvocationTargetException {
+            Object[] params, int[] entries) throws IllegalAccessException {
         try {
-            Object expected = mathMethod.invoke(mathMethod, params);
-            Object actual = fastMethod.invoke(mathMethod, params);
-            if (!expected.equals(actual)) {
+            Object expected;
+            try {
+                expected = mathMethod.invoke(mathMethod, params);
+            } catch (InvocationTargetException ite) {
+                expected = ite.getCause();
+            }
+            Object actual;
+            try {
+                actual = fastMethod.invoke(mathMethod, params);
+            } catch (InvocationTargetException ite) {
+                actual = ite.getCause();
+            }
+            if (expected instanceof ArithmeticException) {
+                Assert.assertEquals(MathArithmeticException.class, actual.getClass());
+            } else  if (!expected.equals(actual)) {
                 reportFailedResults(mathMethod, params, expected, actual, entries);
             }
         } catch (IllegalArgumentException e) {


Mime
View raw message