-
Notifications
You must be signed in to change notification settings - Fork 5
/
CosmoIdCoordinateFactoryTest.groovy
99 lines (81 loc) · 2.48 KB
/
CosmoIdCoordinateFactoryTest.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
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.io.factory.timeseries
import edu.ie3.datamodel.io.factory.SimpleFactoryData
import edu.ie3.util.geo.GeoUtils
import org.apache.commons.lang3.tuple.Pair
import org.locationtech.jts.geom.Point
import spock.lang.Shared
import spock.lang.Specification
class CosmoIdCoordinateFactoryTest extends Specification {
@Shared
CosmoIdCoordinateFactory factory
def setupSpec() {
factory = new CosmoIdCoordinateFactory()
}
def "A COSMO id to coordinate factory returns correct fields"() {
given:
def expectedFields = [
"tid",
"id",
"latrot",
"longrot",
"latgeo",
"longgeo"
] as Set
Map<String, String> parameter = [
"tid": "1",
"id": "106580",
"latgeo": "39.602772",
"longgeo": "1.279336",
"latrot": "-10",
"longrot": "-6.8125"
]
def validSimpleFactoryData = new SimpleFactoryData(parameter, Pair)
when:
def actual = factory.getFields(validSimpleFactoryData)
then:
actual.size() == 1
actual.head() == expectedFields
}
def "A COSMO id to coordinate factory refuses to build from invalid data"() {
given:
Map<String, String> parameter = [
"tid": "1",
"id": "106580",
"latrot": "-10",
"longrot": "-6.8125"
]
def invalidSimpleFactoryData = new SimpleFactoryData(parameter, Pair)
when:
def actual = factory.get(invalidSimpleFactoryData)
then:
actual.failure
actual.exception().message.startsWith("The provided fields [id, latrot, longrot, tid] with data \n{id -> 106580,\nlatrot" +
" -> -10,\nlongrot -> -6.8125,\ntid -> 1} are invalid for instance of Pair.")
}
def "A COSMO id to coordinate factory builds model from valid data"() {
given:
Map<String, String> parameter = [
"tid": "1",
"id": "106580",
"latgeo": "39.602772",
"longgeo": "1.279336",
"latrot": "-10",
"longrot": "-6.8125"
]
def validSimpleFactoryData = new SimpleFactoryData(parameter, Pair)
Pair<Integer, Point> expectedPair = Pair.of(106580, GeoUtils.buildPoint(39.602772, 1.279336))
when:
def actual = factory.get(validSimpleFactoryData)
then:
actual.success
actual.data().with {
assert it.key == expectedPair.key
assert it.value.equalsExact(expectedPair.value, 1E-6)
}
}
}