Package com.irurueta.units
Class EnergyConverterTest
java.lang.Object
com.irurueta.units.EnergyConverterTest
Unit tests for
EnergyConverter.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doubleTolerance used when comparing floating point values.private static final doubleNumber of joules in 1 BTU.private static final doubleNumber of joules in 1 calorie.private static final doubleNumber of joules in 1 kilocalorie.private static final doubleNumber of joules in 1 kilojoule.private static final doubleNumber of joules in 1 kilowatt-hour.private static final doubleNumber of joules in 1 megajoule. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidChecks every unit pair against a conversion through joules, and that converting back recovers the original value.(package private) voidChecks that converting into an output energy uses the unit already set on the output.(package private) voidChecks that converting an energy stores the result in the provided instance without modifying the input.(package private) voidChecks that converting an energy to a unit updates that same instance.(package private) voidChecks that null units or a null value are rejected.(package private) voidChecks conversion ofNumbervalues.(package private) voidChecks conversions against well-known energy equivalences.(package private) voidChecks that converting and returning a new energy leaves the input unchanged.private static doublefromJoules(double joules, EnergyUnit unit) Converts a value expressed in joules to the given unit.(package private) voidChecks conversion between joules and BTU in both directions.(package private) voidChecks conversion between joules and calories in both directions.(package private) voidChecks conversion between joules and kilocalories in both directions.(package private) voidChecks conversion between joules and kilojoules in both directions.(package private) voidChecks conversion between joules and kilowatt-hours in both directions.(package private) voidChecks conversion between joules and megajoules in both directions.private static doubletoJoules(double value, EnergyUnit unit) Converts a value expressed in the given unit to joules.
-
Field Details
-
JOULES_PER_KILOJOULE
private static final double JOULES_PER_KILOJOULENumber of joules in 1 kilojoule.- See Also:
-
JOULES_PER_MEGAJOULE
private static final double JOULES_PER_MEGAJOULENumber of joules in 1 megajoule.- See Also:
-
JOULES_PER_CALORIE
private static final double JOULES_PER_CALORIENumber of joules in 1 calorie.- See Also:
-
JOULES_PER_KILOCALORIE
private static final double JOULES_PER_KILOCALORIENumber of joules in 1 kilocalorie.- See Also:
-
JOULES_PER_KILOWATT_HOUR
private static final double JOULES_PER_KILOWATT_HOURNumber of joules in 1 kilowatt-hour.- See Also:
-
JOULES_PER_BTU
private static final double JOULES_PER_BTUNumber of joules in 1 BTU.- See Also:
-
ERROR
private static final double ERRORTolerance 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 ofNumbervalues. -
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
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
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.
-