Unit testing is an essential part of modern software development that helps ensure correctness. EJML itself makes extensive use of unit tests as well as system level tests. EJML provides several functions are specifically designed for creating unit tests.
EjmlUnitTests and MatrixFeatures are two classes which contain useful functions for unit testing. EjmlUnitTests provides a similar interface to how JUnitTest operates. MatrixFeatures is primarily intended for extracting high level information about a matrix, but also contains several functions for testing if two matrices are equal or have specific characteristics.
The following is a brief introduction to unit testing with EJML. See the JavaDoc for a more detailed list of functions available in EjmlUnitTests and MatrixFeatures.
In this example it checks to see if each element of the two matrices are within 1e-8 of each other. The reference EjmlUnitTests to can be avoided by invoking a "static import". If an error is found and the test fails the exact element it failed at is printed.
To maintain compatibility with different unit test libraries a generic runtime exception is thrown if a test fails.
Here the JUnitTest function assertTrue() has been used. MatrixFeatures_DDRM.isEquals() returns true of the two matrices are within tolerance of each other. If the test fails it doesn't print any additional information, such as which element it failed at.
One advantage of MatrixFeatures_DDRM is it provides support for many more specialized tests. For example if you want to know if a matrix is orthogonal call MatrixFeatures_DDRM.isOrthogonal() or to test for symmetry call MatrixFeatures_DDRM.isSymmetric().
This page was last modified on 18 May 2017, at 10:30.