Class EnergyConverterTest

java.lang.Object
com.irurueta.units.EnergyConverterTest

class EnergyConverterTest extends Object
Unit tests for EnergyConverter.
  • Field Details

    • JOULES_PER_KILOJOULE

      private static final double JOULES_PER_KILOJOULE
      Number of joules in 1 kilojoule.
      See Also:
    • JOULES_PER_MEGAJOULE

      private static final double JOULES_PER_MEGAJOULE
      Number of joules in 1 megajoule.
      See Also:
    • JOULES_PER_CALORIE

      private static final double JOULES_PER_CALORIE
      Number of joules in 1 calorie.
      See Also:
    • JOULES_PER_KILOCALORIE

      private static final double JOULES_PER_KILOCALORIE
      Number of joules in 1 kilocalorie.
      See Also:
    • JOULES_PER_KILOWATT_HOUR

      private static final double JOULES_PER_KILOWATT_HOUR
      Number of joules in 1 kilowatt-hour.
      See Also:
    • JOULES_PER_BTU

      private static final double JOULES_PER_BTU
      Number of joules in 1 BTU.
      See Also:
    • ERROR

      private static final double ERROR
      Tolerance used when comparing floating point values.
      See Also:
  • Constructor Details

    • EnergyConverterTest

      EnergyConverterTest()
  • Method Details

    • convert_whenWellKnownEquivalences_returnsExpectedValues

      @Test void convert_whenWellKnownEquivalences_returnsExpectedValues()
      Checks conversions against well-known energy equivalences.
    • jouleToKilojoule_whenRandomValue_returnsExpectedResult

      @Test void jouleToKilojoule_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and kilojoules in both directions.
    • jouleToMegajoule_whenRandomValue_returnsExpectedResult

      @Test void jouleToMegajoule_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and megajoules in both directions.
    • jouleToCalorie_whenRandomValue_returnsExpectedResult

      @Test void jouleToCalorie_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and calories in both directions.
    • jouleToKilocalorie_whenRandomValue_returnsExpectedResult

      @Test void jouleToKilocalorie_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and kilocalories in both directions.
    • jouleToKilowattHour_whenRandomValue_returnsExpectedResult

      @Test void jouleToKilowattHour_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and kilowatt-hours in both directions.
    • jouleToBtu_whenRandomValue_returnsExpectedResult

      @Test void jouleToBtu_whenRandomValue_returnsExpectedResult()
      Checks conversion between joules and BTU in both directions.
    • convert_whenDoubleAndAllUnitPairs_matchesConversionThroughJoulesAndRoundTrips

      @Test void convert_whenDoubleAndAllUnitPairs_matchesConversionThroughJoulesAndRoundTrips()
      Checks every unit pair against a conversion through joules, and that converting back recovers the original value.
    • convert_whenNumber_returnsExpectedValue

      @Test void convert_whenNumber_returnsExpectedValue()
      Checks conversion of Number values.
    • convert_whenEnergyAndResult_storesResultInProvidedInstance

      @Test void convert_whenEnergyAndResult_storesResultInProvidedInstance()
      Checks that converting an energy stores the result in the provided instance without modifying the input.
    • convert_whenEnergyAndUnit_updatesInstance

      @Test void convert_whenEnergyAndUnit_updatesInstance()
      Checks that converting an energy to a unit updates that same instance.
    • convertAndReturnNew_whenEnergy_returnsNewConvertedEnergy

      @Test void convertAndReturnNew_whenEnergy_returnsNewConvertedEnergy()
      Checks that converting and returning a new energy leaves the input unchanged.
    • convert_whenEnergyAndOutputEnergy_usesOutputUnit

      @Test void convert_whenEnergyAndOutputEnergy_usesOutputUnit()
      Checks that converting into an output energy uses the unit already set on the output.
    • convert_whenNullArguments_throwsNullPointerException

      @Test void convert_whenNullArguments_throwsNullPointerException()
      Checks that null units or a null value are rejected.
    • toJoules

      private static double toJoules(double value, EnergyUnit unit)
      Converts a value expressed in the given unit to joules.
      Parameters:
      value - value to convert.
      unit - unit of the value.
      Returns:
      value expressed in joules.
    • fromJoules

      private static double fromJoules(double joules, EnergyUnit unit)
      Converts a value expressed in joules to the given unit.
      Parameters:
      joules - value in joules.
      unit - target unit.
      Returns:
      value expressed in the target unit.