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(), getSiArray(), 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 (invertEntries, multiplyEntries, divideEntries) + 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, getSiArray(), get(index) (Col).voidVerify size, x/y/z quantities, xSi/ySi/zSi, getSiArray() 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).voidCol.of(double[],unit) happy path.voidCol.of(double[],unit) null array.voidCol.of(double[],unit) wrong length.voidCol.of(double,double,double,unit) happy path.voidCol.of(double,double,double,null) must throw.voidCol.of(Q,Q,Q) happy path.voidCol.of(Q,Q,Q) with null x.voidCol.of(Q,Q,Q) with null z.voidCol.of(Q[]) happy path.voidCol.of(Q[]) null array.voidCol.of(Q[]) wrong length.voidCol.ofSi(double[],null unit).voidCol.ofSi(double[],unit) happy path.voidCol.ofSi(double[],unit) wrong length.voidCol.ofSi(double,double,double,unit) happy path.voidCol.ofSi(double,double,double,null) must throw.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.voidRow·Col → scalar; unit composition with SIUnit.plus.voidRow.of(double[],unit) happy path.voidRow.of(double[],unit) null array.voidRow.of(double[],unit) wrong length.voidRow.of(double,double,double,unit) happy path.voidRow.of(double,double,double,null) must throw.voidRow.of(Q,Q,Q) happy path.voidRow.of(Q,Q,Q) with null y.voidRow.of(Q[]) happy path.voidRow.of(Q[]) null array.voidRow.of(Q[]) wrong length.voidRow.ofSi(double[],null unit).voidRow.ofSi(double[],unit) happy path.voidRow.ofSi(double[],unit) wrong length.voidRow.ofSi(double,double,double,unit) happy path.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, and sum.voidVerify statistics for a Row vector: min, max, mean, median, and sum.voidTest as() functions for Col vector.voidTest as() functions for Row vector.
-
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, getSiArray() copy, and get(index) (Row)") public void testAccessorsAndIndexingRow()Verify size, x/y/z quantities, xSi/ySi/zSi, getSiArray() copy semantics, and get(index) branches (Row). -
testAccessorsAndIndexingCol
@Test @DisplayName("size, x/y/z (Q), xSi/ySi/zSi, getSiArray() copy, and get(index) (Col)") public void testAccessorsAndIndexingCol()Verify size, x/y/z quantities, xSi/ySi/zSi, getSiArray(), 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/sum (Row)") public void testStatisticsRow()Verify statistics for a Row vector: min, max, mean, median, 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/sum (Col)") public void testStatisticsCol()Verify statistics for a Col vector: min, max, mean, median, 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). -
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. -
testColOfDoubleTripleUnitHappy
@Test public void testColOfDoubleTripleUnitHappy()Col.of(double,double,double,unit) happy path. -
testRowOfDoubleTripleUnitHappy
@Test public void testRowOfDoubleTripleUnitHappy()Row.of(double,double,double,unit) happy path. -
testColOfDoubleTripleUnitNull
@Test public void testColOfDoubleTripleUnitNull()Col.of(double,double,double,null) must throw. -
testRowOfDoubleTripleUnitNull
@Test public void testRowOfDoubleTripleUnitNull()Row.of(double,double,double,null) must throw. -
testColOfQQQHappy
@Test public void testColOfQQQHappy()Col.of(Q,Q,Q) happy path. -
testRowOfQQQHappy
@Test public void testRowOfQQQHappy()Row.of(Q,Q,Q) happy path. -
testColOfQQQNullX
@Test public void testColOfQQQNullX()Col.of(Q,Q,Q) with null x. -
testRowOfQQQNullY
@Test public void testRowOfQQQNullY()Row.of(Q,Q,Q) with null y. -
testColOfQQQNullZ
@Test public void testColOfQQQNullZ()Col.of(Q,Q,Q) with null z. -
testColOfArrayUnitHappy
@Test public void testColOfArrayUnitHappy()Col.of(double[],unit) happy path. -
testRowOfArrayUnitHappy
@Test public void testRowOfArrayUnitHappy()Row.of(double[],unit) happy path. -
testColOfArrayUnitNullArray
@Test public void testColOfArrayUnitNullArray()Col.of(double[],unit) null array. -
testRowOfArrayUnitNullArray
@Test public void testRowOfArrayUnitNullArray()Row.of(double[],unit) null array. -
testColOfArrayUnitWrongLength
@Test public void testColOfArrayUnitWrongLength()Col.of(double[],unit) wrong length. -
testRowOfArrayUnitWrongLength
@Test public void testRowOfArrayUnitWrongLength()Row.of(double[],unit) wrong length. -
testColOfSiArrayUnitHappy
@Test public void testColOfSiArrayUnitHappy()Col.ofSi(double[],unit) happy path. -
testRowOfSiArrayUnitHappy
@Test public void testRowOfSiArrayUnitHappy()Row.ofSi(double[],unit) happy path. -
testColOfSiArrayWrongLength
@Test public void testColOfSiArrayWrongLength()Col.ofSi(double[],unit) wrong length. -
testRowOfSiArrayWrongLength
@Test public void testRowOfSiArrayWrongLength()Row.ofSi(double[],unit) wrong length. -
testColOfSiArrayNullUnit
@Test public void testColOfSiArrayNullUnit()Col.ofSi(double[],null unit). -
testRowOfSiArrayNullUnit
@Test public void testRowOfSiArrayNullUnit()Row.ofSi(double[],null unit). -
testColOfSiScalarsHappy
@Test public void testColOfSiScalarsHappy()Col.ofSi(double,double,double,unit) happy path. -
testRowOfSiScalarsHappy
@Test public void testRowOfSiScalarsHappy()Row.ofSi(double,double,double,unit) happy path. -
testColOfSiScalarsNullUnit
@Test public void testColOfSiScalarsNullUnit()Col.ofSi(double,double,double,null) must throw. -
testColOfQuantityArrayHappy
@Test public void testColOfQuantityArrayHappy()Col.of(Q[]) happy path. -
testRowOfQuantityArrayHappy
@Test public void testRowOfQuantityArrayHappy()Row.of(Q[]) happy path. -
testColOfQuantityArrayNull
@Test public void testColOfQuantityArrayNull()Col.of(Q[]) null array. -
testRowOfQuantityArrayNull
@Test public void testRowOfQuantityArrayNull()Row.of(Q[]) null array. -
testColOfQuantityArrayWrongLength
@Test public void testColOfQuantityArrayWrongLength()Col.of(Q[]) wrong length. -
testRowOfQuantityArrayWrongLength
@Test public void testRowOfQuantityArrayWrongLength()Row.of(Q[]) wrong length. -
testVector3ColAsFunctions
@Test @DisplayName("Vector3.Col as() functions test") public void testVector3ColAsFunctions()Test as() functions for Col vector. -
testVector3RowAsFunctions
@Test @DisplayName("Vector3.Row as() functions test") public void testVector3RowAsFunctions()Test as() functions for Row vector.
-