Class Matrix3x3Test

java.lang.Object
org.djunits.vecmat.d3.Matrix3x3Test

public class Matrix3x3Test extends Object
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:

Assertions reflect the intended functional specification. If any method is incorrectly implemented, tests will fail—by design.

Conventions used

Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
Author:
Alexander Verbraeck (specifications); Test implementation by Copilot.
  • Constructor Details

    • Matrix3x3Test

      public Matrix3x3Test()
  • Method Details

    • testFactoryOfArray

      @Test @DisplayName("Factory of(double[]) \u2014 nulls, length check, SI conversion") public void testFactoryOfArray()
      Verify Matrix3x3.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()
      Verify Matrix3x3.of(double[][], UnitInterface) validation and SI conversion.
    • testInstantiate

      @Test @DisplayName("instantiateSi(double[]) \u2014 uses provided SI and keeps display unit") public void testInstantiate()
      Verify Matrix3x3.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()
    • testSetDisplayUnit

      @Test @DisplayName("setDisplayUnit() only changes presentation") public void testSetDisplayUnit()
      Verify that VectorMatrix.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()
      Verify add(Q) and subtract(Q) with quantities.
    • testAddSubtractMatrix

      @Test @DisplayName("add(VM) / subtract(VM) element-wise") public void testAddSubtractMatrix()
      Verify add(VM) and subtract(VM) element-wise for matrices.
    • testNegateAbsScaleBy

      @Test @DisplayName("negate / abs / scaleBy") public void testNegateAbsScaleBy()
      Verify negate(), abs(), and scaleBy(double).
    • testStats

      @Test @DisplayName("mean / median / min / max / mode / sum") public void testStats()
      Verify mean, median, min, max, mode, and sum.
    • 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 NonInvertibleMatrixException
      Verify Matrix3x3.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 that Matrix3x3.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()
      Verify Matrix3x3.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 on VectorMatrix.
    • testSiArrayExtraction

      @Test @DisplayName("getRowSi / getColumnSi / getDiagonalSi") public void testSiArrayExtraction()
      Verify double array extraction helpers on VectorMatrix.
    • 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()
      Verify equality and hashCode semantics across VectorMatrix, SquareDenseMatrix, and Matrix3x3.
    • 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.