Skip to content

Commit

Permalink
Adapting tests to squants
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Jun 16, 2023
1 parent 394002c commit 206e339
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class HpModelTest extends Specification {
def nextInnerTemperature = hpModel.calculateNextState(hpData).innerTemperature()

then:
Math.abs((nextInnerTemperature.toCelsiusScale() - expectedNewInnerTemperature)) < 0.0001
Math.abs((nextInnerTemperature.toCelsiusScale().doubleValue() - expectedNewInnerTemperature.doubleValue())) < 0.0001

where:
hpState || expectedNewInnerTemperature // (isRunning, tooHigh, tooLow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils
import edu.ie3.util.TimeUtil
import edu.ie3.util.scala.quantities.Sq
import scala.Option
import scala.Some
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
import squants.Each$
import squants.energy.Kilowatts$
import squants.motion.MetersPerSecond$
import squants.motion.Pascals$
import squants.motion.Pressure
import squants.space.SquareMeters$
import squants.thermal.Celsius$

import static edu.ie3.datamodel.models.StandardUnits.*
Expand Down Expand Up @@ -99,9 +103,9 @@ class WecModelTest extends Specification {
wecModel.uuid() == inputModel.getUuid()
wecModel.id() == inputModel.getId()
wecModel.scalingFactor() == 1
wecModel.sRated() == Kilowatts(inputModel.getType.getsRated.to(KILOWATT).getValue.doubleValue)
wecModel.sRated() == Sq.create((inputModel.getType().getsRated().value.doubleValue()), Kilowatts$.MODULE$)
wecModel.cosPhiRated() == inputModel.getType().getCosPhiRated()
wecModel.rotorArea() == SquareMeters(inputModel.getType.getRotorArea.to(SQUARE_METRE).getValue.doubleValue)
wecModel.rotorArea() == Sq.create((inputModel.getType().getRotorArea().value.doubleValue()), SquareMeters$.MODULE$)
wecModel.betzCurve() == new WecModel.WecCharacteristic$().apply(inputModel.getType().getCpCharacteristic())
}

Expand All @@ -112,7 +116,7 @@ class WecModelTest extends Specification {
def wecData = new WecRelevantData(
Sq.create(velocity, MetersPerSecond$.MODULE$),
Sq.create(20, Celsius$.MODULE$),
Sq.create(101325, Pascals$.MODULE$))
new Some (Sq.create(101325d, Pascals$.MODULE$)))

when:
def result = wecModel.calculateActivePower(wecData)
Expand All @@ -122,18 +126,18 @@ class WecModelTest extends Specification {

where:
velocity || power
1.0 || 0
2.0 || -2948.80958
3.0 || -24573.41320
7.0 || -522922.23257
9.0 || -1140000
13.0 || -1140000
15.0 || -1140000
19.0 || -1140000
23.0 || -1140000
27.0 || -1140000
34.0 || -24573.39638
40.0 || 0
1.0d || 0
2.0d || -2948.80958
3.0d || -24573.41320
7.0d || -522922.23257
9.0d || -1140000
13.0d || -1140000
15.0d || -1140000
19.0d || -1140000
23.0d || -1140000
27.0d || -1140000
34.0d || -24573.39638
40.0d || 0
}

@Unroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class ThermalHouseTest extends Specification {

def "Calculation of thermal energy change and new inner temperature is performed correctly"() {
given:
def thermalHouse = buildThermalHouse(18, 22)
def innerTemperature = Sq.create(20, Celsius$.MODULE$)
def thermalHouse = buildThermalHouse(18d, 22d)
def innerTemperature = Sq.create(20d, Celsius$.MODULE$)

when:
def thermalEnergyGain = thermalHouse.calcThermalEnergyGain(Sq.create(100, Kilowatts$.MODULE$), Sq.create(3600, Seconds$.MODULE$))
Expand All @@ -77,20 +77,20 @@ class ThermalHouseTest extends Specification {
def newInnerTemperature = thermalHouse.calcNewInnerTemperature(innerTemperature, innerTemperatureChange)

then:
Math.abs(100d - thermalEnergyGain.toKilowattHours()) < TOLERANCE
Math.abs(10d - thermalEnergyLoss.toKilowattHours()) < TOLERANCE
Math.abs(90d - thermalEnergyChange.toKilowattHours()) < TOLERANCE
Math.abs(9d - innerTemperatureChange.toKelvinScale()) < TOLERANCE
Math.abs(29d - newInnerTemperature.toCelsiusScale()) < TOLERANCE
Sq.create(100d, KilowattHours$.MODULE$) - thermalEnergyGain < Sq.create(TOLERANCE, KilowattHours$.MODULE$)
Sq.create(10d, KilowattHours$.MODULE$) - thermalEnergyLoss < Sq.create(TOLERANCE, KilowattHours$.MODULE$)
Sq.create(90d, KilowattHours$.MODULE$) - thermalEnergyChange < Sq.create(TOLERANCE, KilowattHours$.MODULE$)
Sq.create(9d, Kelvin$.MODULE$) - innerTemperatureChange < Sq.create(TOLERANCE, Kelvin$.MODULE$)
Sq.create(29d, Celsius$.MODULE$) - newInnerTemperature < Sq.create(TOLERANCE,Celsius$.MODULE$)
}

def "Comprising function to calculate new inner temperature works as expected"() {
given:
def thermalHouse = buildThermalHouse(18, 22)
def thermalPower = Sq.create(100, Kilowatts$.MODULE$)
def duration = Sq.create(3600, Seconds$.MODULE$)
def currentInnerTemperature = Sq.create(20, Celsius$.MODULE$)
def ambientTemperature = Sq.create(10, Celsius$.MODULE$)
def thermalHouse = buildThermalHouse(18d, 22d)
def thermalPower = Sq.create(100d, Kilowatts$.MODULE$)
def duration = Sq.create(3600d, Seconds$.MODULE$)
def currentInnerTemperature = Sq.create(20d, Celsius$.MODULE$)
def ambientTemperature = Sq.create(10d, Celsius$.MODULE$)

when:
def newInnerTemperature = thermalHouse.newInnerTemperature(thermalPower, duration, currentInnerTemperature, ambientTemperature)
Expand All @@ -105,11 +105,11 @@ class ThermalHouseTest extends Specification {
UUID.randomUUID(),
"Thermal House",
null,
getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION),
getQuantity(10.0, StandardUnits.HEAT_CAPACITY),
getQuantity(0, CELSIUS), // stub
getQuantity(18, CELSIUS),
getQuantity(22, CELSIUS)
Sq.create(1.0d, StandardUnits.THERMAL_TRANSMISSION),
Sq.create(10.0d, StandardUnits.HEAT_CAPACITY),
Sq.create(0d, Celsius$.MODULE$), // stub
Sq.create(18d, Celsius$.MODULE$),
Sq.create(22d, Celsius$.MODULE$)
)

when:
Expand Down

0 comments on commit 206e339

Please sign in to comment.