Search in sources :

Example 11 with UnitConverter

use of javax.measure.UnitConverter in project indriya by unitsofmeasurement.

the class PrefixTest method testKibi.

@Test
public void testKibi() {
    final UnitConverter expected = new RationalConverter(128, 125);
    final UnitConverter actual = KIBI(METRE).getConverterTo(KILO(METRE));
    assertEquals("Ki", KIBI.getSymbol());
    assertEquals(expected, actual);
}
Also used : RationalConverter(tech.units.indriya.function.RationalConverter) UnitConverter(javax.measure.UnitConverter) Test(org.junit.jupiter.api.Test)

Example 12 with UnitConverter

use of javax.measure.UnitConverter in project indriya by unitsofmeasurement.

the class PrefixTest method testZebi.

@Test
public void testZebi() {
    final UnitConverter expected = new RationalConverter(1, 6835937500000000000L);
    final UnitConverter actual = ZEBI(GRAM).getConverterTo(ZETTA(GRAM));
    assertEquals(expected, actual);
}
Also used : RationalConverter(tech.units.indriya.function.RationalConverter) UnitConverter(javax.measure.UnitConverter) Test(org.junit.jupiter.api.Test)

Example 13 with UnitConverter

use of javax.measure.UnitConverter in project indriya by unitsofmeasurement.

the class PrefixTest method testYobi.

@Test
public void testYobi() {
    final UnitConverter expected = new RationalConverter(BigInteger.ONE, BigDecimal.valueOf(7812500000000000000000D).toBigInteger());
    final UnitConverter actual = YOBI(GRAM).getConverterTo(YOTTA(GRAM));
    assertEquals(expected, actual);
}
Also used : RationalConverter(tech.units.indriya.function.RationalConverter) UnitConverter(javax.measure.UnitConverter) Test(org.junit.jupiter.api.Test)

Example 14 with UnitConverter

use of javax.measure.UnitConverter in project indriya by unitsofmeasurement.

the class PrefixTest method testNestedOperationsShouldBeSame.

@Test
@Disabled("This is research for https://github.com/unitsofmeasurement/uom-se/issues/164")
public void testNestedOperationsShouldBeSame() {
    Unit<Mass> m1 = MICRO(GRAM);
    Unit<Mass> m2 = GRAM.divide(1000).divide(1000);
    UnitConverter c1 = m1.getConverterTo(m2);
    List steps1 = c1.getConversionSteps();
    UnitConverter c2 = m2.getConverterTo(m1);
    List steps2 = c2.getConversionSteps();
    assertEquals(c1, c2);
    assertEquals(m1, m2);
}
Also used : Mass(javax.measure.quantity.Mass) UnitConverter(javax.measure.UnitConverter) List(java.util.List) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 15 with UnitConverter

use of javax.measure.UnitConverter in project indriya by unitsofmeasurement.

the class UnitsTest method testConverterToSI.

/**
 * Test method for {@link javax.measure.Unit#toMetric()}.
 */
// @Test
// public void testToMetric() {
// AbstractUnit<? extends QuantityAmount> su = (AbstractUnit<? extends
// QuantityAmount>) one.toMetric();
// assertTrue(su.isUnscaledMetric());
// }
/**
 * Test method for {@link javax.measure.Unit#getConverterTo}.
 */
@Test
public void testConverterToSI() {
    Double factor = 10.0;
    UnitConverter converter = one.getConverterTo(one);
    Double result = converter.convert(factor.doubleValue());
    assertEquals(result, factor);
    logger.log(Level.FINER, result.toString());
}
Also used : UnitConverter(javax.measure.UnitConverter) Test(org.junit.jupiter.api.Test)

Aggregations

UnitConverter (javax.measure.UnitConverter)54 IncommensurableException (javax.measure.IncommensurableException)18 UnconvertibleException (javax.measure.UnconvertibleException)13 Test (org.junit.jupiter.api.Test)11 Test (org.junit.Test)9 RationalConverter (tech.units.indriya.function.RationalConverter)7 Unit (javax.measure.Unit)5 List (java.util.List)4 Mass (javax.measure.quantity.Mass)4 Date (java.util.Date)3 DateFormat (java.text.DateFormat)2 DecimalFormat (java.text.DecimalFormat)2 Format (java.text.Format)2 NumberFormat (java.text.NumberFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 Dimension (javax.measure.Dimension)2 CompoundFormat (org.apache.sis.io.CompoundFormat)2 Angle (org.apache.sis.measure.Angle)2 AngleFormat (org.apache.sis.measure.AngleFormat)2