-
Notifications
You must be signed in to change notification settings - Fork 5
/
ReactivePowerCharacteristicTest.groovy
181 lines (143 loc) · 6.09 KB
/
ReactivePowerCharacteristicTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.models.system.characteristic
import edu.ie3.datamodel.exceptions.ParsingException
import edu.ie3.datamodel.models.input.system.characteristic.*
import spock.lang.Shared
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import javax.measure.quantity.Dimensionless
import static edu.ie3.util.quantities.PowerSystemUnits.PU
class ReactivePowerCharacteristicTest extends Specification {
@Shared
CosPhiFixed validCosPhiFixed
@Shared
String validCosPhiFixedDeSerialized = "cosPhiFixed:{(0.0,0.95)}"
@Shared
CosPhiP validCosPhiP
@Shared
String validCosPhiPDeSerialized = "cosPhiP:{(0.0,1.0),(0.9,1.0),(1.2,-0.3)}"
@Shared
QV validQV
@Shared
String validQVDeSerialized = "qV:{(0.9,-0.3),(0.95,0.0),(1.05,0.0),(1.1,0.3)}"
def setupSpec() {
validCosPhiFixed = new CosPhiFixed(
[
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(0d, PU), Quantities.getQuantity(0.95, PU))
] as SortedSet<CharacteristicPoint<Dimensionless, Dimensionless>>
)
validCosPhiP = new CosPhiP(
[
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(0d, PU), Quantities.getQuantity(1.0, PU)),
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(0.9, PU), Quantities.getQuantity(1.0, PU)),
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(1.2, PU), Quantities.getQuantity(-0.3, PU))
] as SortedSet<CharacteristicPoint<Dimensionless, Dimensionless>>
)
validQV = new QV(
[
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(0.9, PU), Quantities.getQuantity(-0.3, PU)),
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(0.95, PU), Quantities.getQuantity(0.0, PU)),
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(1.05, PU), Quantities.getQuantity(0.0, PU)),
new CharacteristicPoint<Dimensionless, Dimensionless>(
Quantities.getQuantity(1.1, PU), Quantities.getQuantity(0.3, PU))
] as SortedSet<CharacteristicPoint<Dimensionless, Dimensionless>>
)
}
def "A valid CosPhiFixed is correctly de-serialized"() {
when: "De-serializing a valid input"
String actual = validCosPhiFixed.Serialize()
then: "it returns the correct string"
actual == validCosPhiFixedDeSerialized
}
def "A CosPhiFixed is correctly set up from a correctly formatted string"() {
when:
CosPhiFixed actual = new CosPhiFixed(validCosPhiFixedDeSerialized)
then:
actual.points == validCosPhiFixed.points
}
def "A CosPhiFixed throws an exception if it should be set up from a malformed string"() {
when:
new CosPhiFixed("cosPhiFixed:{(10.00)}")
then:
ParsingException exception = thrown(ParsingException)
exception.message == "Cannot parse '(10.00)' to Set of points as it contains a malformed point."
}
def "A valid CosPhiP is correctly de-serialized"() {
when: "De-serializing a valid input"
String actual = validCosPhiP.Serialize()
then: "it returns the correct string"
actual == validCosPhiPDeSerialized
}
def "A CosPhiP is correctly set up from a correctly formatted string"() {
when:
CosPhiP actual = new CosPhiP(validCosPhiPDeSerialized)
then:
actual.points == validCosPhiP.points
}
def "A CosPhiP throws an exception if it should be set up from a malformed string"() {
when:
new CosPhiFixed("cosPhiP:{(0.00),(0.90),(1.20)}")
then:
ParsingException exception = thrown(ParsingException)
exception.message == "Cannot parse 'cosPhiP:{(0.00),(0.90),(1.20)}' to characteristic. It has to be of the form 'cosPhiFixed:{(%d,%d),...}'"
}
def "A valid QV is correctly de-serialized"() {
when: "De-serializing a valid input"
String actual = validQV.Serialize()
then: "it returns the correct string"
actual == validQVDeSerialized
}
def "A QV is correctly set up from a correctly formatted string"() {
when:
QV actual = new QV(validQVDeSerialized)
then:
actual.points == validQV.points
}
def "A QV throws an exception if it should be set up from a malformed string"() {
when:
new CosPhiFixed("qV:{(0.90),(0.95),(1.05),(1.10)}")
then:
ParsingException exception = thrown(ParsingException)
exception.message == "Cannot parse 'qV:{(0.90),(0.95),(1.05),(1.10)}' to characteristic. It has to be of the form 'cosPhiFixed:{(%d,%d),...}'"
}
def "The ReactivePowerCharacteristic is able to parse a fixed power factor correctly from string"() {
when:
ReactivePowerCharacteristic actual = ReactivePowerCharacteristic.parse(validCosPhiFixedDeSerialized)
then:
actual instanceof CosPhiFixed
actual.points == validCosPhiFixed.points
}
def "The ReactivePowerCharacteristic is able to parse a power dependent power factor correctly from string"() {
when:
ReactivePowerCharacteristic actual = ReactivePowerCharacteristic.parse(validCosPhiPDeSerialized)
then:
actual instanceof CosPhiP
actual.points == validCosPhiP.points
}
def "The ReactivePowerCharacteristic is able to parse voltage dependent reactive power correctly from string"() {
when:
ReactivePowerCharacteristic actual = ReactivePowerCharacteristic.parse(validQVDeSerialized)
then:
actual instanceof QV
actual.points == validQV.points
}
def "The ReactivePowerCharacteristic throws an Exception, if no valid characteristic format can be recognized"() {
when:
ReactivePowerCharacteristic.parse("nonSense:{bli,bla,blob}")
then:
ParsingException exception = thrown(ParsingException)
exception.message == "Cannot parse 'nonSense:{bli,bla,blob}' to a reactive power characteristic, as it does " +
"not meet the specifications of any of the available classes."
}
}