Skip to content

Commit c44b047

Browse files
committed
Implementing requested changes.
1 parent 7589f8a commit c44b047

File tree

2 files changed

+89
-35
lines changed

2 files changed

+89
-35
lines changed

src/test/groovy/edu/ie3/datamodel/io/source/csv/CsvSystemParticipantSourceTest.groovy

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
156156
heatPumps.exception.get().class == SourceException
157157

158158
where:
159-
operators | types | thermalBuses || resultingSize | resultingSet
160-
[] | [] | [] || 0 | []
161-
[] | [] | [] || 0 | []
162-
[sptd.hpInput.operator] | [] | [] || 0 | []
163-
[sptd.hpInput.operator] | [sptd.hpInput.type] | [] || 0 | []
159+
operators | types | thermalBuses
160+
[] | [] | []
161+
[sptd.hpInput.operator] | [] | []
162+
[sptd.hpInput.operator] | [sptd.hpInput.type] | []
164163
}
165164

166165
def "A SystemParticipantSource with csv input should throw an exception from a invalid chp input file as expected"() {
@@ -181,11 +180,11 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
181180
chpUnits.exception.get().class == SourceException
182181

183182
where:
184-
operators | types | thermalBuses | thermalStorages || resultingSet
185-
[] | [] | [] | [] as List || []
186-
[] | [] | [] | [] as List || []
187-
[sptd.chpInput.operator] | [] | [] | [] as List || []
188-
[sptd.chpInput.operator] | [sptd.chpInput.type] | [] | [] as List || []
183+
operators | types | thermalBuses | thermalStorages
184+
[] | [] | [] | [] as List
185+
[] | [] | [] | [] as List
186+
[sptd.chpInput.operator] | [] | [] | [] as List
187+
[sptd.chpInput.operator] | [sptd.chpInput.type] | [] | [] as List
189188
}
190189

191190
def "A SystemParticipantSource with csv input should throw an exception from invalid ev input file as expected"() {
@@ -206,9 +205,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
206205
sysParts.exception.get().class == SourceException
207206

208207
where:
209-
operators | types || resultingSet
210-
[sptd.evInput.operator] | [] || []
211-
[] | [] || []
208+
operators | types
209+
[sptd.evInput.operator] | []
210+
[] | []
212211
}
213212

214213
def "A SystemParticipantSource with csv input should throw an exception from invalid wec input file as expected"() {
@@ -229,9 +228,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
229228
sysParts.exception.get().class == SourceException
230229

231230
where:
232-
operators | types || resultingSet
233-
[sptd.wecInput.operator] | [] || []
234-
[] | [] || []
231+
operators | types
232+
[sptd.wecInput.operator] | []
233+
[] | []
235234
}
236235

237236
def "A SystemParticipantSource with csv input should throw an exception from invalid storage input file as expected"() {
@@ -252,9 +251,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
252251
sysParts.exception.get().class == SourceException
253252

254253
where:
255-
operators | types || resultingSet
256-
[sptd.storageInput.operator] | [] || []
257-
[] | [] || []
254+
operators | types
255+
[sptd.storageInput.operator] | []
256+
[] | []
258257
}
259258

260259
def "A SystemParticipantSource with csv input should throw an exception from invalid bm input file as expected"() {
@@ -275,10 +274,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
275274
sysParts.exception.get().class == SourceException
276275

277276
where:
278-
operators | types || resultingSet
279-
[sptd.bmInput.operator] | [] || []
280-
[] | [] || []
281-
[] | [] || []
277+
operators | types
278+
[sptd.bmInput.operator] | []
279+
[] | []
282280
}
283281

284282
def "A SystemParticipantSource with csv input should throw an exception from invalid ev charging station input file as expected"() {
@@ -298,9 +296,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
298296
sysParts.exception.get().class == SourceException
299297

300298
where:
301-
nodes | operators || resultingSet
302-
[] | [sptd.evcsInput.operator] || []
303-
[] | [] || []
299+
nodes | operators
300+
[] | [sptd.evcsInput.operator]
301+
[] | []
304302
}
305303

