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