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(), si(), 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, si() copy, and get(index)") public void testAccessorsAndIndexing()
      Verify size, x() quantities, xSi(), si() 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/mode/sum") public void testStatistics()
      Verify statistics: min, max, mean, median, mode, 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.
    • testScalarExtraction

      @Test @DisplayName("getScalars / getRowScalars / getColumnScalars") public void testScalarExtraction()
      Verify scalar array extraction helpers on VectorMatrix.
    • testVectorExtractionSpec

      @Test @DisplayName("getRowVector / getColumnVector return the expected vectors (spec)") public void testVectorExtractionSpec()
      Verify vector extraction helpers (getRowVector, getColumnVector) behave per spec.

      This test expects non-null vectors with the correct content.

    • testSiArrayExtraction

      @Test @DisplayName("getRowSi / getColumnSi") public void testSiArrayExtraction()
      Verify si array extraction helpers on VectorMatrix.
    • 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.