Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/main/scala/edu/ie3/util/quantities/QuantityUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import javax.measure.quantity.{
Energy,
Length,
Power,
Time
Temperature,
Time,
Volume
}
import scala.math.BigDecimal.RoundingMode
import scala.math.BigDecimal.RoundingMode.RoundingMode
Expand Down Expand Up @@ -211,19 +213,35 @@ object QuantityUtils {
def asMicroFarradPerKilometre: ComparableQuantity[SpecificCapacitance] =
as(MICROFARAD_PER_KILOMETRE)

def asKiloWattHourPerKelvin: ComparableQuantity[HeatCapacity] =
as(KILOWATTHOUR_PER_KELVIN)

def asKiloWattHourPerKelvinTimesCubicMetre
: ComparableQuantity[SpecificHeatCapacity] =
as(KILOWATTHOUR_PER_KELVIN_TIMES_CUBICMETRE)

/* ==== Thermal Conductance ==== */
/* ==== Thermal ==== */

def asDegreeKelvin: ComparableQuantity[Temperature] = as(
KELVIN
)

def asDegreeCelsius: ComparableQuantity[Temperature] = as(
CELSIUS
)

def asKiloWattPerKelvin: ComparableQuantity[ThermalConductance] = as(
KILOWATT_PER_KELVIN
)

def asKiloWattHourPerKelvin: ComparableQuantity[HeatCapacity] =
as(KILOWATTHOUR_PER_KELVIN)

/* ==== Volume ==== */

def asCubicMetre: ComparableQuantity[Volume] =
as(CUBIC_METRE)

def asLitre: ComparableQuantity[Volume] =
as(LITRE)

/** Create a quantity from the double with given unit
* @param unit
* the unit to create the quantity with
Expand Down
36 changes: 36 additions & 0 deletions src/test/scala/edu/ie3/util/quantities/QuantityUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,42 @@ class QuantityUtilsSpec
)
}

"convert a double to a degree kelvin quantity" in {
value.asDegreeKelvin should equalWithTolerance(
Quantities.getQuantity(
value,
KELVIN
)
)
}

"convert a double to a degree celsius quantity" in {
value.asDegreeCelsius should equalWithTolerance(
Quantities.getQuantity(
value,
CELSIUS
)
)
}

"convert a double to a cubic metre quantity" in {
value.asCubicMetre should equalWithTolerance(
Quantities.getQuantity(
value,
CUBIC_METRE
)
)
}

"convert a double to a litre quantity" in {
value.asLitre should equalWithTolerance(
Quantities.getQuantity(
value,
LITRE
)
)
}

/* ==== Thermal Conductance ==== */

"convert a double to a kilowatt per kelvin quantity" in {
Expand Down