Package org.djunits.vecmat.dn
Class VectorNTest
java.lang.Object
org.djunits.vecmat.dn.VectorNTest
Comprehensive unit tests for
VectorN, validating both VectorN.Row and VectorN.Col implementations
with concrete quantity Length and display units from Length.Unit.
The tests encode the intended functional specification. They will fail when the implementation deviates (e.g.,
incorrect addressing in get(index) or wrong unit composition in Hadamard operations).
Coverage scope:
- Construction via a
DataGridSi-backed SI store - Accessors:
size(),rows(),cols(),isColumnVector(),si(),get(index) - Iteration and
getScalarArray()correctness (types, order, unit) - Fluent display-unit switching (
setDisplayUnit) and stringification (toString()) - Vector algebra:
add/subtract(Q),add/subtract(V),negate(),abs(),scaleBy(double) - Norms:
norm(),normL1(),normL2(),normLp(int),normLinf() - Hadamard operations:
invertElements(),multiplyElements(V),divideElements(V)with unit composition - Statistics:
min(),max(),mean(),median(),mode(),sum()
- Author:
- Alexander Verbraeck (specifications); Test implementation by Copilot.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidVerify vector algebra operations forVectorN.Col: element-wiseadd/subtract(V),add/subtract(Q),negate(),abs(), andscaleBy(double).voidVerify vector algebra operations forVectorN.Row: element-wiseadd/subtract(V),add/subtract(Q),negate(),abs(), andscaleBy(double).voidVerify scalar array extraction helpers on aVectorN.Col(4x1) and their 1-based variants.voidVerify SI-array extraction helpers on aVectorN.Coland direct SI element access usingsi(row, col)andmsi(row, col)including bounds.voidVerify vector extraction helpers on aVectorN.Col(4x1) for both 0-based and 1-based variants.voidVerify that aVectorN.Colconstructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation).voidVerify that aVectorN.Rowconstructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation).voidVerify equals() and hashCode() methods.voidVerify thatVectorMatrix.setDisplayUnit(org.djunits.unit.UnitInterface)returnsthisfor fluent usage and thatVectorN.toString()andVectorN.toString(org.djunits.unit.UnitInterface)contain correct orientation and unit abbreviation.voidVerify thatVectorN.getScalarArray()returns aQ[]of correct length and component types, with entries in the expected x..n order.voidVerify element-wise Hadamard operations on aVectorN.Col:invertElements(),multiplyElements(V),divideElements(V)and validate result-unit composition.voidVerify element-wise Hadamard operations on aVectorN.Row:invertElements(),multiplyElements(V),divideElements(V)and validate result-unit composition viaSIUnit.add(SIUnit, SIUnit)andSIUnit.subtract(SIUnit, SIUnit).voidVerifyVector.get(int)andVector.get(int)with valid and invalid indices; this test ensures the index addressing follows the intended semantics: a row vector reads from(0, index-1), a column vector from(index-1, 0).voidVerify instantiateSi(double[]) enforces length=3 and delegates (Col).voidVerify instantiateSi(double[]) enforces length=3 and delegates (Row).voidVerify that theIterableinterface is implemented correctly: the iterator produces Q values in natural order and throwsNoSuchElementExceptionat the end.voidTest multiply/divide by scalar and as() method.voidVerifynorm(),normL1(),normL2(),normLp(int), andnormLinf()for both Row and Col vectors;norm()is expected to equalnormL2()per theNormeddefault.voidTest the of() methods for Col.voidTest the of() methods for Row.voidVerify scalar array extraction helpers on aVectorN.Row(1x4) and their 1-based variants.voidVerify SI-array extraction helpers on aVectorN.Rowand direct SI element access usingsi(row, col)andmsi(row, col)including bounds.voidVerify vector extraction helpers on aVectorN.Row(1x4) for both 0-based and 1-based variants.voidVerifymin,max,mean,median,mode, andsumon aVectorN.Colwith inputs in kilometers; assertions are made against SI values in meters.voidVerifymin,max,mean,median,mode, andsumon an unsorted odd-lengthVectorN.Rowinput (to avoid even-median ambiguity).voidVerify transpose() method.voidVerify that VectorN.Coland VectorN.Rowconvert to Vector1/Vector2/Vector3 variants with preserved SI data and display unit; and that illegal shapes throwIllegalStateException.
-
Constructor Details
-
VectorNTest
public VectorNTest()
-
-
Method Details
-
testConstructorAndShapeCol
@Test @DisplayName("Constructor SI storage & shape (Col)") public void testConstructorAndShapeCol()Verify that aVectorN.Colconstructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation). -
testConstructorAndShapeRow
@Test @DisplayName("Constructor SI storage & shape (Row)") public void testConstructorAndShapeRow()Verify that aVectorN.Rowconstructed from display values stores SI internally and reports correct shape properties (rows, cols, size, orientation). -
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). -
testOfCol
@Test public void testOfCol()Test the of() methods for Col. -
testOfRow
@Test public void testOfRow()Test the of() methods for Row. -
testIndexing
@Test @DisplayName("get(index), addressing semantics (Row & Col)") public void testIndexing()VerifyVector.get(int)andVector.get(int)with valid and invalid indices; this test ensures the index addressing follows the intended semantics: a row vector reads from(0, index-1), a column vector from(index-1, 0). -
testIterator
@Test @DisplayName("iterator() yields Q in display unit, in natural order") public void testIterator()Verify that theIterableinterface is implemented correctly: the iterator produces Q values in natural order and throwsNoSuchElementExceptionat the end. -
testGetScalarArray
@Test @DisplayName("getScalarArray() returns Q[] with correct order and types") public void testGetScalarArray()Verify thatVectorN.getScalarArray()returns aQ[]of correct length and component types, with entries in the expected x..n order. -
testFluentAndToString
@Test @DisplayName("setDisplayUnit() is fluent; toString contains orientation & unit") public void testFluentAndToString()Verify thatVectorMatrix.setDisplayUnit(org.djunits.unit.UnitInterface)returnsthisfor fluent usage and thatVectorN.toString()andVectorN.toString(org.djunits.unit.UnitInterface)contain correct orientation and unit abbreviation. -
testAlgebraRow
@Test @DisplayName("Vector algebra (Row)") public void testAlgebraRow()Verify vector algebra operations forVectorN.Row: element-wiseadd/subtract(V),add/subtract(Q),negate(),abs(), andscaleBy(double). -
testAlgebraCol
@Test @DisplayName("Vector algebra (Col)") public void testAlgebraCol()Verify vector algebra operations forVectorN.Col: element-wiseadd/subtract(V),add/subtract(Q),negate(),abs(), andscaleBy(double). -
testNorms
@Test @DisplayName("Normed: norm(), normL1(), normL2(), normLp(p), normLinf()") public void testNorms()Verifynorm(),normL1(),normL2(),normLp(int), andnormLinf()for both Row and Col vectors;norm()is expected to equalnormL2()per theNormeddefault. -
testHadamardRow
@Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Row)") public void testHadamardRow()Verify element-wise Hadamard operations on aVectorN.Row:invertElements(),multiplyElements(V),divideElements(V)and validate result-unit composition viaSIUnit.add(SIUnit, SIUnit)andSIUnit.subtract(SIUnit, SIUnit). -
testHadamardCol
@Test @DisplayName("Hadamard: invert/multiply/divide + unit composition (Col)") public void testHadamardCol()Verify element-wise Hadamard operations on aVectorN.Col:invertElements(),multiplyElements(V),divideElements(V)and validate result-unit composition. -
testStatisticsRow
@Test @DisplayName("Statistics: min/max/mean/median/mode/sum (Row)") public void testStatisticsRow()Verifymin,max,mean,median,mode, andsumon an unsorted odd-lengthVectorN.Rowinput (to avoid even-median ambiguity). -
testStatisticsCol
@Test @DisplayName("Statistics: min/max/mean/median/mode/sum (Col)") public void testStatisticsCol()Verifymin,max,mean,median,mode, andsumon aVectorN.Colwith inputs in kilometers; assertions are made against SI values in meters. -
testColNScalarExtraction
@Test @DisplayName("VectorN.Col: getScalars helpers (Row/Column) incl. 1-based, lengths, values, and bounds") public void testColNScalarExtraction()Verify scalar array extraction helpers on aVectorN.Col(4x1) and their 1-based variants.Uses kilometers as display unit to verify correct SI conversion.
-
testColNVectorExtractionSpec
@Test @DisplayName("VectorN.Col: getRowVector / getColumnVector incl. 1-based and bounds") public void testColNVectorExtractionSpec()Verify vector extraction helpers on aVectorN.Col(4x1) for both 0-based and 1-based variants.Row vectors returned are
Vector1(1 element). The full column is returned asVectorN.Col. -
testColNSiArrayExtractionAndSiAt
@Test @DisplayName("VectorN.Col: getRowSi / getColumnSi incl. 1-based + si(r,c)/msi(r,c)") public void testColNSiArrayExtractionAndSiAt()Verify SI-array extraction helpers on aVectorN.Coland direct SI element access usingsi(row, col)andmsi(row, col)including bounds. -
testRowNScalarExtraction
@Test @DisplayName("VectorN.Row: getScalars helpers (Row/Column) incl. 1-based, lengths, values, and bounds") public void testRowNScalarExtraction()Verify scalar array extraction helpers on aVectorN.Row(1x4) and their 1-based variants.Uses centimeters as display unit to verify correct SI conversion.
-
testRowNVectorExtractionSpec
@Test @DisplayName("VectorN.Row: getRowVector / getColumnVector incl. 1-based and bounds") public void testRowNVectorExtractionSpec()Verify vector extraction helpers on aVectorN.Row(1x4) for both 0-based and 1-based variants.Full row returns
VectorN.Row; each column returnsVector1. -
testRowNSiArrayExtractionAndSiAt
@Test @DisplayName("VectorN.Row: getRowSi / getColumnSi incl. 1-based + si(r,c)/msi(r,c)") public void testRowNSiArrayExtractionAndSiAt()Verify SI-array extraction helpers on aVectorN.Rowand direct SI element access usingsi(row, col)andmsi(row, col)including bounds. -
testVectorNasVectorConversionsRowAndCol
@Test @DisplayName("VectorN.{Row,Col}: asVector1 / asVector2* / asVector3* preserve SI & unit; illegal shapes throw") public void testVectorNasVectorConversionsRowAndCol()Verify that VectorN.Coland VectorN.Rowconvert to Vector1/Vector2/Vector3 variants with preserved SI data and display unit; and that illegal shapes throwIllegalStateException.Uses kilometers for column vectors and centimeters for row vectors to ensure SI conversion is correct.
-
testEqualsHashCode
@Test @DisplayName("Equals and hashCode") public void testEqualsHashCode()Verify equals() and hashCode() methods. -
testTranspose
@Test @DisplayName("Transpose") public void testTranspose()Verify transpose() method. -
testMultiplyScalarAs
@Test public void testMultiplyScalarAs()Test multiply/divide by scalar and as() method.
-