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 ElectricalPotentialUnitTest extends AbstractLinearUnitTest<ElectricalPotentialUnit>
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("kgm2/s3A", ElectricalPotentialUnit.SI.getQuantity().getSiDimensions().toString(true, false));
38          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.VOLT, 1, 0.00000001, "volt", "V");
39          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.MILLIVOLT, 0.001, 0.00000000001, "millivolt", "mV");
40          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.KILOVOLT, 1000, 0.005, "kilovolt", "kV");
41          // Check two conversions between non-standard units
42          assertEquals("one KILOVOLT is 1000000 MILLIVOLT", 1000000,
43                  getMultiplicationFactorTo(ElectricalPotentialUnit.KILOVOLT, ElectricalPotentialUnit.MILLIVOLT), 0.0001);
44      }
45  
46      /**
47       * Verify that we can create our own electrical potential unit.
48       */
49      @Test
50      public final void createElectricalPotentialUnit()
51      {
52          ElectricalPotentialUnit myEPU = ElectricalPotentialUnit.VOLT.deriveLinear(1e-9, "nanoV", "NanoVolt");
53          assertTrue("Can create a new ElectricalPotentialUnit", null != myEPU);
54          checkUnitRatioNameAndAbbreviation(myEPU, 1e-9, 0.1, "NanoVolt", "nanoV");
55          ElectricalPotentialUnit.BASE.unregister(myEPU);
56  
57          myEPU = ElectricalPotentialUnit.SI.deriveLinear(
58                  PowerUnit.FOOT_POUND_FORCE_PER_HOUR.getScale().toStandardUnit(1.0)
59                          / ElectricalCurrentUnit.MICROAMPERE.getScale().toStandardUnit(1.0),
60                  "ft.lbfph/uA", "foot pound-force per hour per microA", UnitSystem.IMPERIAL);
61          assertTrue("Can create a new ElectricalPotentialUnit", null != myEPU);
62          checkUnitRatioNameAndAbbreviation(myEPU, 376.6, 0.1, "foot pound-force per hour per microA", "ft.lbfph/uA");
63          ElectricalPotentialUnit.BASE.unregister(myEPU);
64      }
65  
66  }