Package org.djunits.util
Class MatrixMathTest
java.lang.Object
org.djunits.util.MatrixMathTest
Unit tests for
MatrixMath. The suite aims for 100% line and branch coverage by exercising:
- Multiplication (rectangular), including length-mismatch error paths
- Trace, symmetry and skew-symmetry with default and explicit tolerances
- Determinant: closed-form (n=1,2,3) and LU-based (n≥4)
- Inverse: closed-form (n=1,2,3) and LU-based (n≥4), including singular matrix exceptions
- Adjugate: closed-form (n=1,2,3) and general (n≥4), validated via A·adj(A)=det(A)·I
- Coverage of the private constructor
Notes:
- All matrices are provided in row-major layout, matching
MatrixMathcontracts. - Floating-point comparisons use a tight tolerance; identities from inversion are validated numerically.
- Author:
- Alexander Verbraeck (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidVerifies adjugate for n=1,2,3 and n≥4 via the identity A·adj(A) = det(A)·I.(package private) voidVerifies determinant for n=1,2,3 (closed-form) and n≥4 (LU path).(package private) voidVerifies inverse for n=1,2,3 and n≥4, including singular matrix exceptions.(package private) voidVerifies rectangular matrix multiplication and length-mismatch precondition errors.(package private) voidCovers the private constructor ofMatrixMathvia reflection for complete coverage.(package private) voidVerifies symmetry checks with default and explicit tolerances.voidTest theadjugate(double[], int)method for correctness and full branch coverage.(package private) voidVerifiesMatrixMath.trace(double[], int)on simple matrices.
-
Constructor Details
-
MatrixMathTest
public MatrixMathTest()
-
-
Method Details
-
privateConstructorCoverage
Covers the private constructor ofMatrixMathvia reflection for complete coverage.- Throws:
Exception- if reflective construction fails
-
multiplyRectangularAndErrors
@Test void multiplyRectangularAndErrors()Verifies rectangular matrix multiplication and length-mismatch precondition errors. -
traceOfMatrix
@Test void traceOfMatrix()VerifiesMatrixMath.trace(double[], int)on simple matrices. -
symmetryChecks
@Test void symmetryChecks()Verifies symmetry checks with default and explicit tolerances. -
determinantVariants
@Test void determinantVariants()Verifies determinant for n=1,2,3 (closed-form) and n≥4 (LU path). -
inverseVariants
Verifies inverse for n=1,2,3 and n≥4, including singular matrix exceptions.- Throws:
Exception- if inversion unexpectedly fails
-
adjugateVariants
@Test void adjugateVariants()Verifies adjugate for n=1,2,3 and n≥4 via the identity A·adj(A) = det(A)·I. -
testAdjugateAllBranches
@Test public void testAdjugateAllBranches()Test theadjugate(double[], int)method for correctness and full branch coverage. Covers fast paths for n=1, n=2, n=3 as well as the general case for larger n, ensuring that minors of size m=1, m=2, m=3 and m>3 are exercised. For m>3, LU-based determinant computation is invoked indirectly to complete coverage.Correctness is evaluated by using the mathematical identity:
adj(A) = det(A) * inverse(A). For small matrices (1x1, 2x2, 3x3), expected adjugates are computed analytically. For larger matrices (4x4, 5x5), correctness is verified by checking that A * adj(A) equals det(A) times the identity matrix.
-