Package org.djunits.vecmat.dn
Class MatrixNxNTest
java.lang.Object
org.djunits.vecmat.dn.MatrixNxNTest
Unit tests for
MatrixNxN (using n=4) with concrete quantity Length and unit
Length.Unit.
The tests encode intended behavior (display → SI conversion, unit algebra via SIUnit.plus(SIUnit) /
SIUnit.add(SIUnit, SIUnit), etc.). They fail if the implementation deviates—by design.
Coverage:
- Factories (
of(double[],U),of(double[][],U)) instantiateSi(double[])- Matrix basics:
rows(),cols(),value(r,c),setDisplayUnit,toString - Ops defaults:
add/sub (Q & VM),negate,abs,scaleBy, stats - SquareMatrixOps:
transpose,determinantScalar,determinant,trace,normFrobenius,isSymmetric(± tol),isSkewSymmetric(± tol) - Inverse/adjugate (success + singular), matrixxmatrix, matrixxvector
- Hadamard:
invertElements,multiplyElements,divideElements(+ unit composition) as(targetUnit)success/failure- Scalar extraction helpers:
getScalars,getRowScalars,getColumnScalars,getDiagonalScalars equals/hashCode
- Author:
- Alexander Verbraeck (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerify vector/matrix algebra defaults and statistics.voidtestAs()VerifyMatrixNxN.as(UnitInterface)success (m↔km) and failure (dimension mismatch).voidVerify thatasMatrix1x1()preserves SI and display unit for a 1x1 matrix, and throwsIllegalStateExceptionfor other N (N=2 and N=3).voidVerify thatasMatrix2x2()preserves SI and display unit for a 2x2 matrix, and throwsIllegalStateExceptionfor other N (tested with N=1 and N=3).voidVerify thatasMatrix3x3()preserves SI and display unit for a 3x3 matrix, and throwsIllegalStateExceptionfor other N (tested with N=2 and N=4).voidVerify constructor.voidVerifyequals/hashCodefor equal and different data.voidVerifyMatrixNxN.of(double[], UnitInterface)rejects nulls, wrong lengths, and converts to SI.voidVerifyMatrixNxN.of(double[][], UnitInterface)checks 4x4 shape and converts to SI.voidVerify element-wise Hadamard operations and unit composition.voidVerifyMatrixNxN.instantiateSi(double[])preserves display unit and adopts SI values.voidVerifyMatrixNxN.inverse()throws on singular andMatrixNxN.adjugate()shape.voidVerify matrixxmatrix and matrixxvector multiplication with unit composition.voidTest multiply/divide by scalar and as() method.voidVerify scalar extraction helpers:getScalars,getRowScalars,getColumnScalars, andgetDiagonalScalars.voidVerify thatVectorMatrix.setDisplayUnit(UnitInterface)only affects presentation (not SI storage).voidvoidVerify SI extraction helpers:getRowSi,getColumnSi, andgetDiagonalSi.voidVerify transpose, determinant/trace/normFrobenius, symmetry checks.voidVerifyVectorMatrix.toString()andVectorMatrix.toString(UnitInterface)include unit abbreviation.voidVerify scalar extraction helpers:getRowVector,getColumnVector, andgetDiagonalVector.
-
Constructor Details
-
MatrixNxNTest
public MatrixNxNTest()
-
-
Method Details
-
testFactoryArray
@Test @DisplayName("of(double[],U): nulls, length, SI conversion") public void testFactoryArray()VerifyMatrixNxN.of(double[], UnitInterface)rejects nulls, wrong lengths, and converts to SI. -
testFactoryGrid
@Test @DisplayName("of(double[][],U): shape & SI conversion") public void testFactoryGrid()VerifyMatrixNxN.of(double[][], UnitInterface)checks 4x4 shape and converts to SI. -
testInstantiateSi
@Test @DisplayName("instantiateSi(double[]): display unit preserved, SI adopted") public void testInstantiateSi()VerifyMatrixNxN.instantiateSi(double[])preserves display unit and adopts SI values. -
testConstructor
@Test @DisplayName("MatrixNxN constructor") public void testConstructor()Verify constructor. -
testShapeAndValue
@Test @DisplayName("rows/cols/value/isRelative") public void testShapeAndValue() -
testSetDisplayUnit
@Test @DisplayName("setDisplayUnit() only changes presentation") public void testSetDisplayUnit()Verify thatVectorMatrix.setDisplayUnit(UnitInterface)only affects presentation (not SI storage). -
testToString
@Test @DisplayName("toString()/toString(unit) include unit") public void testToString()VerifyVectorMatrix.toString()andVectorMatrix.toString(UnitInterface)include unit abbreviation. -
testAlgebraAndStats
@Test @DisplayName("add/sub (Q & VM), negate/abs/scaleBy, stats") public void testAlgebraAndStats()Verify vector/matrix algebra defaults and statistics. -
testSquareOps
@Test @DisplayName("transpose, determinant/trace/Frobenius, symmetry") public void testSquareOps()Verify transpose, determinant/trace/normFrobenius, symmetry checks. -
testInverseAdjugate
@Test @DisplayName("inverse(): singular throws; adjugate() exists") public void testInverseAdjugate()VerifyMatrixNxN.inverse()throws on singular andMatrixNxN.adjugate()shape. -
testMultiply
@Test @DisplayName("matrix x matrix and matrix x vector") public void testMultiply()Verify matrixxmatrix and matrixxvector multiplication with unit composition. -
testHadamard
@Test @DisplayName("Hadamard: invert/multiply/divide + unit composition") public void testHadamard()Verify element-wise Hadamard operations and unit composition. -
testAs
@Test @DisplayName("as(targetUnit) success/failure") public void testAs()VerifyMatrixNxN.as(UnitInterface)success (m↔km) and failure (dimension mismatch). -
testScalarExtraction
@Test @DisplayName("getScalars / getRowScalars / getColumnScalars / getDiagonalScalars") public void testScalarExtraction()Verify scalar extraction helpers:getScalars,getRowScalars,getColumnScalars, andgetDiagonalScalars. -
testSiArrayExtraction
@Test @DisplayName("getRowSi / getColumnSi / getDiagonalSi") public void testSiArrayExtraction()Verify SI extraction helpers:getRowSi,getColumnSi, andgetDiagonalSi. -
testVectorExtraction
@Test @DisplayName("getRowVector / getColumnVector / getDiagonalVector") public void testVectorExtraction()Verify scalar extraction helpers:getRowVector,getColumnVector, andgetDiagonalVector. -
testEqualsHash
@Test @DisplayName("equals / hashCode") public void testEqualsHash()Verifyequals/hashCodefor equal and different data. -
testMultiplyScalarAs
@Test public void testMultiplyScalarAs()Test multiply/divide by scalar and as() method. -
testAsMatrix1x1
@Test @DisplayName("MatrixNxN: asMatrix1x1 preserves SI & unit for 1x1; throws for N\u22601") public void testAsMatrix1x1()Verify thatasMatrix1x1()preserves SI and display unit for a 1x1 matrix, and throwsIllegalStateExceptionfor other N (N=2 and N=3).Note: The current implementation appears to have a bug: it checks
cols() != 2instead ofcols() != 1, which will make this test fail until fixed. -
testAsMatrix2x2
@Test @DisplayName("MatrixNxN: asMatrix2x2 preserves SI & unit for 2x2; throws for N\u22602") public void testAsMatrix2x2()Verify thatasMatrix2x2()preserves SI and display unit for a 2x2 matrix, and throwsIllegalStateExceptionfor other N (tested with N=1 and N=3). -
testAsMatrix3x3
@Test @DisplayName("MatrixNxN: asMatrix3x3 preserves SI & unit for 3x3; throws for N\u22603") public void testAsMatrix3x3()Verify thatasMatrix3x3()preserves SI and display unit for a 3x3 matrix, and throwsIllegalStateExceptionfor other N (tested with N=2 and N=4).
-