Skip to content

Commit

Permalink
Issue #14. Adapt unit tests to accept "" as unit string
Browse files Browse the repository at this point in the history
The Dimensionless unit and SI quantity for dimensionless now display ""
instead of "1" (or even "unit").
  • Loading branch information
averbraeck committed Jul 24, 2023
1 parent 763aa4c commit f138060
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/test/java/org/djunits/unit/si/SIRuntimeExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.djunits.unit.SpeedUnit;
import org.djunits.unit.Unit;
import org.junit.Test;

Expand Down Expand Up @@ -84,6 +85,10 @@ public void testException()
@Test
public void testUnitGetUnit()
{
assertTrue(Unit.getUnit("").getQuantity().getSiDimensions().equals(SIDimensions.DIMLESS));
assertTrue(Unit.getUnit("m/s").getQuantity().getSiDimensions()
.equals(SpeedUnit.METER_PER_SECOND.getQuantity().getSiDimensions()));

try
{
Unit.getUnit(null);
Expand All @@ -94,16 +99,6 @@ public void testUnitGetUnit()
assertTrue("Exception describes the parameter that has the problem", npe.getMessage().contains("unitString"));
}

try
{
Unit.getUnit("");
fail("empty string should have thrown a IllegalArgumentException");
}
catch (IllegalArgumentException npe)
{
assertTrue("Exception describes the parameter that has the problem", npe.getMessage().contains("unitString"));
}

try
{
Unit.getUnit("m.m.m.m");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public void testMatrixMethods() throws ValueRuntimeException, UnitException
SIMatrix 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

0 comments on commit f138060

Please sign in to comment.