-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
After parsing a symbol and formating to Unit again, the same symbol should be created or at least a equivalent Unit.
But for Units that contain number 10 (or multiplications of it) that fails:
Example 1: L/(100.km)
@Test
void shouldBeSameSymbol() {
//given
UCUMFormat ucumFormat = UCUMFormat.getInstance(DEFAULT_UCUM_FORMAT);
String unitSymbol = "L/(100.km)";
Unit programatic = LITER.divide(KILO(METER).multiply(100));
//when
Unit parsed = ucumFormat.parse(unitSymbol);
String parsedSymbol = ucumFormat.format(parsed);
//when
assertTrue(parsed.isEquivalentTo(programatic)); //ok
assertThat(parsedSymbol, is(unitSymbol)); //fails
}
results in Expected: is "L/(100.km)" but: was "L/(10^2.km)"
That is acceptable...should at least be equivalent. But when i try to parse that again:
@Test
void shouldParseLiterPer100kmWithExp() {
//given
UCUMFormat ucumFormat = UCUMFormat.getInstance(DEFAULT_UCUM_FORMAT);
String aUnitSymbol = "L/(10^2.km)";
//when
Unit<? extends Quantity<?>> parsed = ucumFormat.parse(aUnitSymbol);
String parsedSymbol = ucumFormat.format(parsed);
//when
assertThat(parsedSymbol, is(aUnitSymbol));
}
an Exception occures during parse:
systems.uom.ucum.internal.format.TokenException
at systems.uom.ucum.internal.format.UCUMFormatParser.SimpleUnit(UCUMFormatParser.java:207)
at systems.uom.ucum.internal.format.UCUMFormatParser.Annotatable(UCUMFormatParser.java:158)
at systems.uom.ucum.internal.format.UCUMFormatParser.Component(UCUMFormatParser.java:122)
at systems.uom.ucum.internal.format.UCUMFormatParser.Term(UCUMFormatParser.java:77)
at systems.uom.ucum.internal.format.UCUMFormatParser.Component(UCUMFormatParser.java:141)
at systems.uom.ucum.internal.format.UCUMFormatParser.Term(UCUMFormatParser.java:96)
at systems.uom.ucum.internal.format.UCUMFormatParser.parseUnit(UCUMFormatParser.java:67)
at systems.uom.ucum.format.UCUMFormat$Parsing.parse(UCUMFormat.java:491)
at systems.uom.ucum.format.UCUMFormat$Parsing.parse(UCUMFormat.java:509)
Even worse when i try with symbol "L/(10.mm)"
@Test
void shouldBeSameSymbol2() {
//given
UCUMFormat ucumFormat = UCUMFormat.getInstance(DEFAULT_UCUM_FORMAT);
String unitSymbol = "L/(10.mm)";
Unit programatic = LITER.divide(MILLI(METER).multiply(10));
//when
Unit parsed = ucumFormat.parse(unitSymbol);
String parsedSymbol = ucumFormat.format(parsed);
//when
assertTrue(parsed.isEquivalentTo(programatic), parsedSymbol); //fails here!
assertThat(parsedSymbol, is(unitSymbol));
}
the parse results in a symbol "L/(da.mm)"...which imho makes no sense.
Trying to parse 'L/(da.mm)' leads to a TokenException, too (same StackTrace as in example 1):
@Test
void shouldParseLiterPer10mmWithDeka() {
//given
UCUMFormat ucumFormat = UCUMFormat.getInstance(DEFAULT_UCUM_FORMAT);
String aUnitSymbol = "L/(da.mm)";
//when
assertDoesNotThrow(() -> ucumFormat.parse(aUnitSymbol)); //fails, throws tokenException
}
DrDanielMetz, KaiSuchomel and MimoDevelop