Package org.djunits.vecmat.storage
Class DenseDoubleDataSiTest
java.lang.Object
org.djunits.vecmat.storage.DenseDoubleDataSiTest
Unit tests for
DenseDoubleDataSi.
This test class verifies the functional behavior of DenseDoubleDataSi and the default methods in the DataGridSi
interface:
- Constructors: double[], double[][], and Q[][] (SI values)
- Accessors:
rows(),cols(),get(int,int),getDataArray() - Default methods in
DataGridSi:getRowArray(int),getColArray(int)including bounds checks - Copy and instantiation:
copy(),instantiateNew(double[]),instantiateNew(double[],int,int) - Cardinality semantics, including 0.0, -0.0,
NaN, and infinities - Equality and hash code contracts
- All branches and all exception paths
Tests assert functional intent; if the implementation is incorrect, these tests will fail by design.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerifyDenseDoubleDataSi.cardinality()semantics: counts non-zero entries (treats +/-0.0 as zero; counts NaN and infinities as non-zero).voidtestCopy()VerifyDenseDoubleDataSi.copy()creates a deep copy (independent backing array).voidVerify constructor withdouble[][]validates inputs, performs a safe copy, and preserves row-major ordering.voidVerify constructor withdouble[]validates inputs and sets geometry and backing reference as specified (no safe copy).voidVerify constructor withQ[][]validates inputs, performs a safe copy, and writes SI values; unit conversions must be respected (e.g., km to m, cm to m).voidVerify equality and hash code contracts.voidVerify thatDataGridSi.getColArray(int)returns a dense copy with correct values and enforces bounds.voidVerify exposure semantics ofDenseDoubleDataSi.getDataArray()(no safe copy).voidVerify thatget(int,int)throws for all out-of-bounds row/col combinations.voidVerify thatDataGridSi.getRowArray(int)returns a dense copy with correct values and enforces bounds.voidVerifyDenseDoubleDataSi.instantiateNew(double[], int, int)for new shape and argument validation.voidVerifyDenseDoubleDataSi.instantiateNew(double[])returns a new instance with same shape and exposed backing.voidVerify basic gettersrows(),cols(), andget(int,int)on a simple 2x3 matrix.
-
Constructor Details
-
DenseDoubleDataSiTest
public DenseDoubleDataSiTest()
-
-
Method Details
-
testRowsColsAndGet
@Test @DisplayName("rows/cols/get: happy path for 2x3") public void testRowsColsAndGet()Verify basic gettersrows(),cols(), andget(int,int)on a simple 2x3 matrix. -
testGetOutOfBounds
@Test @DisplayName("get: index bounds checking") public void testGetOutOfBounds()Verify thatget(int,int)throws for all out-of-bounds row/col combinations. -
testGetRowArray
@Test @DisplayName("DataGrid.getRowArray: happy path + bounds") public void testGetRowArray()Verify thatDataGridSi.getRowArray(int)returns a dense copy with correct values and enforces bounds. -
testGetColArray
@Test @DisplayName("DataGrid.getColArray: happy path + bounds") public void testGetColArray()Verify thatDataGridSi.getColArray(int)returns a dense copy with correct values and enforces bounds. -
testGetDataArrayExposure
@Test @DisplayName("getDataArray: exposes internal array (by design)") public void testGetDataArrayExposure()Verify exposure semantics ofDenseDoubleDataSi.getDataArray()(no safe copy). Modifications through the returned array are reflected in the object, by design. -
testCopy
@Test @DisplayName("copy: deep copy of data and identical geometry") public void testCopy()VerifyDenseDoubleDataSi.copy()creates a deep copy (independent backing array). -
testInstantiateNewSameDims
@Test @DisplayName("instantiateNew(double[]): shape preserved, backing exposed") public void testInstantiateNewSameDims()VerifyDenseDoubleDataSi.instantiateNew(double[])returns a new instance with same shape and exposed backing. -
testInstantiateNewNewDims
@Test @DisplayName("instantiateNew(double[], r, c): new shape and length checks") public void testInstantiateNewNewDims()VerifyDenseDoubleDataSi.instantiateNew(double[], int, int)for new shape and argument validation. -
testCardinality
@Test @DisplayName("cardinality: zero, -zero, NaN, +/-infinity") public void testCardinality()VerifyDenseDoubleDataSi.cardinality()semantics: counts non-zero entries (treats +/-0.0 as zero; counts NaN and infinities as non-zero). -
testEqualsHashCode
@Test @DisplayName("equals/hashCode: reflexive, symmetric, and data/shape sensitive") public void testEqualsHashCode()Verify equality and hash code contracts. -
testCtorDoubleArrayValidationAndExposure
@Test @DisplayName("ctor(double[], r, c): validation and exposure semantics") public void testCtorDoubleArrayValidationAndExposure()Verify constructor withdouble[]validates inputs and sets geometry and backing reference as specified (no safe copy). -
testCtor2DArrayValidationCopyingAndOrder
@Test @DisplayName("ctor(double[][]): validation, safe copy, row-major, ragged exact-exception") public void testCtor2DArrayValidationCopyingAndOrder()Verify constructor withdouble[][]validates inputs, performs a safe copy, and preserves row-major ordering. Additionally, assert the exact exception type for ragged rows to surface the current format-string bug. -
testCtorQuantity2DArraySIConversion
@Test @DisplayName("ctor(Q[][]): validation, safe copy, SI conversion, ragged exact-exception") public void testCtorQuantity2DArraySIConversion()Verify constructor withQ[][]validates inputs, performs a safe copy, and writes SI values; unit conversions must be respected (e.g., km to m, cm to m). Additionally, assert the exact exception type for ragged rows to surface the current format-string bug.
-