-
Notifications
You must be signed in to change notification settings - Fork 5
/
CsvIdCoordinateSourceIconIT.groovy
230 lines (178 loc) · 7.11 KB
/
CsvIdCoordinateSourceIconIT.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
* © 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.source.csv
import edu.ie3.datamodel.io.factory.timeseries.IconIdCoordinateFactory
import edu.ie3.util.geo.CoordinateDistance
import edu.ie3.util.geo.GeoUtils
import spock.lang.Shared
import spock.lang.Specification
import tech.units.indriya.quantity.Quantities
import tech.units.indriya.unit.Units
import java.util.stream.Collectors
import java.util.stream.Stream
class CsvIdCoordinateSourceIconIT extends Specification implements CsvTestDataMeta {
@Shared
CsvIdCoordinateSource source
def setupSpec() {
source = new CsvIdCoordinateSource(new IconIdCoordinateFactory(), new CsvDataSource(csvSep, coordinatesIconFolderPath, fileNamingStrategy))
}
def "The CsvCoordinateSource is able to create a valid stream from a coordinate file"() {
def expectedStream = Stream.of(
["id": "67775", "latitude": "51.5", "longitude": "7.438", "coordinatetype": "ICON"],
["id": "531137", "latitude": "51.5", "longitude": "7.375", "coordinatetype": "ICON"],
["id": "551525", "latitude": "51.438", "longitude": "7.438", "coordinatetype": "ICON"],
["id": "278150", "latitude": "51.438", "longitude": "7.375", "coordinatetype": "ICON"]
)
when:
def actualStream = source.buildStreamWithFieldsToAttributesMap()
then:
actualStream.success
actualStream.data.get().collect(Collectors.toList()).containsAll(expectedStream.collect(Collectors.toList()))
}
def "The CsvIdCoordinateSource is able to look up a specific point or an empty Optional otherwise" () {
given:
def knownCoordinateId = 551525
def expectedPointA = Optional.of(GeoUtils.buildPoint(51.438, 7.438))
def unknownCoordinateId = 42
when: "looking up a known coordinate id"
def actualPointA = source.getCoordinate(knownCoordinateId)
then: "we get the expected point"
actualPointA == expectedPointA
when: "looking up an unknown coordinate id"
def actualPointB = source.getCoordinate(unknownCoordinateId)
then: "we get an empty optional"
actualPointB == Optional.empty()
}
def "The CsvIdCoordinateSource is able to look up specified points" () {
int[] ids = [67775, 551525, 278150]
def expectedCoordinates = [
GeoUtils.buildPoint(51.5, 7.438),
GeoUtils.buildPoint(51.438, 7.438),
GeoUtils.buildPoint(51.438, 7.375)
].toSet()
when:
def actualCoordinates = source.getCoordinates(ids)
then:
actualCoordinates == expectedCoordinates
}
def "The CsvIdCoordinateSource is able to return a specific ID or an empty Optional otherwise" () {
def knownCoordinate = GeoUtils.buildPoint(51.438, 7.438)
def expectedIdForA = Optional.of(551525)
def unknownCoordinate = GeoUtils.buildPoint(48.035011, 14.39335)
when: "looking up an id of a known coordinate"
def actualIdForA = source.getId(knownCoordinate)
then: "we get the matching id"
actualIdForA == expectedIdForA
when: "looking up an unknown coordinate"
def actualIdForB = source.getId(unknownCoordinate)
then: "we get nothing"
actualIdForB == Optional.empty()
}
def "The CsvIdCoordinateSource is able to return a count of all available coordinates" () {
given:
def expectedCount = 4
when:
def actualCount = source.coordinateCount
then:
actualCount == expectedCount
}
def "The CsvIdCoordinateSource is able to return all available coordinates" () {
given:
def expectedCoordinates = [
GeoUtils.buildPoint(51.5, 7.438),
GeoUtils.buildPoint(51.5, 7.375),
GeoUtils.buildPoint(51.438, 7.438),
GeoUtils.buildPoint(51.438, 7.375)
].toSet()
when:
def actualCoordinates = source.allCoordinates.toSet()
then:
actualCoordinates == expectedCoordinates
}
def "The CsvIdCoordinateSource is able to return the nearest n coordinates in a collection" () {
given:
def allCoordinates = [
GeoUtils.buildPoint(39d, 1d),
GeoUtils.buildPoint(40d, 2d),
GeoUtils.buildPoint(40d, 1d),
GeoUtils.buildPoint(39d, 2d)
]
def basePoint = GeoUtils.buildPoint(39.617162, 1.438029)
def expectedDistances = [
new CoordinateDistance(basePoint, allCoordinates[2]),
new CoordinateDistance(basePoint, allCoordinates[1])
].sort()
when:
def actualDistances = source.calculateCoordinateDistances(basePoint, 2, allCoordinates)
then:
actualDistances == expectedDistances
}
def "The CsvIdCoordinateSource will return the nearest n coordinates" () {
given:
def n = 5
def basePoint = GeoUtils.buildPoint(39.617162, 1.438029)
def expectedDistances = source.calculateCoordinateDistances(basePoint, n, source.allCoordinates)
when:
def actualDistances = source.getNearestCoordinates(basePoint, n)
then:
actualDistances == expectedDistances
}
def "The CsvIdCoordinateSource will return no coordinates if no coordinates are in the given radius" () {
given:
def n = 5
def basePoint = GeoUtils.buildPoint(39.617162, 1.438029)
def distance = Quantities.getQuantity(10000, Units.METRE)
when:
def actualDistances = source.getClosestCoordinates(basePoint, n, distance)
then:
actualDistances.empty
}
def "The CsvIdCoordinateSource will return the nearest n coordinates if n coordinates are in the search radius"() {
given:
def basePoint = GeoUtils.buildPoint(51.5, 7.38)
def distance = Quantities.getQuantity(10000, Units.METRE)
when:
def actualDistances = source.getClosestCoordinates(basePoint, 3, distance)
then:
actualDistances.size() == 3
}
def "The CsvIdCoordinateSource will return the nearest m coordinates if less than n coordinates are in the given radius"() {
given:
def basePoint = GeoUtils.buildPoint(51.5, 7.38)
def distance = Quantities.getQuantity(1000, Units.METRE)
when:
def actualDistances = source.getClosestCoordinates(basePoint, 3, distance)
then:
actualDistances.size() == 1
}
def "The CsvCoordinateSource will return the four corner points if enough points are within the given distance"() {
given:
def basePoint = GeoUtils.buildPoint(51.45, 7.4)
def distance = Quantities.getQuantity(10000, Units.METRE)
when:
def actualDistances = source.findCornerPoints(basePoint, distance)
then:
actualDistances.size() == 4
}
def "The CsvCoordinateSource will return less than four corner points if not enough points are within the given distance"() {
given:
def basePoint = GeoUtils.buildPoint(51.45, 7.38)
def distance = Quantities.getQuantity(5000, Units.METRE)
when:
def actualDistances = source.findCornerPoints(basePoint, distance)
then:
actualDistances.size() == 2
}
def "The CsvCoordinateSource will return one point if there is an exact match"() {
given:
def basePoint = GeoUtils.buildPoint(51.5, 7.438)
def distance = Quantities.getQuantity(100, Units.METRE)
when:
def actualDistances = source.findCornerPoints(basePoint, distance)
then:
actualDistances.size() == 1
}
}