Package org.djunits.vecmat.table
Class QuantityTableTest
java.lang.Object
org.djunits.vecmat.table.QuantityTableTest
Unit tests for
QuantityTable. This test covers all behavior specifically introduced in QuantityTable.
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 TypeMethodDescriptionvoidtestAs()Test as(): converting the table to a different display unit but identical SI unit.voidVerify thatasMatrixNxN()preserves SI data and display unit for square matrices (tested with 1x1 and 4x4), and throwsIllegalStateExceptionfor non-square shapes (tested with 2x3 and 3x2).voidVerify that all asXXX() methods correctly preserve SI values and correctly assign display units.voidVerify thatasVectorNCol(): Preserves SI data and display unit forN x 1matrices (tested with N=4 and N=1), ThrowsIllegalStateExceptionwhen the matrix has more than one column (e.g.,N x 2). SI correctness is validated via both the row-majorsi()array and element access on the returned vector.voidVerify thatasVectorNRow(): Preserves SI data and display unit for1 x Nmatrices (tested with N=4 and N=1), ThrowsIllegalStateExceptionwhen the matrix has more than one row (e.g.,2 x N). SI correctness is validated via both the row-majorsi()array and element access on the returned vector.voidTest basic constructor behavior: correct dimensions and display unit.voidTest divideElements(): Hadamard division of two tables.voidVerify equals/hashCode.voidVerify of(double[], rows, cols, U) rejects nulls/bad sizes and converts display→SI.voidVerify of(double[][],U) checks rectangular shape and converts display→SI.voidVerify of(Q[][],U) accepts per-cell units via DenseDoubleData and sets display unit.voidTest instantiateSi(double[]): produces new instance with SI data replaced.voidTest invertElements(): works elementwise, produces SIQuantity output.voidTest multiplyElements(): Hadamard product of two tables.voidTest multiply/divide by scalar and as() method.voidVerify QuantityTable conversions to fixed-size matrices preserve SI data and display unit, and that shape checks throw IllegalStateException for the mismatch branches covered.voidVerify QuantityTable conversions to quantity table preserve SI data and display unit, and that shape checks throw IllegalStateException for the mismatch branches covered.voidVerify QuantityTable conversions to fixed-size vectors and matrices preserve SI data and display unit, and that shape checks throw IllegalStateException with both row- and column-mismatch branches covered.voidVerify scalar extraction helpers.voidVerify double extraction helpers.voidVerify vector extraction helpers.
-
Constructor Details
-
QuantityTableTest
public QuantityTableTest()
-
-
Method Details
-
testConstructor
@Test @DisplayName("ctor: stores datagrid and display unit correctly") public void testConstructor()Test basic constructor behavior: correct dimensions and display unit. -
testFactoryArray
@Test @DisplayName("of(double[],rows,cols,U): nulls/bad sizes/SI convert") public void testFactoryArray()Verify of(double[], rows, cols, U) rejects nulls/bad sizes and converts display→SI. -
testFactoryGrid
@Test @DisplayName("of(double[][],U): rectangular shape & SI convert") public void testFactoryGrid()Verify of(double[][],U) checks rectangular shape and converts display→SI. -
testFactoryQuantityGrid
@Test @DisplayName("of(Q[][],U): quantity grid accepted") public void testFactoryQuantityGrid()Verify of(Q[][],U) accepts per-cell units via DenseDoubleData and sets display unit. -
testInstantiateSi
@Test @DisplayName("instantiateSi(): replaces SI data correctly and preserves display unit") public void testInstantiateSi()Test instantiateSi(double[]): produces new instance with SI data replaced. -
testInvertElements
@Test @DisplayName("invertElements(): reciprocal of each SI value") public void testInvertElements()Test invertElements(): works elementwise, produces SIQuantity output. -
testMultiplyElements
@Test @DisplayName("multiplyElements(): Hadamard multiplication") public void testMultiplyElements()Test multiplyElements(): Hadamard product of two tables. -
testDivideElements
@Test @DisplayName("divideElements(): Hadamard division") public void testDivideElements()Test divideElements(): Hadamard division of two tables. -
testEqualsHash
@Test @DisplayName("equals / hashCode") public void testEqualsHash()Verify equals/hashCode. -
testAs
@Test @DisplayName("as(): convert display unit when SI units match") public void testAs()Test as(): converting the table to a different display unit but identical SI unit. -
testQuantityTableAsVectorConversions
@Test @DisplayName("QuantityTable: asVector preserve SI and unit; row/col mismatch branches throw") public void testQuantityTableAsVectorConversions()Verify QuantityTable conversions to fixed-size vectors and matrices preserve SI data and display unit, and that shape checks throw IllegalStateException with both row- and column-mismatch branches covered.Uses kilometers for column-shaped tests and centimeters for row-shaped tests to exercise SI conversion.
-
testQuantityTableAsMatrixConversions
@Test @DisplayName("QuantityTable: asMatrix preserve SI and unit") public void testQuantityTableAsMatrixConversions()Verify QuantityTable conversions to fixed-size matrices preserve SI data and display unit, and that shape checks throw IllegalStateException for the mismatch branches covered. -
testQuantityTableAsMatrixNxM
@Test @DisplayName("QuantityTable: asMatrixNxM preserve SI and unit") public void testQuantityTableAsMatrixNxM()Verify QuantityTable conversions to quantity table preserve SI data and display unit, and that shape checks throw IllegalStateException for the mismatch branches covered. -
testAsMatrixNxN
@Test @DisplayName("QuantityTable: asMatrixNxN preserves SI & unit (square) and throws for non-square shapes") public void testAsMatrixNxN()Verify thatasMatrixNxN()preserves SI data and display unit for square matrices (tested with 1x1 and 4x4), and throwsIllegalStateExceptionfor non-square shapes (tested with 2x3 and 3x2). SI correctness is checked via both the row-majorsi()array andsi(row, col)with 0-based indices. -
testAsVectorNCol
@Test @DisplayName("QuantityTable: asVectorNCol preserves SI & unit (Nx1) and throws for Nx2") public void testAsVectorNCol()Verify thatasVectorNCol():- Preserves SI data and display unit for
N x 1matrices (tested with N=4 and N=1), - Throws
IllegalStateExceptionwhen the matrix has more than one column (e.g.,N x 2).
si()array and element access on the returned vector. - Preserves SI data and display unit for
-
testAsVectorNRow
@Test @DisplayName("QuantityTable: asVectorNRow preserves SI & unit (1xN) and throws for 2xN") public void testAsVectorNRow()Verify thatasVectorNRow():- Preserves SI data and display unit for
1 x Nmatrices (tested with N=4 and N=1), - Throws
IllegalStateExceptionwhen the matrix has more than one row (e.g.,2 x N).
si()array and element access on the returned vector. - Preserves SI data and display unit for
-
testAsMethodsUnitConversion
@Test @DisplayName("asXXX(): SI consistency and correct display-unit conversion") public void testAsMethodsUnitConversion()Verify that all asXXX() methods correctly preserve SI values and correctly assign display units. This test detects subtle SI/display-unit conversion mistakes such as interpreting SI values as display-unit values or performing double conversion. -
testScalarExtraction
@Test @DisplayName("getScalars / getRowScalars / getColumnScalars") public void testScalarExtraction()Verify scalar extraction helpers. -
testVectorExtraction
@Test @DisplayName("getRowVector / getColumnVector") public void testVectorExtraction()Verify vector extraction helpers. -
testSiArrayExtraction
@Test @DisplayName("getRowSi / getColumnSi") public void testSiArrayExtraction()Verify double extraction helpers. -
testMultiplyScalarAs
@Test public void testMultiplyScalarAs()Test multiply/divide by scalar and as() method.
-