View Javadoc
1   package org.djunits.value.vfloat.matrix;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertFalse;
5   import static org.junit.Assert.assertNotEquals;
6   import static org.junit.Assert.assertTrue;
7   import static org.junit.Assert.fail;
8   
9   import java.lang.reflect.InvocationTargetException;
10  import java.lang.reflect.Method;
11  
12  import org.djunits.unit.AbsoluteTemperatureUnit;
13  import org.djunits.unit.AngleUnit;
14  import org.djunits.unit.AreaUnit;
15  import org.djunits.unit.DirectionUnit;
16  import org.djunits.unit.DurationUnit;
17  import org.djunits.unit.LengthUnit;
18  import org.djunits.unit.PositionUnit;
19  import org.djunits.unit.SIUnit;
20  import org.djunits.unit.TemperatureUnit;
21  import org.djunits.unit.TimeUnit;
22  import org.djunits.unit.Unit;
23  import org.djunits.unit.quantity.Quantities;
24  import org.djunits.unit.quantity.Quantity;
25  import org.djunits.unit.util.UnitException;
26  import org.djunits.unit.util.UnitRuntimeException;
27  import org.djunits.value.CLASSNAMES;
28  import org.djunits.value.ValueRuntimeException;
29  import org.djunits.value.storage.StorageType;
30  import org.djunits.value.vdouble.matrix.AreaMatrix;
31  import org.djunits.value.vdouble.matrix.Determinant;
32  import org.djunits.value.vdouble.matrix.base.DoubleMatrix;
33  import org.djunits.value.vfloat.function.FloatMathFunctions;
34  import org.djunits.value.vfloat.matrix.base.AbstractFloatMatrixRel;
35  import org.djunits.value.vfloat.matrix.base.FloatMatrix;
36  import org.djunits.value.vfloat.matrix.base.FloatSparseValue;
37  import org.djunits.value.vfloat.matrix.data.FloatMatrixData;
38  import org.djunits.value.vfloat.scalar.FloatAbsoluteTemperature;
39  import org.djunits.value.vfloat.scalar.FloatArea;
40  import org.djunits.value.vfloat.scalar.FloatDirection;
41  import org.djunits.value.vfloat.scalar.FloatDuration;
42  import org.djunits.value.vfloat.scalar.FloatLength;
43  import org.djunits.value.vfloat.scalar.FloatPosition;
44  import org.djunits.value.vfloat.scalar.FloatTime;
45  import org.djunits.value.vfloat.vector.FLOATVECTOR;
46  import org.djunits.value.vfloat.vector.FloatAreaVector;
47  import org.djutils.exceptions.Try;
48  import org.junit.Test;
49  
50  /**
51   * ...
52   */
53  public class FloatMatrixMethodTest
54  {
55  
56      /**
57       * Test the standard methods of all matrix classes.
58       * @throws UnitException on error
59       * @throws ValueRuntimeException on error
60       */
61      @Test
62      public void testMatrixMethods() throws ValueRuntimeException, UnitException
63      {
64          float[][] denseTestData = FLOATMATRIX.denseRectArrays(10, 20);
65          float[][] sparseTestData = FLOATMATRIX.sparseRectArrays(10, 20);
66          float[][] reverseSparseTestData = new float[sparseTestData.length][];
67          // sparseTestData and reverseSparseTestData should not "run out of values" at the same index
68          for (int index = 0; index < sparseTestData.length; index++)
69          {
70              reverseSparseTestData[reverseSparseTestData.length - 1 - index] = sparseTestData[index];
71          }
72          // Ensure that there are > 50% positions where both have a non-zero value
73          for (int row = 1; row < 8; row++)
74          {
75              for (int col = 2; col < 18; col++)
76              {
77                  sparseTestData[row][col] = 10000.456f + row + 100 * col;
78                  reverseSparseTestData[row][col] = 20000.567f + row + 100 * col;
79              }
80          }
81  
82          for (StorageType storageType : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
83          {
84              for (AreaUnit au : new AreaUnit[] {AreaUnit.SQUARE_METER, AreaUnit.ACRE})
85              {
86                  float[][] testData = storageType.equals(StorageType.DENSE) ? denseTestData : sparseTestData;
87                  FloatAreaMatrix am =
88                          FloatMatrix.instantiate(FloatMatrixData.instantiate(testData, au.getScale(), storageType), au);
89  
90                  // INDEX CHECKING
91                  for (int row : new int[] {-1, 0, denseTestData.length - 1, denseTestData.length})
92                  {
93                      for (int col : new int[] {-1, 0, denseTestData[0].length - 1, denseTestData[0].length})
94                      {
95                          if (row < 0 || col < 0 || row >= denseTestData.length || col >= denseTestData[0].length)
96                          {
97                              try
98                              {
99                                  am.get(row, col);
100                                 fail("bad row or bad column value should have thrown a ValueRuntimeException");
101                             }
102                             catch (ValueRuntimeException vre)
103                             {
104                                 // Ignore expected exception
105                             }
106                         }
107                         else
108                         {
109                             am.get(row, col);
110                         }
111                     }
112                     if (row < 0 || row >= denseTestData.length)
113                     {
114                         try
115                         {
116                             am.getRow(row);
117                             fail("getRow with bad row value should have thrown a ValueRuntimeException");
118                         }
119                         catch (ValueRuntimeException vre)
120                         {
121                             // Ignore expected exception
122                         }
123                     }
124                 }
125                 for (int col : new int[] {-1, 0, denseTestData[0].length - 1, denseTestData[0].length})
126                 {
127                     if (col < 0 || col >= denseTestData[0].length)
128                     {
129                         try
130                         {
131                             am.getColumn(col);
132                             fail("getColumn with bad column value should have thrown a ValueRuntimeException");
133                         }
134                         catch (ValueRuntimeException vre)
135                         {
136                             // Ignore expected exception
137                         }
138                     }
139                     else
140                     {
141                         am.getColumn(col);
142                     }
143                 }
144 
145                 // SPARSE AND DENSE
146                 assertEquals(am, am.toSparse());
147                 assertEquals(am, am.toDense());
148                 assertEquals(am, am.toSparse().toDense());
149                 assertEquals(am, am.toDense().toSparse());
150                 assertEquals(am.hashCode(), am.toSparse().hashCode());
151                 assertEquals(am.hashCode(), am.toDense().hashCode());
152                 assertTrue(am.toDense().isDense());
153                 assertFalse(am.toDense().isSparse());
154                 assertTrue(am.toSparse().isSparse());
155                 assertFalse(am.toSparse().isDense());
156 
157                 // EQUALS
158                 assertEquals(am, am);
159                 assertNotEquals(am, new Object());
160                 assertNotEquals(am, null);
161                 assertNotEquals(am, FloatMatrix.instantiate(
162                         FloatMatrixData.instantiate(testData, LengthUnit.METER.getScale(), storageType), LengthUnit.METER));
163                 assertNotEquals(am, am.divide(2.0f));
164 
165                 // MUTABLE
166                 assertFalse(am.isMutable());
167                 FloatAreaMatrix ammut = am.mutable();
168                 assertTrue(ammut.isMutable());
169                 assertFalse(am.isMutable());
170                 FloatAreaMatrix ammut2 = ammut.multiplyBy(1.0);
171                 assertEquals(am, ammut2);
172                 assertTrue(ammut.isMutable());
173                 assertFalse(am.isMutable());
174                 assertTrue(ammut2.isMutable());
175                 ammut2 = ammut2.mutable().divideBy(2.0);
176                 assertEquals(am, ammut);
177                 assertNotEquals(am, ammut2);
178                 FloatAreaMatrix ammut3 = ammut2.mutable().divideBy(0.0);
179                 for (int row = 0; row < ammut3.rows(); row++)
180                 {
181                     for (int col = 0; col < ammut3.cols(); col++)
182                     {
183                         if (ammut2.getSI(row, col) == 0)
184                         {
185                             assertTrue("Value should be NaN", Float.isNaN(ammut3.getSI(row, col)));
186 
187                         }
188                         else
189                         {
190                             assertTrue("Value should be Infinite", Float.isInfinite(ammut3.getSI(row, col)));
191                         }
192                     }
193                 }
194 
195                 // ZSUM and CARDINALITY
196                 FloatArea zSum = am.zSum();
197                 float sum = 0;
198                 int card = 0;
199                 for (int row = 0; row < testData.length; row++)
200                 {
201                     for (int col = 0; col < testData[0].length; col++)
202                     {
203                         sum += testData[row][col];
204                         card += testData[row][col] == 0.0f ? 0 : 1;
205                     }
206                 }
207                 assertEquals("zSum", sum, zSum.getInUnit(), 5f);
208                 assertEquals("cardinality", card, am.cardinality());
209                 FloatAreaMatrix ammutZero = ammut.multiplyBy(0.0f);
210                 assertEquals("cardinality should be 0", 0, ammutZero.cardinality());
211                 assertEquals("zSum should be 0", 0.0, ammutZero.zSum().getSI(), 0);
212 
213                 // INCREMENTBY(SCALAR) and DECREMENTBY(SCALAR)
214                 FloatAreaMatrix amold = am.clone();
215                 FloatArea fa = FloatArea.of(10.0f, "m^2");
216                 FloatAreaMatrix aminc = am.mutable().incrementBy(fa).immutable();
217                 FloatAreaMatrix amdec = am.mutable().decrementBy(fa).immutable();
218                 FloatAreaMatrix amid = aminc.mutable().decrementBy(fa);
219                 assertEquals("immutable matrix should not change when converted to mutable", am, amold);
220                 for (int row = 0; row < testData.length; row++)
221                 {
222                     for (int col = 0; col < testData[0].length; col++)
223                     {
224                         assertEquals("increment and decrement with scalar should result in same matrix", am.getSI(row, col),
225                                 amid.getSI(row, col), 5f);
226                         assertEquals("m + s = (m+s)", au.getScale().toStandardUnit(testData[row][col]) + 10.0,
227                                 aminc.getSI(row, col), 6f);
228                         assertEquals("m - s = (m-s)", au.getScale().toStandardUnit(testData[row][col]) - 10.0,
229                                 amdec.getSI(row, col), 6f);
230                     }
231                 }
232 
233                 // MULTIPLYBY() and DIVIDEBY(), TIMES(), DIVIDE()
234                 FloatAreaMatrix amt5 = am.mutable().multiplyBy(5.0f).immutable();
235                 FloatAreaMatrix amd5 = am.mutable().divideBy(5.0f).immutable();
236                 FloatAreaMatrix amtd = amt5.mutable().divideBy(5.0f);
237                 FloatAreaMatrix amtimD = am.times(5.0d);
238                 FloatAreaMatrix amtimF = am.times(5.0f);
239                 FloatAreaMatrix amdivD = am.divide(5.0d);
240                 FloatAreaMatrix amdivF = am.divide(5.0f);
241                 for (int row = 0; row < testData.length; row++)
242                 {
243                     for (int col = 0; col < testData[0].length; col++)
244                     {
245                         assertEquals("times followed by divide with constant should result in same matrix", am.getSI(row, col),
246                                 amtd.getSI(row, col), 0.5);
247                         assertEquals("m * 5.0 = (m*5.0)", au.getScale().toStandardUnit(testData[row][col]) * 5.0f,
248                                 amt5.getSI(row, col), 50f);
249                         assertEquals("m / 5.0 = (m/5.0)", au.getScale().toStandardUnit(testData[row][col]) / 5.0f,
250                                 amd5.getSI(row, col), 2f);
251                         assertEquals("amtimD", amt5.getSI(row, col), amtimD.getSI(row, col), 0.1f);
252                         assertEquals("amtimF", amt5.getSI(row, col), amtimF.getSI(row, col), 0.1f);
253                         assertEquals("amdivD", amd5.getSI(row, col), amdivD.getSI(row, col), 0.01f);
254                         assertEquals("amdivD", amd5.getSI(row, col), amdivF.getSI(row, col), 0.01f);
255                     }
256                 }
257 
258                 // GET(), GETINUNIT()
259                 assertEquals("get()", new FloatArea(testData[2][2], au), am.get(2, 2));
260                 assertEquals("getSI()", au.getScale().toStandardUnit(testData[2][2]), am.getSI(2, 2), 1f);
261                 assertEquals("getInUnit()", testData[2][2], am.getInUnit(2, 2), 0.1);
262                 assertEquals("getInUnit(unit)",
263                         AreaUnit.SQUARE_YARD.getScale().fromStandardUnit(au.getScale().toStandardUnit(testData[2][2])),
264                         am.getInUnit(2, 2, AreaUnit.SQUARE_YARD), 10f);
265 
266                 // SET(), SETINUNIT()
267                 FloatArea fasqft = new FloatArea(10.5f, AreaUnit.SQUARE_FOOT);
268                 FloatAreaMatrix famChange = am.clone().mutable();
269                 famChange.set(2, 2, fasqft);
270                 assertEquals("set()", fasqft.si, famChange.get(2, 2).si, 0.1f);
271                 famChange = am.clone().mutable();
272                 famChange.setSI(2, 2, 123.4f);
273                 assertEquals("setSI()", 123.4f, famChange.get(2, 2).si, 0.1f);
274                 famChange = am.clone().mutable();
275                 famChange.setInUnit(2, 2, 1.2f);
276                 assertEquals("setInUnit()", 1.2f, famChange.getInUnit(2, 2), 0.1f);
277                 famChange = am.clone().mutable();
278                 famChange.setInUnit(2, 2, 1.5f, AreaUnit.HECTARE);
279                 assertEquals("setInUnit(unit)", 15000.0f, famChange.get(2, 2).si, 1.0f);
280 
281                 // GETROW(), GETCOLUMN(), GETDIAGONAL
282                 float[][] squareData = storageType.equals(StorageType.DENSE) ? FLOATMATRIX.denseRectArrays(12, 12)
283                         : FLOATMATRIX.sparseRectArrays(12, 12);
284                 FloatAreaMatrix amSquare =
285                         FloatMatrix.instantiate(FloatMatrixData.instantiate(squareData, au.getScale(), storageType), au);
286                 float[] row2si = am.getRowSI(2);
287                 float[] col2si = am.getColumnSI(2);
288                 float[] diagsi = amSquare.getDiagonalSI();
289                 FloatAreaVector row2v = am.getRow(2);
290                 FloatAreaVector col2v = am.getColumn(2);
291                 FloatAreaVector diagv = amSquare.getDiagonal();
292                 FloatArea[] row2scalar = am.getRowScalars(2);
293                 FloatArea[] col2scalar = am.getColumnScalars(2);
294                 FloatArea[] diagscalar = amSquare.getDiagonalScalars();
295                 for (int col = 0; col < testData[0].length; col++)
296                 {
297                     assertEquals("row2si", au.getScale().toStandardUnit(testData[2][col]), row2si[col], 10f);
298                     assertEquals("row2v", au.getScale().toStandardUnit(testData[2][col]), row2v.getSI(col), 10f);
299                     assertEquals("row2scalar", au.getScale().toStandardUnit(testData[2][col]), row2scalar[col].si, 10f);
300                 }
301                 for (int row = 0; row < testData.length; row++)
302                 {
303                     assertEquals("col2si", au.getScale().toStandardUnit(testData[row][2]), col2si[row], 10f);
304                     assertEquals("col2v", au.getScale().toStandardUnit(testData[row][2]), col2v.getSI(row), 10f);
305                     assertEquals("col2scalar", au.getScale().toStandardUnit(testData[row][2]), col2scalar[row].si, 10f);
306                 }
307                 for (int diag = 0; diag < amSquare.rows(); diag++)
308                 {
309                     assertEquals("diag2si", au.getScale().toStandardUnit(squareData[diag][diag]), diagsi[diag], 0.1f);
310                     assertEquals("diag2v", au.getScale().toStandardUnit(squareData[diag][diag]), diagv.getSI(diag), 0.1f);
311                     assertEquals("diag2scalar", au.getScale().toStandardUnit(squareData[diag][diag]), diagscalar[diag].si,
312                             0.1f);
313                 }
314 
315                 // GETVALUES(), GETSCALARS()
316                 float[][] valsi = am.getValuesSI();
317                 float[][] valunit = am.getValuesInUnit();
318                 float[][] valsqft = am.getValuesInUnit(AreaUnit.SQUARE_YARD);
319                 FloatArea[][] valscalars = am.getScalars();
320                 for (int row = 0; row < testData.length; row++)
321                 {
322                     for (int col = 0; col < testData[0].length; col++)
323                     {
324                         assertEquals("getValuesSI()", au.getScale().toStandardUnit(testData[row][col]), valsi[row][col], 5f);
325                         assertEquals("getValuesInUnit()", testData[row][col], valunit[row][col], 0.1);
326                         assertEquals("getValuesInUnit(unit)", AreaUnit.SQUARE_YARD.getScale()
327                                 .fromStandardUnit(au.getScale().toStandardUnit(testData[row][col])), valsqft[row][col], 10f);
328                         assertEquals("getValuesInUnit(unit)", au.getScale().toStandardUnit(testData[row][col]),
329                                 valscalars[row][col].si, 5f);
330                     }
331                 }
332 
333                 // ASSIGN FUNCTION ABS, CEIL, FLOOR, NEG, RINT
334                 FloatAreaMatrix amdiv2 = am.divide(2.0f);
335                 assertEquals(am.getStorageType(), amdiv2.getStorageType());
336                 assertEquals(am.getDisplayUnit(), amdiv2.getDisplayUnit());
337                 FloatAreaMatrix amAbs = amdiv2.mutable().abs().immutable();
338                 assertEquals(am.getStorageType(), amAbs.getStorageType());
339                 assertEquals(am.getDisplayUnit(), amAbs.getDisplayUnit());
340                 FloatAreaMatrix amCeil = amdiv2.mutable().ceil().immutable();
341                 assertEquals(am.getStorageType(), amCeil.getStorageType());
342                 assertEquals(am.getDisplayUnit(), amCeil.getDisplayUnit());
343                 FloatAreaMatrix amFloor = amdiv2.mutable().floor().immutable();
344                 assertEquals(am.getStorageType(), amFloor.getStorageType());
345                 assertEquals(am.getDisplayUnit(), amFloor.getDisplayUnit());
346                 FloatAreaMatrix amNeg = amdiv2.mutable().neg().immutable();
347                 assertEquals(am.getStorageType(), amNeg.getStorageType());
348                 assertEquals(am.getDisplayUnit(), amNeg.getDisplayUnit());
349                 FloatAreaMatrix amRint = amdiv2.mutable().rint().immutable();
350                 assertEquals(am.getStorageType(), amRint.getStorageType());
351                 assertEquals(am.getDisplayUnit(), amRint.getDisplayUnit());
352                 for (int row = 0; row < testData.length; row++)
353                 {
354                     for (int col = 0; col < testData[0].length; col++)
355                     {
356                         // TODO: Should be rounded IN THE UNIT rather than BY SI VALUES
357                         assertEquals("div2", au.getScale().toStandardUnit(testData[row][col]) / 2.0f, amdiv2.getSI(row, col),
358                                 5f);
359                         assertEquals("abs", (float) Math.abs(au.getScale().toStandardUnit(testData[row][col]) / 2.0f),
360                                 amAbs.getSI(row, col), 0.1f);
361                         assertEquals("ceil", (float) Math.ceil(au.getScale().toStandardUnit(testData[row][col]) / 2.0f),
362                                 amCeil.getSI(row, col), 5f);
363                         assertEquals("floor", (float) Math.floor(au.getScale().toStandardUnit(testData[row][col]) / 2.0f),
364                                 amFloor.getSI(row, col), 5f);
365                         assertEquals("neg", -au.getScale().toStandardUnit(testData[row][col]) / 2.0f, amNeg.getSI(row, col),
366                                 5f);
367                         assertEquals("rint", (float) Math.rint(au.getScale().toStandardUnit(testData[row][col]) / 2.0f),
368                                 amRint.getSI(row, col), 5f);
369                     }
370                 }
371 
372                 float[][] testData4x4 = new float[][] {{2, 3, 5, 7}, {11, 13, 17, 19}, {23, 29, 31, 37}, {41, 43, 47, 49}};
373                 FloatAreaMatrix am4x4 =
374                         FloatMatrix.instantiate(FloatMatrixData.instantiate(testData4x4, au.getScale(), storageType), au);
375                 float det = am4x4.determinantSI();
376                 float detCalc = Determinant.det(am4x4.getValuesSI());
377                 float err = Math.max(det, detCalc) / 1000.0f;
378                 assertEquals("Determinant of square matrix with unit " + au.getDefaultTextualAbbreviation() + ", storage = "
379                         + storageType + " = " + det + " but should have been " + detCalc, detCalc, det, err);
380                 Try.testFail(() -> am.determinantSI(), "Determinant of non-square matrix should have thrown exception");
381 
382                 // TEST METHODS THAT INVOLVE TWO MATRIX INSTANCES
383 
384                 for (StorageType storageType2 : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
385                 {
386                     float[][] testData2 = storageType2.equals(StorageType.DENSE) ? denseTestData : reverseSparseTestData;
387                     for (AreaUnit au2 : new AreaUnit[] {AreaUnit.SQUARE_METER, AreaUnit.ACRE})
388                     {
389 
390                         // PLUS and INCREMENTBY(MATRIX)
391                         FloatAreaMatrix am2 = FloatMatrix
392                                 .instantiate(FloatMatrixData.instantiate(testData2, au2.getScale(), storageType2), au2);
393                         FloatAreaMatrix amSum1 = am.plus(am2);
394                         FloatAreaMatrix amSum2 = am2.plus(am);
395                         FloatAreaMatrix amSum3 = am.mutable().incrementBy(am2).immutable();
396                         FloatAreaMatrix amSum4 = am2.mutable().incrementBy(am).immutable();
397                         assertEquals("a+b == b+a", amSum1, amSum2);
398                         assertEquals("a+b == b+a", amSum1, amSum3);
399                         assertEquals("a+b == b+a", amSum1, amSum4);
400                         for (int row = 0; row < testData.length; row++)
401                         {
402                             for (int col = 0; col < testData[0].length; col++)
403                             {
404                                 float tolerance = Float.isFinite(amSum1.getSI(row, col))
405                                         ? Math.abs(amSum1.getSI(row, col) / 10000.0f) : 0.1f;
406                                 assertEquals("value in matrix matches",
407                                         au.getScale().toStandardUnit(testData[row][col])
408                                                 + au2.getScale().toStandardUnit(testData2[row][col]),
409                                         amSum1.getSI(row, col), tolerance);
410                             }
411                         }
412 
413                         // MINUS and DECREMENTBY(MATRIX)
414                         FloatAreaMatrix amDiff1 = am.minus(am2);
415                         FloatAreaMatrix amDiff2 = am2.minus(am).mutable().neg();
416                         FloatAreaMatrix amDiff3 = am.mutable().decrementBy(am2).immutable();
417                         assertEquals("a-b == -(b-a)", amDiff1, amDiff2);
418                         assertEquals("a-b == -(b-a)", amDiff1, amDiff3);
419                         for (int row = 0; row < testData.length; row++)
420                         {
421                             for (int col = 0; col < testData[0].length; col++)
422                             {
423                                 float tolerance = Float.isFinite(amDiff1.getSI(row, col))
424                                         ? Math.abs(amDiff1.getSI(row, col) / 10000.0f) : 0.1f;
425                                 assertEquals("value in matrix matches",
426                                         au.getScale().toStandardUnit(testData[row][col])
427                                                 - au2.getScale().toStandardUnit(testData2[row][col]),
428                                         amDiff1.getSI(row, col), tolerance);
429                             }
430                         }
431 
432                         // TIMES(MATRIX) and DIVIDE(MATRIX)
433                         FloatSIMatrix amTim = am.times(am2);
434                         FloatSIMatrix amDiv = am.divide(am2);
435                         assertEquals("unit of m2 * m2 should be m4", "m4",
436                                 amTim.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
437                         assertEquals("unit of m2 / m2 should be 1", "1",
438                                 amDiv.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
439                         for (int row = 0; row < testData.length; row++)
440                         {
441                             for (int col = 0; col < testData[0].length; col++)
442                             {
443                                 float tolerance = Float.isFinite(amTim.getSI(row, col))
444                                         ? Math.abs(amTim.getSI(row, col) / 10000.0f) : 0.1f;
445                                 assertEquals("value in m2 * m2 matches",
446                                         au.getScale().toStandardUnit(testData[row][col])
447                                                 * au2.getScale().toStandardUnit(testData2[row][col]),
448                                         amTim.getSI(row, col), tolerance);
449                                 tolerance = Float.isFinite(amTim.getSI(row, col)) ? Math.abs(amDiv.getSI(row, col) / 10000.0f)
450                                         : 0.1f;
451                                 assertEquals("value in m2 / m2 matches (could be NaN)",
452                                         au.getScale().toStandardUnit(testData[row][col])
453                                                 / au2.getScale().toStandardUnit(testData2[row][col]),
454                                         amDiv.getSI(row, col), tolerance);
455                             }
456                         }
457                     }
458                 }
459             }
460         }
461     }
462 
463     /**
464      * Test if mutable methods give an error in case the matrix is immutable.
465      */
466     @Test
467     public void testImmutableMatrix()
468     {
469         float[][] denseTestData = FLOATMATRIX.denseRectArrays(5, 10);
470         float[][] sparseTestData = FLOATMATRIX.sparseRectArrays(5, 10);
471 
472         for (StorageType storageType : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
473         {
474             for (AreaUnit au : new AreaUnit[] {AreaUnit.SQUARE_METER, AreaUnit.ACRE})
475             {
476                 float[][] testData = storageType.equals(StorageType.DENSE) ? denseTestData : sparseTestData;
477                 FloatAreaMatrix am =
478                         FloatMatrix.instantiate(FloatMatrixData.instantiate(testData, au.getScale(), storageType), au);
479                 am = am.immutable();
480                 final FloatAreaMatrix amPtr = am;
481                 FloatArea fa = FloatArea.of(10.0f, "m^2");
482                 Try.testFail(() -> amPtr.assign(FloatMathFunctions.ABS), "ImmutableMatrix.assign(...) should throw error");
483                 Try.testFail(() -> amPtr.decrementBy(fa), "ImmutableMatrix.decrementBy(scalar) should throw error");
484                 Try.testFail(() -> amPtr.decrementBy(amPtr), "ImmutableMatrix.decrementBy(matrix) should throw error");
485                 Try.testFail(() -> amPtr.incrementBy(fa), "ImmutableMatrix.incrementBy(scalar) should throw error");
486                 Try.testFail(() -> amPtr.incrementBy(amPtr), "ImmutableMatrix.incrementBy(matrix) should throw error");
487                 Try.testFail(() -> amPtr.divideBy(2.0f), "ImmutableMatrix.divideBy(factor) should throw error");
488                 Try.testFail(() -> amPtr.multiplyBy(2.0f), "ImmutableMatrix.multiplyBy(factor) should throw error");
489                 Try.testFail(() -> amPtr.set(1, 1, fa), "ImmutableMatrix.set() should throw error");
490                 Try.testFail(() -> amPtr.setSI(1, 1, 20.1f), "ImmutableMatrix.setSI() should throw error");
491                 Try.testFail(() -> amPtr.setInUnit(1, 1, 15.2f), "ImmutableMatrix.setInUnit(f) should throw error");
492                 Try.testFail(() -> amPtr.setInUnit(1, 1, 15.2f, AreaUnit.ARE),
493                         "ImmutableMatrix.setInUnit(f, u) should throw error");
494                 Try.testFail(() -> amPtr.abs(), "ImmutableMatrix.abs() should throw error");
495                 Try.testFail(() -> amPtr.ceil(), "ImmutableMatrix.ceil() should throw error");
496                 Try.testFail(() -> amPtr.floor(), "ImmutableMatrix.floor() should throw error");
497                 Try.testFail(() -> amPtr.neg(), "ImmutableMatrix.neg() should throw error");
498                 Try.testFail(() -> amPtr.rint(), "ImmutableMatrix.rint() should throw error");
499             }
500         }
501     }
502 
503     /**
504      * Test toString() methods. TODO: expand?
505      */
506     @Test
507     public void testMatrixToString()
508     {
509         float[][] denseTestData = FLOATMATRIX.denseRectArrays(5, 10);
510         float[][] sparseTestData = FLOATMATRIX.sparseRectArrays(5, 10);
511 
512         for (StorageType storageType : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
513         {
514             for (AreaUnit au : new AreaUnit[] {AreaUnit.SQUARE_METER, AreaUnit.ACRE})
515             {
516                 float[][] testData = storageType.equals(StorageType.DENSE) ? denseTestData : sparseTestData;
517                 FloatAreaMatrix am =
518                         FloatMatrix.instantiate(FloatMatrixData.instantiate(testData, au.getScale(), storageType), au);
519                 String s1 = am.toString(); // non-verbose with unit
520                 assertTrue(s1.contains(au.getDefaultTextualAbbreviation()));
521                 String s2 = am.toString(AreaUnit.SQUARE_INCH); // non-verbose with unit
522                 assertTrue(s2.contains(AreaUnit.SQUARE_INCH.getDefaultTextualAbbreviation()));
523                 String s3 = am.toString(AreaUnit.SQUARE_INCH, true, true); // verbose with unit
524                 assertTrue(s3.contains(AreaUnit.SQUARE_INCH.getDefaultTextualAbbreviation()));
525                 if (storageType.equals(StorageType.DENSE))
526                 {
527                     assertTrue(s3.contains("Dense"));
528                     assertFalse(s3.contains("Sparse"));
529                 }
530                 else
531                 {
532                     assertFalse(s3.contains("Dense"));
533                     assertTrue(s3.contains("Sparse"));
534                 }
535                 assertTrue(s3.contains("Rel"));
536                 assertFalse(s3.contains("Abs"));
537                 assertTrue(s3.contains("Immutable"));
538                 assertFalse(s3.contains("Mutable"));
539                 FloatAreaMatrix ammut = am.mutable();
540                 String smut = ammut.toString(AreaUnit.SQUARE_INCH, true, true); // verbose with unit
541                 assertFalse(smut.contains("Immutable"));
542                 assertTrue(smut.contains("Mutable"));
543                 String sNotVerbose = ammut.toString(false, false);
544                 assertFalse(sNotVerbose.contains("Rel"));
545                 assertFalse(sNotVerbose.contains("Abs"));
546                 assertFalse(sNotVerbose.contains("Immutable"));
547                 assertFalse(sNotVerbose.contains("Mutable"));
548                 assertFalse(sNotVerbose.contains(au.getDefaultTextualAbbreviation()));
549             }
550         }
551         FloatTimeMatrix tm = FloatMatrix.instantiate(
552                 FloatMatrixData.instantiate(denseTestData, TimeUnit.DEFAULT.getScale(), StorageType.DENSE), TimeUnit.DEFAULT);
553         String st = tm.toString(TimeUnit.DEFAULT, true, true); // verbose with unit
554         assertFalse(st.contains("Rel"));
555         assertTrue(st.contains("Abs"));
556         FloatLengthMatrix lm = FloatMatrix.instantiate(
557                 FloatMatrixData.instantiate(denseTestData, LengthUnit.SI.getScale(), StorageType.DENSE), LengthUnit.SI);
558         String sl = lm.toString(LengthUnit.SI, true, true); // verbose with unit
559         assertTrue(sl.contains("Rel"));
560         assertFalse(sl.contains("Abs"));
561     }
562 
563     /**
564      * Test the extra methods that Absolute and Relative with Absolute matrices implement.
565      */
566     @Test
567     public void testSpecialMatrixMethodsRelWithAbs()
568     {
569         float[][] denseTestData = FLOATMATRIX.denseRectArrays(5, 10);
570         FloatTimeMatrix tm = FloatMatrix.instantiate(
571                 FloatMatrixData.instantiate(denseTestData, TimeUnit.DEFAULT.getScale(), StorageType.DENSE), TimeUnit.DEFAULT);
572         FloatDurationMatrix dm = FloatMatrix.instantiate(
573                 FloatMatrixData.instantiate(denseTestData, DurationUnit.MINUTE.getScale(), StorageType.DENSE),
574                 DurationUnit.SECOND);
575         assertTrue(tm.isAbsolute());
576         assertFalse(dm.isAbsolute());
577         assertFalse(tm.isRelative());
578         assertTrue(dm.isRelative());
579 
580         FloatTimeMatrix absPlusRel = tm.plus(dm);
581         FloatTimeMatrix absMinusRel = tm.minus(dm);
582         float[][] halfDenseData = FLOATMATRIX.denseRectArrays(5, 10);
583         for (int row = 0; row < halfDenseData.length; row++)
584         {
585             for (int col = 0; col < halfDenseData[row].length; col++)
586             {
587                 halfDenseData[row][col] *= 0.5;
588             }
589         }
590         FloatTimeMatrix halfTimeMatrix = FloatMatrix.instantiate(
591                 FloatMatrixData.instantiate(halfDenseData, TimeUnit.DEFAULT.getScale(), StorageType.DENSE), TimeUnit.DEFAULT);
592         FloatDurationMatrix absMinusAbs = tm.minus(halfTimeMatrix);
593         FloatTimeMatrix absDecByRelS = tm.mutable().decrementBy(FloatDuration.of(1.0f, "min"));
594         FloatTimeMatrix absDecByRelM = tm.mutable().decrementBy(dm.divide(2.0f));
595         FloatTimeMatrix relPlusAbs = dm.plus(tm);
596         for (int row = 0; row < denseTestData.length; row++)
597         {
598             for (int col = 0; col < denseTestData[0].length; col++)
599             {
600                 assertEquals("absPlusRel", 61.0 * denseTestData[row][col], absPlusRel.getSI(row, col), 0.01);
601                 assertEquals("absMinusRel", -59.0 * denseTestData[row][col], absMinusRel.getSI(row, col), 0.01);
602                 assertEquals("absMinusAbs", denseTestData[row][col] / 2.0, absMinusAbs.getSI(row, col), 0.01);
603                 assertEquals("absDecByRelS", denseTestData[row][col] - 60.0, absDecByRelS.getSI(row, col), 0.01);
604                 assertEquals("absDecByRelM", -29.0 * denseTestData[row][col], absDecByRelM.getSI(row, col), 0.01);
605                 assertEquals("relPlusAbs", 61.0 * denseTestData[row][col], relPlusAbs.getSI(row, col), 0.01);
606             }
607         }
608         for (int dRows : new int[] {-1, 0, 1})
609         {
610             for (int dCols : new int[] {-1, 0, 1})
611             {
612                 if (dRows == 0 && dCols == 0)
613                 {
614                     continue;
615                 }
616                 float[][] other = FLOATMATRIX.denseRectArrays(denseTestData.length + dRows, denseTestData[0].length + dCols);
617                 FloatTimeMatrix wrongTimeMatrix = FloatMatrix.instantiate(
618                         FloatMatrixData.instantiate(other, TimeUnit.DEFAULT.getScale(), StorageType.DENSE), TimeUnit.DEFAULT);
619                 try
620                 {
621                     tm.mutable().minus(wrongTimeMatrix);
622                     fail("Mismatching size should have thrown a ValueRuntimeException");
623                 }
624                 catch (ValueRuntimeException vre)
625                 {
626                     // Ignore expected exception
627                 }
628             }
629         }
630         assertTrue("toString returns something informative",
631                 FloatMatrixData.instantiate(denseTestData, TimeUnit.DEFAULT.getScale(), StorageType.DENSE).toString()
632                         .startsWith("FloatMatrixData"));
633     }
634 
635     /**
636      * Execute a mats++-like memory test on a sparse matrix. See
637      * <a href="http://www.eng.auburn.edu/~agrawvd/COURSE/E7250_05/REPORTS_TERM/Raghuraman_Mem.doc">Memory Test</a>.
638      */
639     @Test
640     public void memoryTest()
641     {
642         AreaMatrix am = DoubleMatrix.instantiate(new double[5][10], AreaUnit.SI, StorageType.SPARSE);
643         am = am.mutable();
644         double nonZeroValue = 123.456;
645         // Initially the array is filled with zero values; we can skip the initialization phase
646         for (int compoundIndex = 0; compoundIndex < am.cols() * am.rows(); compoundIndex++)
647         {
648             // Let the row count fastest
649             int row = compoundIndex % am.rows();
650             int col = compoundIndex / am.rows();
651             assertEquals("initial value is 0", 0d, am.getSI(row, col), 0.0001);
652             am.setSI(row, col, nonZeroValue);
653             assertEquals("current value is nonZero", nonZeroValue, am.getSI(row, col), 0.0001);
654         }
655         for (int compoundIndex = am.cols() * am.rows(); --compoundIndex >= 0;)
656         {
657             // Let the row count fastest
658             int row = compoundIndex % am.rows();
659             int col = compoundIndex / am.rows();
660             assertEquals("current value is nonZero", nonZeroValue, am.getSI(row, col), 0.0001);
661             am.setSI(row, col, 0d);
662             assertEquals("final value is 0", 0d, am.getSI(row, col), 0.0001);
663         }
664     }
665 
666     /**
667      * Test the instantiateAbs method and instantiateScalarAbsSI method.
668      */
669     @Test
670     public void testInstantiateAbs()
671     {
672         float[][] denseTestData = FLOATMATRIX.denseRectArrays(10, 20);
673         FloatTimeMatrix timeMatrix = FloatMatrix.instantiate(
674                 FloatMatrixData.instantiate(denseTestData, TimeUnit.DEFAULT.getScale(), StorageType.DENSE), TimeUnit.DEFAULT);
675         FloatDurationMatrix durationMatrix = FloatMatrix.instantiate(
676                 FloatMatrixData.instantiate(denseTestData, DurationUnit.MINUTE.getScale(), StorageType.DENSE),
677                 DurationUnit.SECOND);
678 
679         float[] halfDenseData = FLOATVECTOR.denseArray(105);
680         for (int index = 0; index < halfDenseData.length; index++)
681         {
682             halfDenseData[index] *= 0.5;
683         }
684         FloatTimeMatrix relPlusAbsTime = durationMatrix.plus(timeMatrix);
685         for (int row = 0; row < denseTestData.length; row++)
686         {
687             for (int col = 0; col < denseTestData[0].length; col++)
688             {
689                 assertEquals("relPlusAbsTime", 61.0 * denseTestData[row][col], relPlusAbsTime.getSI(row, col), 0.01);
690             }
691         }
692         FloatTime floatTime = durationMatrix.instantiateScalarAbsSI(123.456f, TimeUnit.EPOCH_DAY);
693         assertEquals("Unit of instantiateScalarAbsSI matches", TimeUnit.EPOCH_DAY, floatTime.getDisplayUnit());
694         assertEquals("Value of instantiateScalarAbsSI matches", 123.456f, floatTime.si, 0.1);
695 
696         FloatAngleMatrix angleMatrix = FloatMatrix.instantiate(
697                 FloatMatrixData.instantiate(denseTestData, AngleUnit.DEGREE.getScale(), StorageType.DENSE), AngleUnit.DEGREE);
698         FloatDirectionMatrix directionMatrix = FloatMatrix.instantiate(
699                 FloatMatrixData.instantiate(denseTestData, DirectionUnit.EAST_DEGREE.getScale(), StorageType.DENSE),
700                 DirectionUnit.EAST_DEGREE);
701 
702         FloatDirectionMatrix relPlusAbsDirection = angleMatrix.plus(directionMatrix);
703         for (int row = 0; row < denseTestData.length; row++)
704         {
705             for (int col = 0; col < denseTestData[0].length; col++)
706             {
707                 assertEquals("relPlusAbsTime", 2.0 / 180 * Math.PI * denseTestData[row][col],
708                         relPlusAbsDirection.getSI(row, col), 0.01);
709             }
710         }
711         FloatDirection floatDirection = angleMatrix.instantiateScalarAbsSI(123.456f, DirectionUnit.NORTH_RADIAN);
712         assertEquals("Unit of instantiateScalarAbsSI matches", DirectionUnit.NORTH_RADIAN, floatDirection.getDisplayUnit());
713         assertEquals("Value of instantiateScalarAbsSI matches", 123.456f, floatDirection.si, 0.1);
714 
715         FloatTemperatureMatrix temperatureMatrix = FloatMatrix.instantiate(
716                 FloatMatrixData.instantiate(denseTestData, TemperatureUnit.DEGREE_FAHRENHEIT.getScale(), StorageType.DENSE),
717                 TemperatureUnit.DEGREE_FAHRENHEIT);
718         FloatAbsoluteTemperatureMatrix absoluteTemperatureMatrix = FloatMatrix.instantiate(
719                 FloatMatrixData.instantiate(denseTestData, AbsoluteTemperatureUnit.KELVIN.getScale(), StorageType.DENSE),
720                 AbsoluteTemperatureUnit.KELVIN);
721 
722         FloatAbsoluteTemperatureMatrix relPlusAbsTemperature = temperatureMatrix.plus(absoluteTemperatureMatrix);
723         for (int row = 0; row < denseTestData.length; row++)
724         {
725             for (int col = 0; col < denseTestData[0].length; col++)
726             {
727                 assertEquals("relPlusAbsTime", (1.0 + 5.0 / 9.0) * denseTestData[row][col],
728                         relPlusAbsTemperature.getSI(row, col), 0.01);
729             }
730         }
731         FloatAbsoluteTemperature floatAbsoluteTemperature =
732                 temperatureMatrix.instantiateScalarAbsSI(123.456f, AbsoluteTemperatureUnit.DEGREE_FAHRENHEIT);
733         assertEquals("Unit of instantiateScalarAbsSI matches", AbsoluteTemperatureUnit.DEGREE_FAHRENHEIT,
734                 floatAbsoluteTemperature.getDisplayUnit());
735         assertEquals("Value of instantiateScalarAbsSI matches", 123.456f, floatAbsoluteTemperature.si, 0.1);
736 
737         FloatLengthMatrix lengthMatrix = FloatMatrix.instantiate(
738                 FloatMatrixData.instantiate(denseTestData, LengthUnit.MILE.getScale(), StorageType.DENSE), LengthUnit.MILE);
739         FloatPositionMatrix positionMatrix = FloatMatrix.instantiate(
740                 FloatMatrixData.instantiate(denseTestData, PositionUnit.KILOMETER.getScale(), StorageType.DENSE),
741                 PositionUnit.KILOMETER);
742 
743         FloatPositionMatrix relPlusAbsPosition = lengthMatrix.plus(positionMatrix);
744         for (int row = 0; row < denseTestData.length; row++)
745         {
746             for (int col = 0; col < denseTestData[0].length; col++)
747             {
748                 assertEquals("relPlusAbsTime", 2609.344 * denseTestData[row][col], relPlusAbsPosition.getSI(row, col), 0.1);
749             }
750         }
751         FloatPosition floatPosition = lengthMatrix.instantiateScalarAbsSI(123.456f, PositionUnit.ANGSTROM);
752         assertEquals("Unit of instantiateScalarAbsSI matches", PositionUnit.ANGSTROM, floatPosition.getDisplayUnit());
753         assertEquals("Value of instantiateScalarAbsSI matches", 123.456f, floatPosition.si, 0.1);
754     }
755 
756     /**
757      * Test the <code>as</code> method of the FloatSIMatrix class.
758      * @throws SecurityException on error
759      * @throws NoSuchMethodException on error
760      * @throws InvocationTargetException on error
761      * @throws IllegalArgumentException on error
762      * @throws IllegalAccessException on error
763      * @throws ClassNotFoundException on error
764      * @throws UnitException on error
765      * @param <U> the unit type
766      */
767     @SuppressWarnings("unchecked")
768     @Test
769     public <U extends Unit<U>> void testAsUnit() throws ClassNotFoundException, NoSuchMethodException, SecurityException,
770             IllegalAccessException, IllegalArgumentException, InvocationTargetException, UnitException
771     {
772         float[][] testValues = FLOATMATRIX.denseRectArrays(10, 20);
773         for (StorageType storageType : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
774         {
775             for (String type : CLASSNAMES.REL_LIST)
776             {
777                 Class.forName("org.djunits.unit." + type + "Unit");
778                 Quantity<U> quantity = (Quantity<U>) Quantities.INSTANCE.getQuantity(type + "Unit");
779                 for (U unit : quantity.getUnitsById().values())
780                 {
781                     for (StorageType storageType2 : new StorageType[] {StorageType.DENSE, storageType})
782                     {
783                         SIUnit siUnit = SIUnit.of(unit.getQuantity().getSiDimensions());
784                         FloatSIMatrix matrix = FloatSIMatrix.instantiate(testValues, siUnit, storageType2);
785                         Method asMethod = FloatSIMatrix.class.getDeclaredMethod("as", Unit.class);
786                         AbstractFloatMatrixRel<U, ?, ?, ?> asMatrix =
787                                 (AbstractFloatMatrixRel<U, ?, ?, ?>) asMethod.invoke(matrix, siUnit);
788                         assertEquals(matrix.getDisplayUnit().getStandardUnit(), asMatrix.getDisplayUnit());
789                         siUnit = SIUnit.of(AbsoluteTemperatureUnit.KELVIN.getQuantity().getSiDimensions());
790                         for (int row = 0; row < testValues.length; row++)
791                         {
792                             for (int col = 0; col < testValues[0].length; col++)
793                             {
794                                 assertEquals("Values should match", testValues[row][col], matrix.getInUnit(row, col), 0.001);
795                             }
796                         }
797                         try
798                         {
799                             asMethod.invoke(matrix, siUnit);
800                             fail("as method should not be able to cast to unrelated (absoluteTemperature) unit");
801                         }
802                         catch (InvocationTargetException ite)
803                         {
804                             Throwable cause = ite.getCause();
805                             assertEquals("cause is UnitRuntimeException", UnitRuntimeException.class, cause.getClass());
806                             // Otherwise ignore expected exception
807                         }
808                     }
809                 }
810             }
811         }
812     }
813 
814     /**
815      * Test the equals method.
816      */
817     @SuppressWarnings("unlikely-arg-type")
818     @Test
819     public void testEquals()
820     {
821         float[][] testData = FLOATMATRIX.denseRectArrays(12, 34);
822         testData[2][2] = 0;
823         for (StorageType storageType : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
824         {
825             FloatMatrixData fmd = FloatMatrixData.instantiate(testData, TemperatureUnit.KELVIN.getScale(), storageType);
826             assertTrue("Float matrix is equal to itself", fmd.equals(fmd));
827             assertFalse("Float matrix is not equal to null", fmd.equals(null));
828             assertFalse("Float matrix data is not equal to some string", fmd.equals("some string"));
829             assertTrue("Float matrix is equal to sparse version of itself", fmd.equals(fmd.toSparse()));
830             assertTrue("Float matrix is equal to dense version of itself", fmd.equals(fmd.toDense()));
831             for (StorageType storageType2 : new StorageType[] {StorageType.DENSE, StorageType.SPARSE})
832             {
833                 FloatMatrixData dvd2 = FloatMatrixData.instantiate(testData, TemperatureUnit.KELVIN.getScale(), storageType2);
834                 assertEquals(
835                         "Float matrix data is equal to other double vector containing same values regardless of storage type",
836                         fmd, dvd2);
837                 float[][] testData2 = FLOATMATRIX.denseRectArrays(12, 33);
838                 testData2[2][2] = 0;
839                 dvd2 = FloatMatrixData.instantiate(testData2, TemperatureUnit.KELVIN.getScale(), storageType2);
840                 assertFalse("Float matrix data is not equal to other double vector containing same values except last one",
841                         fmd.equals(dvd2));
842                 testData2 = FLOATMATRIX.denseRectArrays(13, 34);
843                 testData2[2][2] = 0;
844                 dvd2 = FloatMatrixData.instantiate(testData2, TemperatureUnit.KELVIN.getScale(), storageType2);
845                 assertFalse("Float matrix data is not equal to other double vector containing same values except last one",
846                         fmd.equals(dvd2));
847                 testData2 = FLOATMATRIX.denseRectArrays(12, 34);
848                 dvd2 = FloatMatrixData.instantiate(testData2, TemperatureUnit.KELVIN.getScale(), storageType2);
849                 assertFalse("Float matrix data is not equal to other double vector containing same values except for one zero",
850                         fmd.equals(dvd2));
851             }
852         }
853     }
854 
855     /**
856      * Test the sparse value class.
857      */
858     @SuppressWarnings({"rawtypes", "unchecked"})
859     @Test
860     public void sparseValueTest()
861     {
862         try
863         {
864             new FloatSparseValue(-1, 0, 123.456f);
865             fail("Negative row should have caused a ValueRuntimeException");
866         }
867         catch (ValueRuntimeException vre)
868         {
869             // Ignore expected exception
870         }
871 
872         try
873         {
874             new FloatSparseValue(0, -1, 123.456f);
875             fail("Negative column should have caused a ValueRuntimeException");
876         }
877         catch (ValueRuntimeException vre)
878         {
879             // Ignore expected exception
880         }
881 
882         FloatLength length = FloatLength.valueOf("123 km");
883         FloatSparseValue dsv = new FloatSparseValue(2, 3, length);
884         assertEquals("row matches", 2, dsv.getRow());
885         assertEquals("column matches", 3, dsv.getColumn());
886         assertEquals("value matches", 123000, dsv.getValueSI(), 0.1);
887         dsv = new FloatSparseValue(2, 3, 123.000f, LengthUnit.KILOMETER);
888         assertEquals("row matches", 2, dsv.getRow());
889         assertEquals("column matches", 3, dsv.getColumn());
890         assertEquals("value matches", 123000, dsv.getValueSI(), 0.1);
891     }
892 
893 }