javax.measure.quantity.Mass Java Examples

The following examples show how to use javax.measure.quantity.Mass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnitsTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests getting a unit for a given quantity type.
 */
@Test
public void testGetForQuantity() {
    assertSame("Length",            Units.METRE,             Units.get(Length.class));
    assertSame("Mass",              Units.KILOGRAM,          Units.get(Mass.class));
    assertSame("Time",              Units.SECOND,            Units.get(Time.class));
    assertSame("Temperature",       Units.KELVIN,            Units.get(Temperature.class));
    assertSame("Area",              Units.SQUARE_METRE,      Units.get(Area.class));
    assertSame("Volume",            Units.CUBIC_METRE,       Units.get(Volume.class));
    assertSame("Speed",             Units.METRES_PER_SECOND, Units.get(Speed.class));
    assertSame("LuminousIntensity", Units.CANDELA,           Units.get(LuminousIntensity.class));
    assertSame("LuminousFlux",      Units.LUMEN,             Units.get(LuminousFlux.class));
    assertSame("SolidAngle",        Units.STERADIAN,         Units.get(SolidAngle.class));
    assertSame("Angle",             Units.RADIAN,            Units.get(Angle.class));
    assertSame("Dimensionless",     Units.UNITY,             Units.get(Dimensionless.class));
}
 
Example #2
Source File: ArithmeticTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAdd() {
	Quantity<Mass> kg = Quantities.getQuantity(5d, Units.KILOGRAM);
	Quantity<Mass> p = Quantities.getQuantity(10d, CLDR.CARAT);
	Quantity<Mass> result = kg.add(p);
	assertEquals(RationalNumber.of(5002, 1000), result.getValue());
	assertEquals(Units.KILOGRAM, result.getUnit());
}
 
Example #3
Source File: ArithmeticTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSubtract2() {
	Quantity<Mass> kg = Quantities.getQuantity(5d, Units.KILOGRAM);
	Quantity<Mass> p = Quantities.getQuantity(10d, CLDR.CARAT);
	Quantity<Mass> result = kg.subtract(p);
	assertEquals(RationalNumber.of(4998, 1000), result.getValue());
	assertEquals(Units.KILOGRAM, result.getUnit());
}
 
Example #4
Source File: UnitsTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGetParentUnit() {
	assertEquals("TransformedUnit", Units.GRAM.getClass().getSimpleName());
	assertEquals("kg", ((TransformedUnit<Mass>) Units.GRAM).getParentUnit().getSymbol());
	// assertEquals("kg", UCUM.POUND.getSymbol()); //"lb"
	// assertEquals("kg", UCUM.OUNCE.getSymbol());//"oz"
	// assertEquals("kg", MetricPrefix.KILO(UCUM.GRAM).getSymbol());
	// assertEquals("kg", UCUM.GRAM.getSymbol()); //"g"
	// assertEquals("kg", US.POUND.getSymbol()); //"lb"
}
 
Example #5
Source File: ArithmeticTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAdd2() {
	Quantity<Mass> kg = Quantities.getQuantity(50d, Units.KILOGRAM);
	Quantity<Mass> p = Quantities.getQuantity(10d, USCustomary.POUND);
	Quantity<Mass> result = kg.add(p);
	assertEquals(54.5359237d, result.getValue().doubleValue(), 0d);
	assertEquals(Units.KILOGRAM, result.getUnit());
}
 
Example #6
Source File: ArithmeticTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSubtract2() {
	Quantity<Mass> kg = Quantities.getQuantity(50d, Units.KILOGRAM);
	Quantity<Mass> p = Quantities.getQuantity(10d, USCustomary.POUND);
	Quantity<Mass> result = kg.subtract(p);
	assertEquals(45.4640763d, result.getValue().doubleValue(), 0d);
	assertEquals(Units.KILOGRAM, result.getUnit());
}
 
Example #7
Source File: UCUMTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testAMU() {
	Unit<Mass> atomicMassUnit = ATOMIC_MASS_UNIT;
	System.out.println(atomicMassUnit.getSymbol());
}
 
Example #8
Source File: UnitFormatPrefixTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testKiloGram() {
	Unit<Mass> m1 = KILO(GRAM);
	assertEquals("kg", FORMAT_PRINT.format(m1));
}
 
Example #9
Source File: UnitFormatPrefixTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testMegaGram() {
	Unit<Mass> m1 = MEGA(GRAM);
	assertEquals("t", FORMAT_PRINT.format(TONNE));
	assertEquals("Mg", FORMAT_PRINT.format(m1));
}
 
Example #10
Source File: UnitFormatPrefixTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testMegaTonne() {
	Unit<Mass> m1 = MEGA(TONNE);
	assertEquals("Mt", FORMAT_PRINT.format(m1));
}
 
Example #11
Source File: UnitFormatPrefixTest.java    From uom-systems with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Test
public void testNanoGram() {
	Unit<Mass> m1 = NANO(GRAM);
	assertEquals("ng", FORMAT_PRINT.format(m1));
}