Search in sources :

Example 11 with UnitFormat

use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.

the class UnitFormatTest method testParseIrregularStringSimple.

@Test
public void testParseIrregularStringSimple() {
    final UnitFormat format = SimpleUnitFormat.getInstance();
    assertThrows(MeasurementParseException.class, () -> {
        Unit<?> u = format.parse("bl//^--1a");
    });
}
Also used : UnitFormat(javax.measure.format.UnitFormat) LocalUnitFormat(tech.units.indriya.format.LocalUnitFormat) SimpleUnitFormat(tech.units.indriya.format.SimpleUnitFormat) Test(org.junit.jupiter.api.Test)

Example 12 with UnitFormat

use of javax.measure.format.UnitFormat in project indriya by unitsofmeasurement.

the class UnitFormatTest method testFormatLocal.

@Test
public void testFormatLocal() {
    final UnitFormat format = LocalUnitFormat.getInstance();
    final Appendable a = new StringBuilder();
    try {
        format.format(METRE, a);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertEquals(METRE, sut.getUnit());
    assertEquals("m", a.toString());
    final Appendable a2 = new StringBuilder();
    @SuppressWarnings("unchecked") Unit<Speed> v = (Unit<Speed>) METRE.divide(SECOND);
    try {
        format.format(v, a2);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertEquals("m/s", a2.toString());
}
Also used : Speed(javax.measure.quantity.Speed) UnitFormat(javax.measure.format.UnitFormat) LocalUnitFormat(tech.units.indriya.format.LocalUnitFormat) SimpleUnitFormat(tech.units.indriya.format.SimpleUnitFormat) IOException(java.io.IOException) Unit(javax.measure.Unit) Test(org.junit.jupiter.api.Test)

Example 13 with UnitFormat

use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.

the class UnitFormatTest method testParseIrregularStringSimple.

@Test(expected = ParserException.class)
public void testParseIrregularStringSimple() {
    final UnitFormat format = SimpleUnitFormat.getInstance();
    Unit<?> u = format.parse("bl//^--1a");
}
Also used : UnitFormat(javax.measure.format.UnitFormat) Test(org.junit.Test)

Example 14 with UnitFormat

use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.

the class UnitFormatTest method testFormatLocal.

@Test
public void testFormatLocal() {
    final UnitFormat format = LocalUnitFormat.getInstance();
    final Appendable a = new StringBuilder();
    try {
        format.format(METRE, a);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertEquals(METRE, sut.getUnit());
    assertEquals("m", a.toString());
    final Appendable a2 = new StringBuilder();
    @SuppressWarnings("unchecked") Unit<Speed> v = (Unit<Speed>) METRE.divide(SECOND);
    try {
        format.format(v, a2);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    assertEquals("m/s", a2.toString());
}
Also used : Speed(javax.measure.quantity.Speed) UnitFormat(javax.measure.format.UnitFormat) IOException(java.io.IOException) Unit(javax.measure.Unit) Test(org.junit.Test)

Example 15 with UnitFormat

use of javax.measure.format.UnitFormat in project uom-se by unitsofmeasurement.

the class LocalFormatTest method testFormatKm.

@Test
public void testFormatKm() {
    final UnitFormat format = LocalUnitFormat.getInstance();
    String s = format.format(KILO(METRE));
    assertEquals("km", s);
}
Also used : UnitFormat(javax.measure.format.UnitFormat) Test(org.junit.Test)

Aggregations

UnitFormat (javax.measure.format.UnitFormat)17 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 LocalUnitFormat (tech.units.indriya.format.LocalUnitFormat)7 SimpleUnitFormat (tech.units.indriya.format.SimpleUnitFormat)3 IOException (java.io.IOException)2 Unit (javax.measure.Unit)2 ParserException (javax.measure.format.ParserException)2 Speed (javax.measure.quantity.Speed)2 Locale (java.util.Locale)1 ServiceProvider (javax.measure.spi.ServiceProvider)1 Ignore (org.junit.Ignore)1 Disabled (org.junit.jupiter.api.Disabled)1