View Javadoc
1   package org.djunits.unit;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertTrue;
5   
6   import java.util.Locale;
7   
8   import org.djunits.locale.DefaultLocale;
9   import org.djunits.unit.unitsystem.UnitSystem;
10  import org.junit.Before;
11  import org.junit.Test;
12  
13  /**
14   * <p>
15   * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
17   * <p>
18   * @author <a href="https://tudelft.nl/pknoppers">Peter Knoppers</a>
19   */
20  public class PressureUnitTest extends AbstractLinearUnitTest<PressureUnit>
21  {
22      /**
23       * Set the locale to "en" so we know what texts should be retrieved from the resources.
24       */
25      @Before
26      public final void setup()
27      {
28          DefaultLocale.setLocale(new Locale("en"));
29      }
30  
31      /**
32       * Verify conversion factors, English names and abbreviations.
33       */
34      @Test
35      public final void conversions()
36      {
37          assertEquals("kg/ms2", PressureUnit.SI.getQuantity().getSiDimensions().toString(true, false));
38          checkUnitRatioNameAndAbbreviation(PressureUnit.PASCAL, 1, 0.00000001, "pascal", "Pa");
39          checkUnitRatioNameAndAbbreviation(PressureUnit.ATMOSPHERE_STANDARD, 101325, 0.5, "atmosphere (standard)", "atm");
40          checkUnitRatioNameAndAbbreviation(PressureUnit.ATMOSPHERE_TECHNICAL, 98066.5, 0.1, "atmosphere (technical)", "at");
41          // Check two conversions between non-standard units
42          assertEquals("one ATMOSPHERE STANDARD is about 1.03327 ATMOSPHERE TECHNICAL", 1 / 0.9678,
43                  getMultiplicationFactorTo(PressureUnit.ATMOSPHERE_STANDARD, PressureUnit.ATMOSPHERE_TECHNICAL), 0.0001);
44          assertEquals("one ATMOSPHERE TECHNICAL is 0.9678 ATMOSPHERE STANDARD", 0.9678,
45                  getMultiplicationFactorTo(PressureUnit.ATMOSPHERE_TECHNICAL, PressureUnit.ATMOSPHERE_STANDARD), 0.0001);
46          // Check conversion factor to standard unit for all remaining time units
47          checkUnitRatioNameAndAbbreviation(PressureUnit.HECTOPASCAL, 100, 0.0001, "hectopascal", "hPa");
48          checkUnitRatioNameAndAbbreviation(PressureUnit.KILOPASCAL, 1000, 0.001, "kilopascal", "kPa");
49          checkUnitRatioNameAndAbbreviation(PressureUnit.BAR, 100000, 0.01, "bar", "bar");
50          checkUnitRatioNameAndAbbreviation(PressureUnit.MILLIBAR, 100, 0.000001, "millibar", "mbar");
51          checkUnitRatioNameAndAbbreviation(PressureUnit.CENTIMETER_MERCURY, 1333.22368, 0.001, "centimeter mercury", "cmHg");
52          checkUnitRatioNameAndAbbreviation(PressureUnit.MILLIMETER_MERCURY, 133.322368, 0.001, "millimeter mercury", "mmHg");
53          checkUnitRatioNameAndAbbreviation(PressureUnit.FOOT_MERCURY, 40636.66, 0.01, "foot mercury", "ftHg");
54          checkUnitRatioNameAndAbbreviation(PressureUnit.INCH_MERCURY, 3386, 0.5, "inch mercury", "inHg");
55          checkUnitRatioNameAndAbbreviation(PressureUnit.KGF_PER_SQUARE_MM, 9806650, 0.5, "kilogram-force per square millimeter",
56                  "kgf/mm^2");
57          checkUnitRatioNameAndAbbreviation(PressureUnit.POUND_PER_SQUARE_FOOT, 47.880259, 0.000001,
58                  "pound-force per square foot", "lbf/ft^2");
59          checkUnitRatioNameAndAbbreviation(PressureUnit.POUND_PER_SQUARE_INCH, 6894.75729, 0.00001,
60                  "pound-force per square inch", "lbf/in^2");
61      }
62  
63      /**
64       * Verify that we can create our own pressure unit.
65       */
66      @Test
67      public final void createPressureUnit()
68      {
69          PressureUnit myPU = PressureUnit.MILLIMETER_MERCURY.deriveLinear(106, "hhhp", "HealthyHumanHeart", UnitSystem.OTHER);
70          assertTrue("Can create a new PowerUnit", null != myPU);
71          checkUnitRatioNameAndAbbreviation(myPU, 14132.1711, 0.01, "HealthyHumanHeart", "hhhp");
72          PressureUnit.BASE.unregister(myPU);
73      }
74  
75  }