Package org.djunits.vecmat.d3
Class Matrix3x3Test
java.lang.Object
org.djunits.vecmat.d3.Matrix3x3Test
Unit tests for
Matrix3x3 with concrete quantity Length and unit Length.Unit.
The tests aim for 100% method and branch coverage of Matrix3x3 and inherited/default behavior from:
VectorMatrixSquareDenseMatrixSquareMatrixHadamard- and value-related interfaces used by VectorMatrixOps (Additive, Scalable, Value)
Assertions reflect the intended functional specification. If any method is incorrectly implemented, tests will fail—by design.
Conventions used
- Quantities:
Length - Units:
Length.Unit.m(SI base),Length.Unit.km(scale 1000), andLength.Unit.cm - Numerical comparisons on SI arrays use a small epsilon
- Author:
- Alexander Verbraeck (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerifyadd(VM)andsubtract(VM)element-wise for matrices.voidVerifyadd(Q)andsubtract(Q)with quantities.voidtestAs()VerifyMatrix3x3.as(UnitInterface)succeeds when SI units match (e.g., m ↔ km), and throws when SI units mismatch (e.g., length ↔ time).voidVerifyVectorMatrix.rows(),VectorMatrix.cols(),VectorMatrix.get(int, int)and relative/absolute flag.voidVerify determinant as scalar and as quantity, and trace; also test the identity A · adj(A) = det(A) · I.voidvoidVerifyMatrix3x3.of(double[], UnitInterface)rejects nulls and wrong sizes, and converts using the display unit.voidVerifyMatrix3x3.of(double[][], UnitInterface)validation and SI conversion.voidVerify Hadamard element-wise operations: invert, multiply, divide.voidEnsure index-related methods do not throw for valid bounds and that value retrieval uses display unit.voidVerifyMatrix3x3.instantiateSi(double[])creates a new matrix with the same display unit and the provided SI.voidVerifyMatrix3x3.inverse()and multiplication with its inverse gives the identity (numerically).voidVerify thatMatrix3x3.inverse()throws on singular matrices.voidVerify standard 3x3 matrix multiplication (A·B).voidVerify multiplication with a column vector (A·v).voidTest multiply/divide by scalar and as() method.voidVerifynegate(),abs(), andscaleBy(double).voidVerify Frobenius norm.voidVerify scalar array extraction helpers onVectorMatrix.voidVerify thatVectorMatrix.setDisplayUnit(UnitInterface)only affects presentation and not SI storage.voidVerify double array extraction helpers onVectorMatrix.voidVerifymean,median,min,max,mode, andsum.voidVerify symmetry and skew-symmetry checks with and without tolerances.voidvoidVerify transpose on a 3x3 matrix.voidVerify vector extraction helpers (getRow,getColumn,getDiagonal) behave per spec: this test expects non-null vectors of appropriate type and unit.
-
Constructor Details
-
Matrix3x3Test
public Matrix3x3Test()
-
-
Method Details
-
testFactoryOfArray
@Test @DisplayName("Factory of(double[]) \u2014 nulls, length check, SI conversion") public void testFactoryOfArray()VerifyMatrix3x3.of(double[], UnitInterface)rejects nulls and wrong sizes, and converts using the display unit. -
testFactoryOfGrid
@Test @DisplayName("Factory of(double[][]) \u2014 nulls, 3x3 shape, SI conversion") public void testFactoryOfGrid()VerifyMatrix3x3.of(double[][], UnitInterface)validation and SI conversion. -
testInstantiate
@Test @DisplayName("instantiateSi(double[]) \u2014 uses provided SI and keeps display unit") public void testInstantiate()VerifyMatrix3x3.instantiateSi(double[])creates a new matrix with the same display unit and the provided SI. -
testBasicShapeAndValue
@Test @DisplayName("rows/cols/value/isRelative") public void testBasicShapeAndValue()VerifyVectorMatrix.rows(),VectorMatrix.cols(),VectorMatrix.get(int, int)and relative/absolute flag. -
testSetDisplayUnit
@Test @DisplayName("setDisplayUnit() only changes presentation") public void testSetDisplayUnit()Verify thatVectorMatrix.setDisplayUnit(UnitInterface)only affects presentation and not SI storage. -
testToString
@Test @DisplayName("toString() and toString(unit) contain unit abbreviation") public void testToString() -
testAddSubtractQuantity
@Test @DisplayName("add(Q) / subtract(Q) apply element-wise SI increments") public void testAddSubtractQuantity()Verifyadd(Q)andsubtract(Q)with quantities. -
testAddSubtractMatrix
@Test @DisplayName("add(VM) / subtract(VM) element-wise") public void testAddSubtractMatrix()Verifyadd(VM)andsubtract(VM)element-wise for matrices. -
testNegateAbsScaleBy
@Test @DisplayName("negate / abs / scaleBy") public void testNegateAbsScaleBy()Verifynegate(),abs(), andscaleBy(double). -
testStats
@Test @DisplayName("mean / median / min / max / mode / sum") public void testStats()Verifymean,median,min,max,mode, andsum. -
testTranspose
@Test @DisplayName("transpose() transposes correctly") public void testTranspose()Verify transpose on a 3x3 matrix. -
testDeterminantTraceAdjugateIdentity
@Test @DisplayName("determinantScalar(), determinant(), trace(), and A\u00b7adj(A)=det(A)\u00b7I") public void testDeterminantTraceAdjugateIdentity()Verify determinant as scalar and as quantity, and trace; also test the identity A · adj(A) = det(A) · I. -
testNormFrobenius
@Test @DisplayName("normFrobenius") public void testNormFrobenius()Verify Frobenius norm. -
testSymmetry
@Test @DisplayName("isSymmetric / isSkewSymmetric with and without tolerance") public void testSymmetry()Verify symmetry and skew-symmetry checks with and without tolerances. -
testInverseAndIdentity
@Test @DisplayName("inverse() and A \u00b7 A^{-1} \u2248 I") public void testInverseAndIdentity() throws NonInvertibleMatrixExceptionVerifyMatrix3x3.inverse()and multiplication with its inverse gives the identity (numerically).- Throws:
NonInvertibleMatrixException- if inversion fails (test expects success)
-
testInverseThrowsOnSingular
@Test @DisplayName("inverse() throws on singular matrix") public void testInverseThrowsOnSingular()Verify thatMatrix3x3.inverse()throws on singular matrices. -
testMatrixMultiply
@Test @DisplayName("matrix x matrix multiplication") public void testMatrixMultiply()Verify standard 3x3 matrix multiplication (A·B). -
testMatrixTimesVector
@Test @DisplayName("matrix x vector (column)") public void testMatrixTimesVector()Verify multiplication with a column vector (A·v). -
testHadamard
@Test @DisplayName("Hadamard: invertElements / multiplyElements / divideElements") public void testHadamard()Verify Hadamard element-wise operations: invert, multiply, divide. -
testAs
@Test @DisplayName("as(targetUnit) success (m\u2194km) and failure (length\u2194time)") public void testAs()VerifyMatrix3x3.as(UnitInterface)succeeds when SI units match (e.g., m ↔ km), and throws when SI units mismatch (e.g., length ↔ time). -
testScalarExtraction
@Test @DisplayName("getScalars / getRowScalars / getColumnScalars / getDiagonalScalars") public void testScalarExtraction()Verify scalar array extraction helpers onVectorMatrix. -
testSiArrayExtraction
@Test @DisplayName("getRowSi / getColumnSi / getDiagonalSi") public void testSiArrayExtraction()Verify double array extraction helpers onVectorMatrix. -
testVectorExtractionSpec
@Test @DisplayName("getRow / getColumn / getDiagonal return expected vectors (spec)") public void testVectorExtractionSpec()Verify vector extraction helpers (getRow,getColumn,getDiagonal) behave per spec: this test expects non-null vectors of appropriate type and unit. -
testEqualsHashCode
@Test @DisplayName("equals / hashCode") public void testEqualsHashCode() -
testIndexingAndValues
@Test @DisplayName("Indexing within bounds and value retrieval") public void testIndexingAndValues()Ensure index-related methods do not throw for valid bounds and that value retrieval uses display unit. -
testMultiplyScalarAs
@Test public void testMultiplyScalarAs()Test multiply/divide by scalar and as() method.
-