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 2020/12/11 18:36:32 UTC

[commons-math] 02/02: MATH-1565: Add unit tests.

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-math.git

commit a2c3868fb8115bccb2920d89388927ff889f619c
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri Dec 11 19:35:02 2020 +0100

    MATH-1565: Add unit tests.
    
    Thanks to Randy Strauss.
---
 src/changes/changes.xml                            |  2 +-
 .../commons/math4/linear/MatrixUtilsTest.java      | 40 ++++++++++++++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 20379fa..0876768 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -54,7 +54,7 @@ If the output is not quite correct, check for invisible trailing spaces!
     </release>
 
     <release version="4.0" date="XXXX-XX-XX" description="">
-      <action dev="erans" type="fix" issue="MATH-1565">
+      <action dev="erans" type="fix" issue="MATH-1565" due-to="Randy Strauss">
         Add context to "OutOfRangeException".
       </action>
       <action dev="erans" type="update" issue="MATH-1562" due-to="Frank Ulbricht">
diff --git a/src/test/java/org/apache/commons/math4/linear/MatrixUtilsTest.java b/src/test/java/org/apache/commons/math4/linear/MatrixUtilsTest.java
index 9940c1c..e7486f2 100644
--- a/src/test/java/org/apache/commons/math4/linear/MatrixUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/MatrixUtilsTest.java
@@ -22,6 +22,7 @@ import org.apache.commons.math4.TestUtils;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.NotStrictlyPositiveException;
 import org.apache.commons.math4.exception.NullArgumentException;
+import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.dfp.Dfp;
 import org.junit.Assert;
 import org.junit.Test;
@@ -445,4 +446,43 @@ public final class MatrixUtilsTest {
                 MatrixUtils.createRealIdentityMatrix(testData.length), result, 1e-12);
     }
 
+    @Test
+    public void testCheckMatrixRowIndexError() {
+        try {
+            AnyMatrix m = MatrixUtils.createRealMatrix(new double[][] {{9,9}, {9,9}, {9,9}});
+            MatrixUtils.checkRowIndex(m, 4);
+            Assert.fail("expected an OutOfRangeException");
+        } catch (OutOfRangeException e) {
+            String s = e.getMessage();
+            int topIx = s.indexOf('2');
+            int botIx = s.indexOf('0');
+            int rowIx = s.indexOf('4');
+            if (topIx < 0 || botIx < 0 || rowIx < 0) {
+                Assert.fail("expected a message like index 4 is not in 0..3, not: " + s);
+            }
+        } catch (Exception e) {
+            Assert.fail("expected an OutOfRange exception, not: " +
+                        e.getClass().getName() + ": " + e.getMessage());
+        }
+    }
+
+    @Test
+    public void testCheckMatrixColIndexError() {
+        try {
+            AnyMatrix m = MatrixUtils.createRealMatrix(new double[][] {{9,9}, {9,9}, {9,9}});
+            MatrixUtils.checkColumnIndex(m, 4);
+            Assert.fail("expected an OutOfRangeException");
+        } catch (OutOfRangeException e) {
+            String s = e.getMessage();
+            int topIx = s.indexOf('1');
+            int botIx = s.indexOf('0');
+            int rowIx = s.indexOf('4');
+            if (topIx < 0 || botIx < 0 || rowIx < 0) {
+                Assert.fail("expected a message like index 4 is not in 0..3, not: " + s);
+            }
+        } catch (Exception e) {
+            Assert.fail("expected an OutOfRange exception, not: " +
+                        e.getClass().getName() + ": " + e.getMessage());
+        }
+    }
 }