Class VectorNTest

java.lang.Object
org.djunits.vecmat.dn.VectorNTest

public final class VectorNTest extends Object
Comprehensive unit tests for VectorN, validating both VectorN.Row and VectorN.Col implementations with concrete quantity Length and display units from Length.Unit.

The tests encode the intended functional specification. They will fail when the implementation deviates (e.g., incorrect addressing in get(index) or wrong unit composition in Hadamard operations).

Coverage scope:

  • Construction via a DataGridSi-backed SI store
  • Accessors: size(), rows(), cols(), isColumnVector(), getSiArray(), get(index)
  • Iteration and getScalarArray() correctness (types, order, unit)
  • Fluent display-unit switching (setDisplayUnit) and stringification (toString())
  • Vector algebra: add/subtract(Q), add/subtract(V), negate(), abs(), scaleBy(double)
  • Norms: norm(), normL1(), normL2(), normLp(int), normLinf()
  • Hadamard operations: invertEntries(), multiplyEntries(V), divideEntries(V) with unit composition
  • Statistics: min(), max(), mean(), median(), sum()
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

    • VectorNTest

      public VectorNTest()
  • Method Details

    • testConstructorAndShapeCol

      @Test @DisplayName("Constructor SI storage & shape (Col)") public void testConstructorAndShapeCol()
      Verify that a VectorN.Col constructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation).
    • testConstructorAndShapeRow

      @Test @DisplayName("Constructor SI storage & shape (Row)") public void testConstructorAndShapeRow()
      Verify that a VectorN.Row constructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation).
    • testInstantiateSiArrayCol

      @Test @DisplayName("instantiateSi(double[]) enforces length=3 and delegates (Col)") public void testInstantiateSiArrayCol()
      Verify instantiateSi(double[]) enforces length=3 and delegates (Col).
    • testInstantiateSiArrayRow

      @Test @DisplayName("instantiateSi(double[]) enforces length=3 and delegates (Row)") public void testInstantiateSiArrayRow()
      Verify instantiateSi(double[]) enforces length=3 and delegates (Row).
    • testOfCol

      @Test public void testOfCol()
      Test the of() methods for Col.
    • testOfRow

      @Test public void testOfRow()
      Test the of() methods for Row.
    • testNnz

      @Test @DisplayName("test nnz()") public void testNnz()
    • testIndexing

      @Test @DisplayName("get(index), addressing semantics (Row & Col)") public void testIndexing()
      Verify Vector.get(int) and Vector.get(int) with valid and invalid indices; this test ensures the index addressing follows the intended semantics: a row vector reads from (0, index-1), a column vector from (index-1, 0).
    • testIterator

      @Test @DisplayName("iterator() yields Q in display unit, in natural order") public void testIterator()
      Verify that the Iterable interface is implemented correctly: the iterator produces Q values in natural order and throws NoSuchElementException at the end.
    • testGetScalarArray

      @Test @DisplayName("getScalarArray() returns Q[] with correct order and types") public void testGetScalarArray()
      Verify that VectorN.getScalarArray() returns a Q[] of correct length and component types, with entries in the expected x..n order.
    • testFluentAndToString

      @Test @DisplayName("setDisplayUnit() is fluent; toString contains orientation & unit") public void testFluentAndToString()
      Verify that VectorMatrix.setDisplayUnit(org.djunits.unit.Unit) returns this for fluent usage and that VectorMatrix.toString() and Value.format(org.djunits.unit.Unit) contain correct orientation and unit abbreviation.
    • testAlgebraRow

      @Test @DisplayName("Vector algebra (Row)") public void testAlgebraRow()
      Verify vector algebra operations for VectorN.Row: element-wise add/subtract(V), add/subtract(Q), negate(), abs(), and scaleBy(double).
    • testAlgebraCol

      @Test @DisplayName("Vector algebra (Col)") public void testAlgebraCol()
      Verify vector algebra operations for VectorN.Col: element-wise add/subtract(V), add/subtract(Q), negate(), abs(), and scaleBy(double).
    • testNorms

      @Test @DisplayName("Normed: norm(), normL1(), normL2(), normLp(p), normLinf()") public void testNorms()
      Verify norm(), normL1(), normL2(), normLp(int), and normLinf() for both Row and Col vectors; norm() is expected to equal normL2() per the Normed default.
    • testHadamardRow

      @Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Row)") public void testHadamardRow()
      Verify element-wise Hadamard operations on a VectorN.Row: invertEntries(), multiplyEntries(V), divideEntries(V) and validate result-unit composition via SIUnit.add(SIUnit, SIUnit) and SIUnit.subtract(SIUnit, SIUnit).
    • testHadamardCol

      @Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Col)") public void testHadamardCol()
      Verify element-wise Hadamard operations on a VectorN.Col: invertEntries(), multiplyEntries(V), divideEntries(V) and validate result-unit composition.
    • testStatisticsRow

      @Test @DisplayName("Statistics: min/max/mean/median/sum (Row)") public void testStatisticsRow()
      Verify min, max, mean, median, and sum on an unsorted odd-length VectorN.Row input (to avoid even-median ambiguity).
    • testStatisticsCol

      @Test @DisplayName("Statistics: min/max/mean/median/sum (Col)") public void testStatisticsCol()
      Verify min, max, mean, median, and sum on a VectorN.Col with inputs in kilometers; assertions are made against SI values in meters.
    • testVectorNasVectorConversionsRowAndCol

      @Test @DisplayName("VectorN.{Row,Col}: asVector1 / asVector2* / asVector3* preserve SI & unit; illegal shapes throw") public void testVectorNasVectorConversionsRowAndCol()
      Verify that VectorN.Col and VectorN.Row convert to Vector1/Vector2/Vector3 variants with preserved SI data and display unit; and that illegal shapes throw IllegalStateException.

      Uses kilometers for column vectors and centimeters for row vectors to ensure SI conversion is correct.

    • testEqualsHashCode

      @Test @DisplayName("Equals and hashCode") public void testEqualsHashCode()
      Verify equals() and hashCode() methods.
    • testTranspose

      @Test @DisplayName("Transpose") public void testTranspose()
      Verify transpose() method.
    • testMultiplyScalarAs

      @Test public void testMultiplyScalarAs()
      Test multiply/divide by scalar and as() method.
    • testColOfArrayUnitHappy

      @Test public void testColOfArrayUnitHappy()
      Col.of(double[], unit) happy path.
    • testRowOfArrayUnitHappy

      @Test public void testRowOfArrayUnitHappy()
      Row.of(double[], unit) happy path.
    • testColOfArrayUnitEmpty

      @Test public void testColOfArrayUnitEmpty()
      Col.of(double[], unit) with empty array.
    • testRowOfArrayUnitEmpty

      @Test public void testRowOfArrayUnitEmpty()
      Row.of(double[], unit) with empty array.
    • testColOfArrayUnitNullArray

      @Test public void testColOfArrayUnitNullArray()
      Col.of(double[], unit) with null array.
    • testRowOfArrayUnitNullArray

      @Test public void testRowOfArrayUnitNullArray()
      Row.of(double[], unit) with null array.
    • testColOfSiArrayHappy

      @Test public void testColOfSiArrayHappy()
      Col.ofSi(double[], unit) happy path.
    • testRowOfSiArrayHappy

      @Test public void testRowOfSiArrayHappy()
      Row.ofSi(double[], unit) happy path.
    • testColOfSiArrayNullUnit

      @Test public void testColOfSiArrayNullUnit()
      Col.ofSi(double[], unit) with null unit.
    • testRowOfSiArrayNullArray

      @Test public void testRowOfSiArrayNullArray()
      Row.ofSi(double[], unit) with null array.
    • testColOfQuantityArrayHappy

      @Test public void testColOfQuantityArrayHappy()
      Col.of(Q[]) happy path.
    • testRowOfQuantityArrayHappy

      @Test public void testRowOfQuantityArrayHappy()
      Row.of(Q[]) happy path.
    • testColOfQuantityArrayEmpty

      @Test public void testColOfQuantityArrayEmpty()
      Col.of(Q[]) with empty array.
    • testRowOfQuantityArrayEmpty

      @Test public void testRowOfQuantityArrayEmpty()
      Row.of(Q[]) with empty array.
    • testColOfQuantityArrayNull

      @Test public void testColOfQuantityArrayNull()
      Col.of(Q[]) with null array.
    • testRowOfQuantityArrayNull

      @Test public void testRowOfQuantityArrayNull()
      Row.of(Q[]) with null array.
    • testColOfQuantityListHappy

      @Test public void testColOfQuantityListHappy()
      Col.of(List) happy path.
    • testRowOfQuantityListHappy

      @Test public void testRowOfQuantityListHappy()
      Row.of(List) happy path.
    • testColOfQuantityListEmpty

      @Test public void testColOfQuantityListEmpty()
      Col.of(List) with empty list.
    • testRowOfQuantityListEmpty

      @Test public void testRowOfQuantityListEmpty()
      Row.of(List) with empty list.
    • testColOfQuantityListWithNullElement

      @Test public void testColOfQuantityListWithNullElement()
      Col.of(List) with null element.
    • testRowOfQuantityListWithNullElement

      @Test public void testRowOfQuantityListWithNullElement()
      Row.of(List) with null element.
    • testColOfSiDataGridHappy

      @Test public void testColOfSiDataGridHappy()
      Col.ofSi(DataGridSi, unit) happy path.
    • testRowOfSiDataGridHappy

      @Test public void testRowOfSiDataGridHappy()
      Row.ofSi(DataGridSi, unit) happy path.
    • testColOfSiDataGridWrongShape

      @Test public void testColOfSiDataGridWrongShape()
      Col.ofSi(DataGridSi, unit) with wrong shape.
    • testRowOfSiDataGridWrongShape

      @Test public void testRowOfSiDataGridWrongShape()
      Row.ofSi(DataGridSi, unit) with wrong shape.
    • testVectorNColAsFunctions

      @Test @DisplayName("VectorN.Col as() functions test") public void testVectorNColAsFunctions()
      Test as() functions for Col vector.
    • testVectorNRowAsFunctions

      @Test @DisplayName("VectorN.Row as() functions test") public void testVectorNRowAsFunctions()
      Test as() functions for Row vector.