Skip to content

Commit

Permalink
Issue #14. Ensure tests don't expect unit 1 for dimensionless
Browse files Browse the repository at this point in the history
  • Loading branch information
averbraeck committed Jul 23, 2023
1 parent 63bdd33 commit 771faf7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/test/java/org/djunits/unit/DimensionlessUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final void setup()
@Test
public final void conversions()
{
assertEquals("1", DimensionlessUnit.SI.getQuantity().getSiDimensions().toString(true, false));
assertEquals("", DimensionlessUnit.SI.getQuantity().getSiDimensions().toString(true, false));
checkUnitRatioNameAndAbbreviation(DimensionlessUnit.SI, 1, 0.000001, "", "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,12 @@ public void testSIScalar() throws UnitException
// test if the . in 10.0 is not removed...
assertEquals(SIScalar.instantiateSI(10.0, m2), SIScalar.valueOf("10.0 m^2"));

legal(SIScalar.class, 10.0, "");
assertEquals(SIScalar.instantiateSI(10.0, SIUnit.DIMLESS), SIScalar.valueOf("10.0"));

legal(SIScalar.class, 10.0, "m2");
legal(SIScalar.class, "10.0 m2");
illegal(SIScalar.class, 10.0, null);
illegal(SIScalar.class, 10.0, "");
illegal(SIScalar.class, null);
illegal(SIScalar.class, "");
// illegal(SIScalar.class, "1.0.0 m2"); // formatter.parse() does not use the whole number string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void testVectorMethods() throws ValueRuntimeException, UnitException
SIVector amDiv = am.divide(am2);
assertEquals("unit of m2 * m2 should be m4", "m4",
amTim.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
assertEquals("unit of m2 / m2 should be 1", "1",
assertEquals("unit of m2 / m2 should be empty string", "",
amDiv.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
for (int index = 0; index < testData.length; index++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void testMatrixMethods() throws ValueRuntimeException, UnitException
FloatSIMatrix amDiv = am.divide(am2);
assertEquals("unit of m2 * m2 should be m4", "m4",
amTim.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
assertEquals("unit of m2 / m2 should be 1", "1",
assertEquals("unit of m2 / m2 should be empty string", "",
amDiv.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
for (int row = 0; row < testData.length; row++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class FloatValueOfTest
* @param value the value to enter
* @param unitString the unit String to use
*/
private void legal(final Class<? extends FloatScalar<?, ?>> scalarClass, final float value,
final String unitString)
private void legal(final Class<? extends FloatScalar<?, ?>> scalarClass, final float value, final String unitString)
{
try
{
Expand Down Expand Up @@ -68,8 +67,7 @@ private void legal(final Class<? extends FloatScalar<?, ?>> scalarClass, final S
* @param value the value to enter
* @param unitString the unit String to use
*/
private void illegal(final Class<? extends FloatScalar<?, ?>> scalarClass, final float value,
final String unitString)
private void illegal(final Class<? extends FloatScalar<?, ?>> scalarClass, final float value, final String unitString)
{
try
{
Expand Down Expand Up @@ -125,10 +123,12 @@ public void testFloatSIScalar() throws UnitException
// test if the . in 10.0 is not removed...
assertEquals(FloatSIScalar.instantiateSI(10.0f, m2), FloatSIScalar.valueOf("10.0 m^2"));

legal(FloatSIScalar.class, 10.0f, "");
assertEquals(FloatSIScalar.instantiateSI(10.0f, SIUnit.DIMLESS), FloatSIScalar.valueOf("10.0"));

legal(FloatSIScalar.class, 10.0f, "m2");
legal(FloatSIScalar.class, "10.0 m2");
illegal(FloatSIScalar.class, 10.0f, null);
illegal(FloatSIScalar.class, 10.0f, "");
illegal(FloatSIScalar.class, null);
illegal(FloatSIScalar.class, "");
// illegal(FloatSIScalar.class, "1.0.0 m2"); // formatter.pasrse() does not use the whole number string
Expand All @@ -143,7 +143,7 @@ public void testFloatSIScalar() throws UnitException
{
// Ignore expected exception
}

try
{
FloatSIScalar.valueOf("xyzuvw");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void testVectorMethods() throws ValueRuntimeException, UnitException
FloatSIVector amDiv = am.divide(am2);
assertEquals("unit of m2 * m2 should be m4", "m4",
amTim.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
assertEquals("unit of m2 / m2 should be 1", "1",
assertEquals("unit of m2 / m2 should be empty string", "",
amDiv.getDisplayUnit().getQuantity().getSiDimensions().toString(false, false, false));
for (int index = 0; index < testData.length; index++)
{
Expand Down

0 comments on commit 771faf7

Please sign in to comment.