Search in sources :

Example 1 with Speed

use of javax.measure.quantity.Speed 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 2 with Speed

use of javax.measure.quantity.Speed 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)

Aggregations

IOException (java.io.IOException)2 Unit (javax.measure.Unit)2 UnitFormat (javax.measure.format.UnitFormat)2 Speed (javax.measure.quantity.Speed)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 LocalUnitFormat (tech.units.indriya.format.LocalUnitFormat)1 SimpleUnitFormat (tech.units.indriya.format.SimpleUnitFormat)1