Class Vector1Test

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

public class Vector1Test extends Object
Unit tests for Vector1 (both Vector1 and Vector1) with concrete quantity Length and unit Length.Unit. The tests encode the correct behavior and are intended to fail when the implementation contains defects (e.g., wrong L1 norm, incorrect Hadamard unit composition).

Coverage goals:

  • Constructors, factories, and SI conversion semantics
  • Accessors: x(), y(), xSi(), ySi(), getSiArray(), get(index)
  • Iterator and getScalarArray()
  • VectorMatrixOps defaults as exercised/overridden by Vector1
  • Normed: norm(), normL1(), normL2(), normLp(p), normLinf()
  • Orientation & shape: rows(), cols(), isColumnVector()
  • Transposition Row<→>Col
  • Hadamard operations (invertElements, multiplyElements, divideElements)
  • Linear algebra products: Row⋅Col, Col⋅Row, Row⋅Matrix2x2
  • as(targetUnit) positive and negative branches
  • equals, hashCode, toString

Important: Values passed to the Vector1 constructors are interpreted in the provided display unit and converted to SI for internal storage. The tests validate that convention. 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

    • Vector1Test

      public Vector1Test()
  • Method Details

    • testConstructorAndSiStorage

      @Test @DisplayName("Constructor conversion: display unit \u2192 SI storage") public void testConstructorAndSiStorage()
      Verify that constructor interprets values in the provided display unit and converts to SI storage.
    • testInstantiateSiArray

      @Test @DisplayName("instantiateSi(double[]) enforces length=1 and delegates") public void testInstantiateSiArray()
      Verify Vector1.instantiateSi(double[]) delegates to the (xSi) variant and enforces length=1.
    • testAccessorsAndIndexing

      @Test @DisplayName("size, x/y (Q), xSi, getSiArray() copy, and get(index)") public void testAccessorsAndIndexing()
      Verify size, x() quantities, xSi(), getSiArray() copy semantics, and get(index) branches.
    • testIterator

      @Test @DisplayName("iterator() yields Q in display unit, in order x") public void testIterator()
      Verify the iterator over Q values yields x in the vector's display unit and is consistent with get().
    • testGetScalarArray

      @Test @DisplayName("getScalarArray() returns Q[] with x") public void testGetScalarArray()
      Verify Vector.getScalarArray() returns a Q[] (not Object[]) with the correct order and values.
    • testShapeAndTranspose

      @Test @DisplayName("rows/cols/isColumnVector and transpose()") public void testShapeAndTranspose()
      Verify rows(), cols(), and isColumnVector() for both Row and Col; verify transpose preserves SI values and unit.
    • testBasicAlgebraRow

      @Test @DisplayName("VectorMatrixOps: add/subtract (Q & V), negate, abs, scaleBy") public void testBasicAlgebraRow()
      Verify add(Q), subtract(Q), add(V), subtract(V), negate(), abs(), scaleBy(double) for Vector1.
    • testStatistics

      @Test @DisplayName("Statistics: min/max/mean/median/sum") public void testStatistics()
      Verify statistics: min, max, mean, median, sum.
    • testNorms

      @Test @DisplayName("Normed: norm(), normL1(), normL2(), normLp(p), normLinf()") public void testNorms()
      Verify norm() equals normL2() and norms compute correct quantities.

      Note: This test assumes correct L1 definition: |x| + |y|. If the implementation divides by 2, this test will fail (as intended).

    • testHadamardCol

      @Test @DisplayName("Hadamard: invertElements / multiplyElements / divideElements + unit composition, Col") public void testHadamardCol()
      Verify Hadamard element-wise operations and correct unit composition. If the implementation derives the unit from x().siUnit() instead of the vector's display unit, the test will fail (by design) for Column vector.
    • testAs

      @Test @DisplayName("as(targetUnit) success for m\u2194km and failure for mismatched SI unit") public void testAs()
      Verify as(targetUnit) succeeds for a unit with identical SI dimension and fails for mismatched dimension.
    • testEqualsHashCode

      @Test @DisplayName("equals/hashCode and type sensitivity") public void testEqualsHashCode()
      Verify equals/hashCode and type-sensitive equality (Row vs Col), and that display unit changes do not affect equals.
    • testToString

      @Test @DisplayName("toString() and toString(unit)") public void testToString()
      Verify toString() and toString(unit) contain orientation tag and unit abbreviation.
    • testFluentAndRelative

      @Test @DisplayName("setDisplayUnit() fluent and isRelative()") public void testFluentAndRelative()
      Verify setDisplayUnit returns this (fluent) and that isRelative aligns with Length semantics.
    • testMultiplyScalarAs

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

      @Test public void testOfDoubleUnitHappy()
      Vector1.of(double, unit) happy path.
    • testOfDoubleUnitNull

      @Test public void testOfDoubleUnitNull()
      Vector1.of(double, null) must throw.
    • testOfQuantityHappy

      @Test public void testOfQuantityHappy()
      Vector1.of(Q) happy path.
    • testOfQuantityNull

      @Test public void testOfQuantityNull()
      Vector1.of(Q) with null quantity.
    • testOfArrayUnitHappy

      @Test public void testOfArrayUnitHappy()
      Vector1.of(double[], unit) happy path.
    • testOfArrayUnitNullArray

      @Test public void testOfArrayUnitNullArray()
      Vector1.of(double[], unit) with null array.
    • testOfArrayUnitWrongLength

      @Test public void testOfArrayUnitWrongLength()
      Vector1.of(double[], unit) with wrong length.
    • testOfSiScalarHappy

      @Test public void testOfSiScalarHappy()
      Vector1.ofSi(double, unit) happy path.
    • testOfSiScalarNullUnit

      @Test public void testOfSiScalarNullUnit()
      Vector1.ofSi(double, null) must throw.
    • testOfSiArrayHappy

      @Test public void testOfSiArrayHappy()
      Vector1.ofSi(double[], unit) happy path.
    • testOfSiArrayNullArray

      @Test public void testOfSiArrayNullArray()
      Vector1.ofSi(double[], unit) with null array.
    • testOfSiArrayWrongLength

      @Test public void testOfSiArrayWrongLength()
      Vector1.ofSi(double[], unit) with wrong length.
    • testOfQuantityArrayHappy

      @Test public void testOfQuantityArrayHappy()
      Vector1.of(Q[]) happy path.
    • testOfQuantityArrayNull

      @Test public void testOfQuantityArrayNull()
      Vector1.of(Q[]) with null array.
    • testOfQuantityArrayWrongLength

      @Test public void testOfQuantityArrayWrongLength()
      Vector1.of(Q[]) with wrong length.
    • testAsFunctions

      @Test @DisplayName("Vector1 as() functions test") public void testAsFunctions()
      Test as() functions.