-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_test.go
84 lines (80 loc) · 2.12 KB
/
convert_test.go
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
package main
import (
"testing"
"github.com/go-spatial/geom"
"github.com/go-spatial/geom/cmp"
)
func TestToTegolaToGeom(t *testing.T) {
type tcase struct {
geom geom.Geometry
err error
}
fn := func(t *testing.T, tc tcase) {
t.Parallel()
gott, err := ToTegola(tc.geom)
if tc.err == nil && err != nil {
t.Errorf("Unexpected error, expected nil got %v", err)
return
}
if tc.err != nil && err == nil {
t.Errorf("Unexpected error, expected %v got nil", tc.err)
return
}
if tc.err != nil && err != nil && tc.err != err {
t.Errorf("Unexpected error, expected %v got %v", tc.err, err)
return
}
if tc.err != nil {
return
}
t.Logf("Tegola geometry %v", gott)
got, err := ToGeom(gott)
if tc.err == nil && err != nil {
t.Logf("Tegola geometry %#v", gott)
t.Errorf("Unexpected error, expected nil got %v", err)
return
}
if !cmp.GeometryEqual(tc.geom, got) {
t.Errorf("unequal geometry, expected %v got %v", tc.geom, got)
}
}
tests := map[string]tcase{
"Point Empty": {geom: geom.Point{}},
"MultiPoint Empty": {geom: geom.MultiPoint{}},
"LineString Empty": {geom: geom.LineString{}},
"MultiLineString Empty": {geom: geom.MultiLineString{}},
"Polygon Empty": {geom: geom.Polygon{}},
"MultiPolygon Empty": {geom: geom.MultiPolygon{}},
"Point": {geom: geom.Point{10, 10}},
"MultiPoint": {geom: geom.MultiPoint{{10, 10}, {90, 90}, {20, 30}}},
"LineString": {geom: geom.LineString{{10, 10}, {90, 90}, {20, 30}}},
"MultiLineString": {
geom: geom.MultiLineString{
{{10, 10}, {90, 90}, {20, 30}},
{{10, 15}, {95, 90}, {25, 30}},
},
},
"Polygon": {
geom: geom.Polygon{
{{10, 10}, {90, 90}, {20, 30}},
{{10, 15}, {95, 90}, {25, 30}},
},
},
"MultiPolygon": {
geom: geom.MultiPolygon{
{
{{10, 10}, {90, 90}, {20, 30}},
{{10, 15}, {95, 90}, {25, 30}},
},
},
},
/*
// Collection support is broken. :(
"Collection Empty": tcase{geom: geom.Collection{}},
*/
}
for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) { fn(t, tc) })
}
}