View Javadoc
1   package org.djunits.unit;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.junit.jupiter.api.Assertions.assertTrue;
5   
6   import java.util.Locale;
7   
8   import org.djunits.unit.unitsystem.UnitSystem;
9   import org.junit.jupiter.api.BeforeEach;
10  import org.junit.jupiter.api.Test;
11  
12  /**
13   * <p>
14   * Copyright (c) 2013-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
16   * </p>
17   * @author <a href="https://tudelft.nl/pknoppers">Peter Knoppers</a>
18   */
19  public class ElectricalPotentialUnitTest extends AbstractLinearUnitTest<ElectricalPotentialUnit>
20  {
21      /**
22       * Set the locale to "en" so we know what texts should be retrieved from the resources.
23       */
24      @BeforeEach
25      public final void setup()
26      {
27          Locale.setDefault(new Locale("en"));
28      }
29  
30      /**
31       * Verify conversion factors, English names and abbreviations.
32       */
33      @Test
34      public final void conversions()
35      {
36          assertEquals("kgm2/s3A", ElectricalPotentialUnit.SI.getQuantity().getSiDimensions().toString(true, false));
37          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.VOLT, 1, 0.00000001, "volt", "V");
38          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.MILLIVOLT, 0.001, 0.00000000001, "millivolt", "mV");
39          checkUnitRatioNameAndAbbreviation(ElectricalPotentialUnit.KILOVOLT, 1000, 0.005, "kilovolt", "kV");
40          // Check two conversions between non-standard units
41          assertEquals(1000000, getMultiplicationFactorTo(ElectricalPotentialUnit.KILOVOLT, ElectricalPotentialUnit.MILLIVOLT),
42                  0.0001, "one KILOVOLT is 1000000 MILLIVOLT");
43      }
44  
45      /**
46       * Verify that we can create our own electrical potential unit.
47       */
48      @Test
49      public final void createElectricalPotentialUnit()
50      {
51          ElectricalPotentialUnit myEPU = ElectricalPotentialUnit.VOLT.deriveLinear(1e-9, "nanoV", "NanoVolt");
52          assertTrue(null != myEPU, "Can create a new ElectricalPotentialUnit");
53          checkUnitRatioNameAndAbbreviation(myEPU, 1e-9, 0.1, "NanoVolt", "nanoV");
54          ElectricalPotentialUnit.BASE.unregister(myEPU);
55  
56          myEPU = ElectricalPotentialUnit.SI.deriveLinear(
57                  PowerUnit.FOOT_POUND_FORCE_PER_HOUR.getScale().toStandardUnit(1.0)
58                          / ElectricalCurrentUnit.MICROAMPERE.getScale().toStandardUnit(1.0),
59                  "ft.lbfph/uA", "foot pound-force per hour per microA", UnitSystem.IMPERIAL);
60          assertTrue(null != myEPU, "Can create a new ElectricalPotentialUnit");
61          checkUnitRatioNameAndAbbreviation(myEPU, 376.6, 0.1, "foot pound-force per hour per microA", "ft.lbfph/uA");
62          ElectricalPotentialUnit.BASE.unregister(myEPU);
63      }
64  
65  }