Package org.djunits.vecmat.d3
Class Vector3Test
java.lang.Object
org.djunits.vecmat.d3.Vector3Test
Unit tests for
Vector3 (both Vector3.Col and Vector3.Row) 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 factories, wrong rows/cols, etc.).
Coverage goals:
- Constructors, factories, and display→SI conversion
- Accessors: x(), y(), z(), xSi(), ySi(), zSi(), si(), get(index)
- Iterator and getScalarArray()
- Vector algebra: add/sub (Q & V), negate, abs, scaleBy
- Normed: norm(), normL1(), normL2(), normLp(p), normLinf()
- Orientation & shape: rows(), cols(), isColumnVector()
- Transposition Row<↔>Col
- Hadamard operations (invertElements, multiplyElements, divideElements) + unit composition
- Linear algebra: Row⋅Col, Col⋅Row, Row⋅Matrix3x3
- as(targetUnit) positive and negative branches
- equals, hashCode, toString, setDisplayUnit, isRelative
- Author:
- Alexander Verbraeck (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerify size, x/y/z quantities, xSi/ySi/zSi, si(), get(index) (Col).voidVerify size, x/y/z quantities, xSi/ySi/zSi, si() copy semantics, and get(index) branches (Row).voidtestAs()Verify as(targetUnit) succeeds for m↔km and fails for mismatched SI unit (Row & Col).voidVerify add(Q), subtract(Q), add(V), subtract(V), negate(), abs(), scaleBy() (Col).voidVerify add(Q), subtract(Q), add(V), subtract(V), negate(), abs(), scaleBy() (Row).voidVerify scalar array extraction helpers on aVector3.Col(3x1) and their 1-based variants.voidVerify SI-array extraction helpers on aVector3.Coland direct SI element access usingsi(row, col)andmsi(row, col)including bounds.voidVerify vector extraction helpers on aVector3.Col(3x1) for both 0-based and 1-based variants.voidCol·Row → Matrix3x3 with plus-unit composition.voidVerify that constructor interprets values in display unit and stores SI internally (Col).voidVerify that constructor interprets values in display unit and stores SI internally (Row).voidVerify getScalarArray returns a Q[3] with values in order x,y,z (Row and Col).voidVerify Hadamard operations and result-unit composition (Col).voidVerify Hadamard operations and result-unit composition (Row).voidVerify instantiateSi(double[]) enforces length=3 and delegates (Col).voidVerify instantiateSi(double[]) enforces length=3 and delegates (Row).voidVerify iterator order and unit for Row and Col.voidTest multiply/divide by scalar and as() method.voidVerify norm(), normL1(), normL2(), normLp(p), normLinf() (Row & Col).voidVerify equals/hashCode and type sensitivity; toString contains orientation and unit; setDisplayUnit is fluent.voidVerify scalar array extraction helpers on aVector3.Row(1x3) and their 1-based variants.voidVerify SI-array extraction helpers on aVector3.Rowand direct SI element access usingsi(row, col)andmsi(row, col)including bounds.voidVerify vector extraction helpers on aVector3.Row(1x3) for both 0-based and 1-based variants.voidRow·Col → scalar; unit composition with SIUnit.plus.voidRow·Matrix3x3 → Col with plus-unit composition.voidVerify rows(), cols(), isColumnVector(), and transpose for both Row and Col.voidVerify statistics for a Col vector: min, max, mean, median, mode, and sum.voidVerify statistics for a Row vector: min, max, mean, median, mode, and sum.
-
Constructor Details
-
Vector3Test
public Vector3Test()
-
-
Method Details
-
testConstructorAndSiStorageCol
@Test @DisplayName("Constructor conversion: display unit \u2192 SI storage (Col)") public void testConstructorAndSiStorageCol()Verify that constructor interprets values in display unit and stores SI internally (Col). -
testConstructorAndSiStorageRow
@Test @DisplayName("Constructor conversion: display unit \u2192 SI storage (Row)") public void testConstructorAndSiStorageRow()Verify that constructor interprets values in display unit and stores SI internally (Row). -
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). -
testAccessorsAndIndexingRow
@Test @DisplayName("size, x/y/z (Q), xSi/ySi/zSi, si() copy, and get(index) (Row)") public void testAccessorsAndIndexingRow()Verify size, x/y/z quantities, xSi/ySi/zSi, si() copy semantics, and get(index) branches (Row). -
testAccessorsAndIndexingCol
@Test @DisplayName("size, x/y/z (Q), xSi/ySi/zSi, si() copy, and get(index) (Col)") public void testAccessorsAndIndexingCol()Verify size, x/y/z quantities, xSi/ySi/zSi, si(), get(index) (Col). -
testIterator
@Test @DisplayName("iterator() yields Q in display unit, in order x,y,z") public void testIterator()Verify iterator order and unit for Row and Col. -
testGetScalarArray
@Test @DisplayName("getScalarArray() returns Q[3] with x,y,z in order") public void testGetScalarArray()Verify getScalarArray returns a Q[3] with values in order x,y,z (Row and Col). -
testShapeAndTranspose
@Test @DisplayName("rows/cols/isColumnVector and transpose()") public void testShapeAndTranspose()Verify rows(), cols(), isColumnVector(), and transpose for both Row and Col. -
testBasicAlgebraRow
@Test @DisplayName("Vector algebra: add/sub (Q & V), negate, abs, scaleBy (Row)") public void testBasicAlgebraRow()Verify add(Q), subtract(Q), add(V), subtract(V), negate(), abs(), scaleBy() (Row). -
testBasicAlgebraCol
@Test @DisplayName("Vector algebra: add/sub (Q & V), negate, abs, scaleBy (Col)") public void testBasicAlgebraCol()Verify add(Q), subtract(Q), add(V), subtract(V), negate(), abs(), scaleBy() (Col). -
testStatisticsRow
@Test @DisplayName("Statistics: min/max/mean/median/mode/sum (Row)") public void testStatisticsRow()Verify statistics for a Row vector: min, max, mean, median, mode, and sum.Uses unsorted input to ensure
median()is order-independent. All assertions are checked against SI values, since the vector stores SI internally andQ.si()returns the SI magnitude. -
testStatisticsCol
@Test @DisplayName("Statistics: min/max/mean/median/mode/sum (Col)") public void testStatisticsCol()Verify statistics for a Col vector: min, max, mean, median, mode, and sum.Values are provided in kilometers to exercise unit conversion, but assertions are made on SI values (meters). Input is deliberately unsorted to verify
median(). -
testNorms
@Test @DisplayName("Normed: norm(), normL1(), normL2(), normLp(p), normLinf()") public void testNorms()Verify norm(), normL1(), normL2(), normLp(p), normLinf() (Row & Col). -
testHadamardCol
@Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Col)") public void testHadamardCol()Verify Hadamard operations and result-unit composition (Col). -
testHadamardRow
@Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Row)") public void testHadamardRow()Verify Hadamard operations and result-unit composition (Row). -
testRowDotCol
@Test @DisplayName("Row \u00b7 Col \u2192 SIQuantity with unit composition") public void testRowDotCol()Row·Col → scalar; unit composition with SIUnit.plus. -
testColTimesRow
@Test @DisplayName("Col \u00b7 Row \u2192 Matrix3x3 with unit composition") public void testColTimesRow()Col·Row → Matrix3x3 with plus-unit composition. -
testRowTimesMatrix
@Test @DisplayName("Row \u00b7 Matrix3x3 \u2192 Col with unit composition") public void testRowTimesMatrix()Row·Matrix3x3 → Col with plus-unit composition. -
testAs
@Test @DisplayName("as(targetUnit) success for m\u2194km and failure for mismatched SI unit") public void testAs()Verify as(targetUnit) succeeds for m↔km and fails for mismatched SI unit (Row & Col). -
testCol3ScalarExtraction
@Test @DisplayName("Vector3.Col: getScalars helpers (Row/Column) incl. 1-based, lengths, values, and bounds") public void testCol3ScalarExtraction()Verify scalar array extraction helpers on aVector3.Col(3x1) and their 1-based variants.Uses kilometers as display unit to verify correct SI conversion.
-
testCol3VectorExtractionSpec
@Test @DisplayName("Vector3.Col: getRowVector / getColumnVector incl. 1-based and bounds") public void testCol3VectorExtractionSpec()Verify vector extraction helpers on aVector3.Col(3x1) for both 0-based and 1-based variants.Row vectors returned are
Vector1(1 element). The full column is returned asVector3.Col. -
testCol3SiArrayExtractionAndSiAt
@Test @DisplayName("Vector3.Col: getRowSi / getColumnSi incl. 1-based + si(r,c)/msi(r,c)") public void testCol3SiArrayExtractionAndSiAt()Verify SI-array extraction helpers on aVector3.Coland direct SI element access usingsi(row, col)andmsi(row, col)including bounds. -
testRow3ScalarExtraction
@Test @DisplayName("Vector3.Row: getScalars helpers (Row/Column) incl. 1-based, lengths, values, and bounds") public void testRow3ScalarExtraction()Verify scalar array extraction helpers on aVector3.Row(1x3) and their 1-based variants.Uses centimeters as display unit to verify correct SI conversion.
-
testRow3VectorExtractionSpec
@Test @DisplayName("Vector3.Row: getRowVector / getColumnVector incl. 1-based and bounds") public void testRow3VectorExtractionSpec()Verify vector extraction helpers on aVector3.Row(1x3) for both 0-based and 1-based variants.Full row returns
Vector3.Row; each column returnsVector1. -
testRow3SiArrayExtractionAndSiAt
@Test @DisplayName("Vector3.Row: getRowSi / getColumnSi incl. 1-based + si(r,c)/msi(r,c)") public void testRow3SiArrayExtractionAndSiAt()Verify SI-array extraction helpers on aVector3.Rowand direct SI element access usingsi(row, col)andmsi(row, col)including bounds. -
testObjectContracts
@Test @DisplayName("equals/hashCode, toString, setDisplayUnit, isRelative") public void testObjectContracts()Verify equals/hashCode and type sensitivity; toString contains orientation and unit; setDisplayUnit is fluent. -
testMultiplyScalarAs
@Test public void testMultiplyScalarAs()Test multiply/divide by scalar and as() method.
-