Class Matrix1x1Test

java.lang.Object
org.djunits.vecmat.d1.Matrix1x1Test

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

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

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

    • Matrix1x1Test

      public Matrix1x1Test()
  • Method Details

    • testFactoryOfArray

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

      @Test @DisplayName("instantiate(double[]) \u2014 uses provided SI data and keeps display unit") public void testInstantiate()
      Verify Matrix1x1.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()
    • 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()
      Call VectorMatrix.toString() and VectorMatrix.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()
      Verify VectorMatrix.add(Quantity) and subtract(Q) with quantities.
    • testAddSubtractMatrix

      @Test @DisplayName("add(VM) / subtract(VM) element-wise") public void testAddSubtractMatrix()
      Verify VectorMatrix.add(Quantity) and subtract(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()
      Verify mean, median, min, max, mode, and sum.
    • 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 default 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 * A^{-1} \u2248 I") public void testInverseAndIdentity() throws NonInvertibleMatrixException
      Verify Matrix1x1.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 Matrix1x1.inverse() throws on singular matrices.
    • testAdjugate

      @Test @DisplayName("adjugate()") public void testAdjugate()
      Verify Matrix1x1.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 a Vector2.Col with 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()
      Verify Matrix1x1.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.
    • 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 on VectorMatrix.
    • testEqualsHashCode

      @Test @DisplayName("equals / hashCode") public void testEqualsHashCode()
      Verify equality and hashCode semantics across VectorMatrix, SquareDenseMatrix, and Matrix1x1.
    • 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.