use of javax.measure.quantity.Length in project smarthome by eclipse.
the class SmartHomeUnitsTest method testM2Ft.
@Test
public void testM2Ft() {
Quantity<Length> cm = Quantities.getQuantity(new BigDecimal("30"), MetricPrefix.CENTI(SIUnits.METRE));
Quantity<Length> foot = cm.to(ImperialUnits.FOOT);
assertThat(foot.getUnit(), is(ImperialUnits.FOOT));
assertThat(foot.getValue().doubleValue(), is(closeTo(0.9842519685039369d, DEFAULT_ERROR)));
}
use of javax.measure.quantity.Length in project tutorials by eugenp.
the class WaterTankTests method givenQuantity_whenGetUnitAndConvertValue_thenSuccess.
@Test
public void givenQuantity_whenGetUnitAndConvertValue_thenSuccess() {
WaterTank waterTank = new WaterTank();
waterTank.setCapacityMeasure(Quantities.getQuantity(9.2, LITRE));
assertEquals(LITRE, waterTank.getCapacityMeasure().getUnit());
Quantity<Volume> waterCapacity = waterTank.getCapacityMeasure();
double volumeInLitre = waterCapacity.getValue().doubleValue();
assertEquals(9.2, volumeInLitre, 0.0f);
double volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(LITRE)).getValue().doubleValue();
assertEquals(9200.0, volumeInMilliLitre, 0.0f);
// compilation error
// volumeInMilliLitre = waterCapacity.to(MetricPrefix.MILLI(KILOGRAM));
Unit<Length> Kilometer = MetricPrefix.KILO(METRE);
// compilation error
// Unit<Length> Centimeter = MetricPrefix.CENTI(LITRE);
}
use of javax.measure.quantity.Length in project indriya by unitsofmeasurement.
the class EBNFFormatTest method testTransformed.
@Test
public void testTransformed() {
final String ANGSTROEM_SYM = "\u212B";
final Unit<Length> ANGSTROEM = new TransformedUnit<Length>(ANGSTROEM_SYM, METRE, METRE, new RationalConverter(BigInteger.ONE, BigInteger.TEN.pow(10)));
final String s = format.format(ANGSTROEM);
assertEquals(ANGSTROEM_SYM, s);
}
use of javax.measure.quantity.Length in project indriya by unitsofmeasurement.
the class SimpleFormatTest method testTransformed.
@Test
public void testTransformed() {
final String ANGSTROEM_SYM = "\u212B";
final Unit<Length> ANGSTROEM = new TransformedUnit<Length>(ANGSTROEM_SYM, METRE, METRE, new RationalConverter(BigInteger.ONE, BigInteger.TEN.pow(10)));
final String s = format.format(ANGSTROEM);
assertEquals(ANGSTROEM_SYM, s);
}
Aggregations