コード例 #1
0
  @Test
  public void getQuantityTest() {
    Quantity<Pressure> bigDecimalQuantity = Quantities.getQuantity(BigDecimal.ONE, PASCAL);
    Quantity<Pressure> bigIntegerQuantity = Quantities.getQuantity(BigInteger.ONE, PASCAL);

    Quantity<Pressure> shortQuantity = Quantities.getQuantity(Short.valueOf("2"), PASCAL);
    Quantity<Pressure> byteQuantity = Quantities.getQuantity(Byte.valueOf("2"), PASCAL);
    Quantity<Pressure> longQuantity = Quantities.getQuantity(Long.valueOf("2"), PASCAL);
    Quantity<Pressure> intQuantity = Quantities.getQuantity(Integer.valueOf("2"), PASCAL);
    Quantity<Pressure> floatQuantity = Quantities.getQuantity(Float.valueOf("2"), PASCAL);
    Quantity<Pressure> doubleQuantity = Quantities.getQuantity(Double.valueOf("2"), PASCAL);

    assertTrue(Short.class.isInstance(shortQuantity.getValue()));
    assertTrue(Byte.class.isInstance(byteQuantity.getValue()));
    assertTrue(Long.class.isInstance(longQuantity.getValue()));
    assertTrue(Integer.class.isInstance(intQuantity.getValue()));
    assertTrue(Float.class.isInstance(floatQuantity.getValue()));
    assertTrue(Double.class.isInstance(doubleQuantity.getValue()));
    assertTrue(BigDecimal.class.isInstance(bigIntegerQuantity.getValue()));
    assertTrue(BigDecimal.class.isInstance(bigDecimalQuantity.getValue()));

    assertTrue(NumberQuantity.class.isInstance(shortQuantity));
    assertTrue(NumberQuantity.class.isInstance(byteQuantity));
    assertTrue(NumberQuantity.class.isInstance(longQuantity));
    assertTrue(NumberQuantity.class.isInstance(intQuantity));
    assertTrue(NumberQuantity.class.isInstance(floatQuantity));
    assertTrue(DoubleQuantity.class.isInstance(doubleQuantity));
    assertTrue(DecimalQuantity.class.isInstance(bigIntegerQuantity));
    assertTrue(DecimalQuantity.class.isInstance(bigDecimalQuantity));
  }
コード例 #2
0
 @Test
 public void testLength() {
   Quantity<Length> l =
       DefaultQuantityFactory.getInstance(Length.class).create(23.5, METRE); // 23.0 km
   assertEquals(Double.valueOf(23.5d), l.getValue());
   assertEquals(METRE, l.getUnit());
   assertEquals("m", l.getUnit().getSymbol());
 }
コード例 #3
0
 @Test
 @Ignore
 public void testMass() {
   Quantity<Mass> m = DefaultQuantityFactory.getInstance(Mass.class).create(10, KILOGRAM); // 10 kg
   assertEquals(Integer.valueOf(10), m.getValue());
   assertEquals(KILOGRAM, m.getUnit());
   assertEquals("kg", m.getUnit().getSymbol());
   assertEquals("10 kg", m.toString());
 }
コード例 #4
0
 @Test
 public void testTime() {
   Quantity<Time> t = DefaultQuantityFactory.getInstance(Time.class).create(40, MINUTE); // 40 min
   assertEquals(Integer.valueOf(40), t.getValue());
   assertEquals(MINUTE, t.getUnit());
   assertNull(t.getUnit().getSymbol());
   //		assertEquals("s", t.getUnit().getSymbol()); // FIXME this should be "min", tweak for
   // TransformedUnit
   assertEquals("40 min", t.toString());
 }