306304
def "A SystemParticipantSource with csv input should throw an exception from invalid load input file as expected"() {
@@ -320,9 +318,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
320318
sysParts.exception.get().class == SourceException
321319

322320
where:
323-
nodes | operators || resultingSet
324-
[] | [sptd.loadInput.operator] || []
325-
[] | [] || []
321+
nodes | operators
322+
[] | [sptd.loadInput.operator]
323+
[] | []
326324
}
327325

328326
def "A SystemParticipantSource with csv input should throw an exception from invalid pv input file as expected"() {
@@ -342,9 +340,9 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
342340
sysParts.exception.get().class == SourceException
343341

344342
where:
345-
nodes | operators || resultingSet
346-
[] | [sptd.pvInput.operator] || []
347-
[] | [] || []
343+
nodes | operators
344+
[] | [sptd.pvInput.operator]
345+
[] | []
348346
}
349347

350348
def "A SystemParticipantSource with csv input should throw an exception from invalid fixedFeedIn input file as expected"() {
@@ -364,8 +362,8 @@ class CsvSystemParticipantSourceTest extends Specification implements CsvTestDat
364362
sysParts.exception.get().class == SourceException
365363

366364
where:
367-
nodes | operators || resultingSet
368-
[] | [sptd.fixedFeedInInput.operator] || []
369-
[] | [] || []
365+
nodes | operators
366+
[] | [sptd.fixedFeedInInput.operator]
367+
[] | []
370368
}
371369
}

src/test/groovy/edu/ie3/datamodel/utils/TryTest.groovy

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ package edu.ie3.datamodel.utils
88
import edu.ie3.datamodel.exceptions.FailureException
99
import edu.ie3.datamodel.exceptions.SourceException
1010
import edu.ie3.datamodel.exceptions.TryException
11+
import org.apache.commons.lang3.tuple.Pair
1112
import spock.lang.Specification
1213

14+
import java.util.function.Function
1315
import java.util.stream.Stream
1416

1517
class TryTest extends Specification {
@@ -343,6 +345,60 @@ class TryTest extends Specification {
343345
flatMapF.exception.get() == failure.get()
344346
}
345347

348+
def "Two Tries can be zipped correctly"() {
349+
given:
350+
def given = Try.of(() -> 1, SourceException)
351+
352+
when:
353+
def actual = given.zip(second)
354+
355+
then:
356+
actual.isSuccess() == isSuccess
357+
actual.data == expectedData
358+
359+
where:
360+
second | isSuccess | expectedData
361+
new Try.Failure(new SourceException("source exception")) | false | Optional.empty()
362+
new Try.Success("1") | true | Optional.of(Pair.of(1, "1"))
363+
}
364+
365+
def "Two Tries can be zipped to any object correctly"() {
366+
given:
367+
def given = Try.of(() -> 1, SourceException)
368+
def fcn = (i1, i2) -> i1 + i2
369+
370+
when:
371+
def actual = given.zip(second, fcn)
372+
373+
then:
374+
actual.isSuccess() == isSuccess
375+
actual.data == expectedData
376+
377+
where:
378+
second | isSuccess | expectedData
379+
new Try.Failure(new SourceException("source exception")) | false | Optional.empty()
380+
new Try.Success(10) | true | Optional.of(11)
381+
}
382+
383+
def "Two Tries can be extracted and zipped correctly"() {
384+
given:
385+
def given = Try.of(() -> 1, SourceException)
386+
387+
def failureExtractor = f -> new Try.Failure(new SourceException("source exception"))
388+
def successExtractor = s -> new Try.Success("10")
389+
390+
when:
391+
def failure = given.zip(failureExtractor)
392+
def success = given.zip(successExtractor)
393+
394+
then:
395+
failure.isFailure()
396+
397+
success.isSuccess()
398+
success.data == Optional.of(Pair.of(1, "10"))
399+
}
400+
401+
346402
def "The convert method should work correctly for successes"() {
347403
given:
348404
Try<Stream<Integer>, SourceException> success = new Try.Success(Stream.of(1, 2, 3))

0 commit comments

Comments
 (0)