Add new Imperial Pressure unit psi (#2758)

Signed-off-by: James Melville <jamesmelville@gmail.com>
This commit is contained in:
James Melville 2022-02-13 09:02:37 +00:00 committed by GitHub
parent 92679aa6fd
commit b594d0a8b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -49,6 +49,9 @@ public final class ImperialUnits extends CustomUnits {
public static final Unit<Pressure> INCH_OF_MERCURY = addUnit(new TransformedUnit<>("inHg", Units.PASCAL,
MultiplyConverter.ofRational(BigInteger.valueOf(3386388), BigInteger.valueOf(1000))));
public static final Unit<Pressure> POUND_FORCE_SQUARE_INCH = addUnit(new TransformedUnit<>("psi", Units.PASCAL,
MultiplyConverter.ofRational(BigInteger.valueOf(6894757), BigInteger.valueOf(1000))));
public static final Unit<Temperature> FAHRENHEIT = addUnit(
new TransformedUnit<>("°F", Units.KELVIN, MultiplyConverter
.ofRational(BigInteger.valueOf(5), BigInteger.valueOf(9)).concatenate(new AddConverter(459.67))));
@ -104,6 +107,7 @@ public final class ImperialUnits extends CustomUnits {
SimpleUnitFormat.getInstance().label(LEAGUE, LEAGUE.getSymbol());
SimpleUnitFormat.getInstance().label(GALLON_LIQUID_US, GALLON_LIQUID_US.getSymbol());
SimpleUnitFormat.getInstance().label(GALLON_PER_MINUTE, "gal/min");
SimpleUnitFormat.getInstance().label(POUND_FORCE_SQUARE_INCH, POUND_FORCE_SQUARE_INCH.getSymbol());
}
private ImperialUnits() {

View File

@ -75,6 +75,14 @@ public class UnitsTest {
isQuantityEquals(Quantities.getQuantity(BigDecimal.ONE, ImperialUnits.INCH_OF_MERCURY)));
}
@Test
public void testPascal2psiConversion() {
Quantity<Pressure> pascal = Quantities.getQuantity(new BigDecimal("6894.757"), SIUnits.PASCAL);
assertThat(pascal.to(ImperialUnits.POUND_FORCE_SQUARE_INCH),
isQuantityEquals(Quantities.getQuantity(BigDecimal.ONE, ImperialUnits.POUND_FORCE_SQUARE_INCH)));
}
@Test
public void testmmHg2PascalConversion() {
Quantity<Pressure> mmHg = Quantities.getQuantity(BigDecimal.ONE, Units.MILLIMETRE_OF_MERCURY);