-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0028b6
commit 17b1223
Showing
6 changed files
with
348 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/scala/edu/ie3/simbench/convert/profiles/PvProfileConverterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package edu.ie3.simbench.convert.profiles | ||
|
||
import edu.ie3.datamodel.models.timeseries.individual.{ | ||
IndividualTimeSeries, | ||
TimeBasedValue | ||
} | ||
import edu.ie3.datamodel.models.value.PValue | ||
import edu.ie3.simbench.model.datamodel.profiles.ResProfileType | ||
import edu.ie3.test.common.UnitSpec | ||
import edu.ie3.util.quantities.QuantityUtils._ | ||
import org.scalatest.prop.TableDrivenPropertyChecks | ||
|
||
import java.time.ZonedDateTime | ||
import scala.jdk.CollectionConverters._ | ||
import scala.jdk.OptionConverters.RichOptional | ||
|
||
class PvProfileConverterSpec extends UnitSpec with TableDrivenPropertyChecks { | ||
|
||
"The pv profile converter" should { | ||
|
||
"calculate the power before the converter correctly" in { | ||
val time = ZonedDateTime.now() | ||
|
||
val timeSeries = new IndividualTimeSeries( | ||
Set( | ||
new TimeBasedValue(time, new PValue((-1).asKiloWatt)), | ||
new TimeBasedValue(time.plusHours(1), new PValue((-3).asKiloWatt)), | ||
new TimeBasedValue(time.plusHours(2), new PValue((-2).asKiloWatt)) | ||
).asJava | ||
) | ||
|
||
val efficiency = 97.asPercent | ||
val kG: Double = 0.8999999761581421 | ||
val kT: Double = 1.0 | ||
|
||
val result = PvProfileConverter.calculatePowerBeforeConverter( | ||
timeSeries, | ||
efficiency, | ||
kG, | ||
kT | ||
) | ||
|
||
val entries = result.getEntries.asScala.toList.map(value => | ||
value.getValue.getP.toScala | ||
.getOrElse(fail("This test should not fail!")) | ||
) | ||
|
||
entries(0).getValue.doubleValue() shouldBe -1.1454754026242313 | ||
entries(1).getValue.doubleValue() shouldBe -3.436426207872694 | ||
entries(2).getValue.doubleValue() shouldBe -2.2909508052484626 | ||
} | ||
|
||
"return the correct azimuth for a given pv profile type" in { | ||
val cases = Table( | ||
("profileType", "expectedAzimuth"), | ||
(ResProfileType.PV1, (-90).asDegreeGeom), | ||
(ResProfileType.PV2, (-90).asDegreeGeom), | ||
(ResProfileType.PV3, 0.asDegreeGeom), | ||
(ResProfileType.PV4, 0.asDegreeGeom), | ||
(ResProfileType.PV5, 0.asDegreeGeom), | ||
(ResProfileType.PV6, 0.asDegreeGeom), | ||
(ResProfileType.PV7, 90.asDegreeGeom), | ||
(ResProfileType.PV8, 90.asDegreeGeom) | ||
) | ||
|
||
forAll(cases) { (profileType, expectedAzimuth) => | ||
PvProfileConverter.getAzimuth(profileType) shouldBe expectedAzimuth | ||
} | ||
} | ||
|
||
"calculate the elevation angle correctly" in { | ||
val result = PvProfileConverter.calculateElevationAngle( | ||
None, | ||
5.asKiloVoltAmpere, | ||
ResProfileType.PV3, | ||
0.asDegreeGeom | ||
) | ||
|
||
result shouldBe 0.652171369646312.asDegreeGeom | ||
} | ||
|
||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/test/scala/edu/ie3/simbench/convert/profiles/ResProfileConverterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package edu.ie3.simbench.convert.profiles | ||
|
||
import edu.ie3.datamodel.models.timeseries.individual.{ | ||
IndividualTimeSeries, | ||
TimeBasedValue | ||
} | ||
import edu.ie3.datamodel.models.value.PValue | ||
import edu.ie3.simbench.convert.profiles.ResProfileConverter.{ | ||
CompassDirection, | ||
findMaxFeedIn, | ||
hanoverCoordinate, | ||
luebeckCoordinate | ||
} | ||
import edu.ie3.simbench.model.datamodel.profiles.ResProfileType | ||
import edu.ie3.test.common.UnitSpec | ||
import edu.ie3.util.quantities.QuantityUtils._ | ||
import org.scalatest.prop.TableDrivenPropertyChecks | ||
|
||
import java.time.ZonedDateTime | ||
import scala.jdk.CollectionConverters._ | ||
import scala.util.{Failure, Success, Try} | ||
|
||
class ResProfileConverterSpec extends UnitSpec with TableDrivenPropertyChecks { | ||
|
||
"The res profile converter" should { | ||
"find the maximum feed in of a time series" in { | ||
val time = ZonedDateTime.now() | ||
|
||
val value0 = new TimeBasedValue(time, new PValue(1.asKiloWatt)) | ||
val value1 = | ||
new TimeBasedValue(time.plusHours(1), new PValue((-1).asKiloWatt)) | ||
val value2 = new TimeBasedValue(time.plusHours(2), new PValue(null)) | ||
val value3 = | ||
new TimeBasedValue(time.plusHours(3), new PValue((-3).asKiloWatt)) | ||
val value4 = | ||
new TimeBasedValue(time.plusHours(4), new PValue((-2).asKiloWatt)) | ||
|
||
val cases = Table( | ||
("timeSeries", "expectedValue"), | ||
(new IndividualTimeSeries(Set(value0).asJava), None), | ||
(new IndividualTimeSeries(Set(value0, value2).asJava), None), | ||
( | ||
new IndividualTimeSeries(Set(value0, value1, value2).asJava), | ||
Some(value1) | ||
), | ||
( | ||
new IndividualTimeSeries(Set(value1, value2, value4).asJava), | ||
Some(value4) | ||
), | ||
( | ||
new IndividualTimeSeries(Set(value1, value2, value3, value4).asJava), | ||
Some(value3) | ||
) | ||
) | ||
|
||
forAll(cases) { (timeSeries, expectedValue) => | ||
val maxFeedIn = findMaxFeedIn(timeSeries) | ||
maxFeedIn shouldBe expectedValue | ||
} | ||
|
||
} | ||
|
||
"return the correct coordinate" in { | ||
val cases = Table( | ||
("profileType", "expectedCoordinate"), | ||
(ResProfileType.PV1, hanoverCoordinate), | ||
(ResProfileType.PV2, luebeckCoordinate), | ||
(ResProfileType.PV3, hanoverCoordinate), | ||
(ResProfileType.PV4, hanoverCoordinate), | ||
(ResProfileType.PV5, luebeckCoordinate), | ||
(ResProfileType.PV6, luebeckCoordinate), | ||
(ResProfileType.PV7, hanoverCoordinate), | ||
(ResProfileType.PV8, hanoverCoordinate) | ||
) | ||
|
||
forAll(cases) { (profileType, expectedCoordinate) => | ||
ResProfileConverter.getCoordinate( | ||
profileType | ||
) shouldBe expectedCoordinate | ||
} | ||
} | ||
|
||
"throw an exception if unknown profile type is given for coordinate" in { | ||
Try(ResProfileConverter.getCoordinate(ResProfileType.WP1)) match { | ||
case Success(_) => fail("This test should not pass!") | ||
case Failure(exception) => | ||
exception.getMessage shouldBe s"There is no coordinate for the profile type WP1." | ||
} | ||
} | ||
|
||
"return the correct compass direction" in { | ||
val cases = Table( | ||
("profileType", "expectedDirection"), | ||
(ResProfileType.PV1, CompassDirection.East), | ||
(ResProfileType.PV2, CompassDirection.East), | ||
(ResProfileType.PV3, CompassDirection.South), | ||
(ResProfileType.PV4, CompassDirection.South), | ||
(ResProfileType.PV5, CompassDirection.South), | ||
(ResProfileType.PV6, CompassDirection.South), | ||
(ResProfileType.PV7, CompassDirection.West), | ||
(ResProfileType.PV8, CompassDirection.West) | ||
) | ||
|
||
forAll(cases) { (profileType, expectedDirection) => | ||
ResProfileConverter.getCompassDirection( | ||
profileType | ||
) shouldBe expectedDirection | ||
} | ||
} | ||
|
||
"throw an exception if unknown profile type is given for compass direction" in { | ||
Try(ResProfileConverter.getCompassDirection(ResProfileType.WP1)) match { | ||
case Success(_) => fail("This test should not pass!") | ||
case Failure(exception) => | ||
exception.getMessage shouldBe s"There is no compass direction for the profile type WP1." | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.