-
Notifications
You must be signed in to change notification settings - Fork 1
/
linestring_test.go
111 lines (84 loc) · 3.55 KB
/
linestring_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
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
package geo
import (
"fmt"
"math"
"testing"
"github.com/stretchr/testify/assert"
)
var ls = NewLineString(p, p2)
func TestLineString_Lat(t *testing.T) {
assert.Equal(t, (p.Lat()+p2.Lat())/2, ls.Lat(), "LineString Lat failed")
}
func TestLineString_Lon(t *testing.T) {
assert.Equal(t, (p.Lon()+p2.Lon())/2, ls.Lon(), "LineString Lon failed")
}
func TestLineString_Z(t *testing.T) {
assert.Equal(t, (p.Alt()+p2.Alt())/2, ls.Alt(), "LineString Alt failed")
}
func TestLineString_GeometryType(t *testing.T) {
assert.Equal(t, "LineString", ls.GeometryType(), "LineString GeometryType failed")
}
func TestLineString_SRID(t *testing.T) {
assert.Equal(t, 4326, ls.SRID(), "LineString SRID failed")
}
func TestLineString_AsText(t *testing.T) {
asText := fmt.Sprintf("LINESTRING (%f %f %f, %f %f %f)", p.Lat(), p.Lon(), p.Alt(), p2.Lat(), p2.Lon(), p2.Alt())
assert.Equal(t, asText, ls.AsText(), "LineString AsText failed")
}
func TestLineString_IsEmpty(t *testing.T) {
assert.False(t, ls.IsEmpty(), "LineString IsEmpty failed")
}
func TestLineString_Is3D(t *testing.T) {
assert.True(t, ls.Is3D(), "LineString Is3D failed")
}
func TestLineString_Equals(t *testing.T) {
assert.True(t, ls.Equals(ls), "LineString Equals failed")
assert.True(t, ls.Equals(l.LineString), "LineString Equals failed")
assert.False(t, ls.Equals(lr.LineString), "LineString Equals failed")
}
func TestLineString_Distance(t *testing.T) {
p3 := NewPoint(p.Lat()-offset, p.Lon(), 0)
p4 := NewPoint(p.Lat()-offset, p.Lon()+offset, 0)
dToP := ls.Distance(p3)
assert.Equal(t, offset, dToP, "LineString Distance (to Point) failed - expected: %f, got: %f", offset, dToP)
lineString := NewLineString(p3, p4)
dToL := l.Distance(lineString)
assert.Equal(t, offset, dToL, "LineString Distance (to LineString) failed - expected: %f, got: %f", offset, dToL)
linearRing := NewLinearRing(p3, p4)
polygon := NewPolygon(linearRing)
dToP = p.Distance(polygon)
assert.Equal(t, offset, dToP, "LineString Distance (to Polygon) failed - expected: %f, got: %f", offset, dToP)
multiPoint := NewMultiPoint(p3, p4)
dToMP := p.Distance(multiPoint)
assert.Equal(t, offset, dToMP, "LineString Distance (to MultiPoint) failed - expected: %f, got: %f", offset, dToMP)
multiLineString := NewMultiLineString(lineString)
dToMLS := p.Distance(multiLineString)
assert.Equal(t, offset, dToMLS, "LineString Distance (to MultiLineString) failed - expected: %f, got: %f", offset, dToMLS)
multiPolygon := NewMultiPolygon(polygon)
dToMPG := p.Distance(multiPolygon)
assert.Equal(t, offset, dToMPG, "LineString Distance (to MultiPolygon) failed - expected: %f, got: %f", offset, dToMPG)
}
func TestLineString_Length(t *testing.T) {
correctLength := math.Sqrt(offset * 3)
assert.Equal(t, correctLength, ls.Length(), "LineString Length failed")
ls2 := NewLineString(p, p2, p)
correctLength = correctLength * 2
assert.Equal(t, correctLength, ls2.Length(), "LineString IsClosed failed")
}
func TestLineString_StartPoint(t *testing.T) {
assert.Equal(t, p, ls.StartPoint(), "LineString StartPoint failed")
}
func TestLineString_EndPoint(t *testing.T) {
assert.Equal(t, p2, ls.EndPoint(), "LineString StartPoint failed")
}
func TestLineString_IsClosed(t *testing.T) {
assert.False(t, ls.IsClosed(), "LineString IsClosed failed")
ls2 := NewLineString(p, p2, p)
assert.True(t, ls2.IsClosed(), "LineString IsClosed failed")
}
func TestLineString_NumPoints(t *testing.T) {
assert.Equal(t, 2, ls.NumPoints(), "LineString NumPoints failed")
}
func TestLineString_PointN(t *testing.T) {
assert.Equal(t, p, ls.PointN(0), "LineString PointN failed")
}