Package org.djunits.vecmat.d1
Class Matrix1x1Test
java.lang.Object
org.djunits.vecmat.d1.Matrix1x1Test
Unit tests for
Matrix1x1 with concrete quantity Length and unit Length.Unit.
The tests aim for 100% method and branch coverage in Matrix1x1 and the inherited default functionality from:
VectorMatrixSquareDenseMatrixSquareMatrixHadamard- and the value interfaces used by
MatrixOps(Additive, Scalable, Value)
The assertions are written to reflect the intended functional specification. If any method in the class hierarchy is incorrectly implemented (including TODOs not implemented), tests will fail, as desired.
Conventions used in these tests
- Quantities:
Length - Units under test:
Length.Unit.m(SI base),Length.Unit.km(scale 1000), and occasionallyLength.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 TypeMethodDescriptionvoidVerifyVectorMatrix.add(Quantity)andsubtract(VM)with another matrix.voidVerifyVectorMatrix.add(Quantity)andsubtract(Q)with quantities.voidVerifyMatrix1x1.adjugate()for a generic 1x1 matrix.voidtestAs()VerifyMatrix1x1.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.voidvoidVerifyMatrix1x1.of(double[], UnitInterface)rejects nulls and wrong sizes, and converts using the display unit.voidVerifyMatrix1x1.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.voidVerifyMatrix1x1.instantiateSi(double[])creates a new matrix with the same display unit and the provided SI values.voidVerifyMatrix1x1.inverse()and multiplication with its inverse gives the identity (numerically).voidVerify thatMatrix1x1.inverse()throws on singular matrices.voidVerify standard 1x1 matrix multiplication.voidVerify multiplication with a column vector.voidTest multiply/divide by scalar and as() method.voidvoidVerify Frobenius norm and defaultnorm().voidVerify scalar array extraction helpers onVectorMatrix.voidVerify thatVectorMatrix.setDisplayUnit(UnitInterface)only affects presentation and not SI storage.voidVerify si array extraction helpers onVectorMatrix.voidVerifymean,median,min,max,mode, andsum.voidVerify symmetry and skew-symmetry checks with and without tolerances.voidCallVectorMatrix.toString()andVectorMatrix.toString(UnitInterface)for coverage.voidVerify transpose on a 1x1 matrix.voidVerify vector extraction helpers (getRow,getColumn,getDiagonal) behave per spec.
-
Constructor Details
-
Matrix1x1Test
public Matrix1x1Test()
-
-
Method Details
-
testFactoryOfArray
@Test @DisplayName("Factory of(double[]) \u2014 nulls, length check, and SI conversion") public void testFactoryOfArray()VerifyMatrix1x1.of(double[], UnitInterface)rejects nulls and wrong sizes, and converts using the display unit. -
testFactoryOfGrid
@Test @DisplayName("Factory of(double[][]) \u2014 nulls, 1x1 shape, and SI conversion") public void testFactoryOfGrid()VerifyMatrix1x1.of(double[][], UnitInterface)validation and SI conversion. -
testInstantiate
@Test @DisplayName("instantiate(double[]) \u2014 uses provided SI data and keeps display unit") public void testInstantiate()VerifyMatrix1x1.instantiateSi(double[])creates a new matrix with the same display unit and the provided SI values. -
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()CallVectorMatrix.toString()andVectorMatrix.toString(UnitInterface)for coverage. We assert the unit abbreviation is present; we do not depend on exact formatting of numbers. -
testAddSubtractQuantity
@Test @DisplayName("add(Q) / subtract(Q) apply element-wise SI increments") public void testAddSubtractQuantity()VerifyVectorMatrix.add(Quantity)andsubtract(Q)with quantities. -
testAddSubtractMatrix
@Test @DisplayName("add(VM) / subtract(VM) element-wise") public void testAddSubtractMatrix()VerifyVectorMatrix.add(Quantity)andsubtract(VM)with another matrix. -
testNegateAbsScaleBy
@Test @DisplayName("negate / abs / scaleBy") public void testNegateAbsScaleBy() -
testStats
@Test @DisplayName("mean / median / min / max / mode / sum") public void testStats()Verifymean,median,min,max,mode, andsum. -
testTranspose
@Test @DisplayName("transpose() swaps off-diagonals") public void testTranspose()Verify transpose on a 1x1 matrix. -
testDeterminantAndTrace
@Test @DisplayName("determinantScalar(), determinant(), trace()") public void testDeterminantAndTrace()Verify determinant as scalar and as quantity, and trace. -
testNorms
@Test @DisplayName("normFrobenius and default norm()") public void testNorms()Verify Frobenius norm and defaultnorm(). -
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 * A^{-1} \u2248 I") public void testInverseAndIdentity() throws NonInvertibleMatrixExceptionVerifyMatrix1x1.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 thatMatrix1x1.inverse()throws on singular matrices. -
testAdjugate
@Test @DisplayName("adjugate()") public void testAdjugate()VerifyMatrix1x1.adjugate()for a generic 1x1 matrix. -
testMatrixMultiply
@Test @DisplayName("matrix x matrix multiplication") public void testMatrixMultiply()Verify standard 1x1 matrix multiplication. -
testMatrixTimesVector
@Test @DisplayName("matrix x vector (column)") public void testMatrixTimesVector()Verify multiplication with a column vector. Assumes aVector2.Colwith constructor (double v1, double v2, SIUnit unit) is available. -
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()VerifyMatrix1x1.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. -
testVectorExtractionSpec
@Test @DisplayName("getRowVector / getColumnVector / getDiagonalVector return the expected vectors (spec)") public void testVectorExtractionSpec()Verify vector extraction helpers (getRow,getColumn,getDiagonal) behave per spec.This test expects non-null vectors with the correct content.
-
testSiArrayExtraction
@Test @DisplayName("getRowSi / getColumnSi / getDiagonalSi") public void testSiArrayExtraction()Verify si array extraction helpers onVectorMatrix. -
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.
-