-
Notifications
You must be signed in to change notification settings - Fork 1
/
tiles_test.go
83 lines (70 loc) · 2.11 KB
/
tiles_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
package cluster_test
import (
"fmt"
"testing"
cluster "github.com/aliakseiz/gocluster"
"github.com/stretchr/testify/assert"
)
func TestCluster_GetTile00(t *testing.T) {
points := importData("./testdata/places.json")
assert.NotEmptyf(t, points, "no points for clustering")
geoPoints := make([]cluster.GeoPoint, len(points))
for i := range points {
geoPoints[i] = points[i]
}
c, _ := cluster.New(geoPoints,
cluster.WithinZoom(0, 3),
cluster.WithPointSize(60),
cluster.WithTileSize(256),
cluster.WithNodeSize(64))
result := c.GetTile(0, 0, 0)
assert.NotEmpty(t, result)
expectedPoints := importPoints("./testdata/expect_tile0_0_0.json")
// Included field value is tested separately
for i := range result {
result[i].Included = nil
}
assert.Equal(t, expectedPoints, result)
}
// validate original result from JS library.
func TestCluster_GetTileDefault(t *testing.T) {
points := importData("./testdata/places.json")
if len(points) == 0 {
t.Error("Getting empty test data")
} else {
t.Logf("Getting %v points to test\n", len(points))
}
geoPoints := make([]cluster.GeoPoint, len(points))
for i := range points {
geoPoints[i] = points[i]
}
c, _ := cluster.New(geoPoints)
result := c.GetTile(0, 0, 0)
assert.NotEmpty(t, result)
expectedPoints := importGeoJSONResultFeature("./testdata/places-z0-0-0.json")
assert.Equal(t, len(result), len(expectedPoints))
for i := range result {
rp := result[i]
ep := expectedPoints[i]
assert.Equal(t, rp.X, ep.Geometry[0][0])
assert.Equal(t, rp.Y, ep.Geometry[0][1])
if rp.NumPoints > 1 {
assert.Equal(t, rp.NumPoints, ep.Tags.PointCount)
}
}
}
func ExampleCluster_GetTile() {
points := importData("./testdata/places.json")
geoPoints := make([]cluster.GeoPoint, len(points))
for i := range points {
geoPoints[i] = points[i]
}
c, _ := cluster.New(geoPoints,
cluster.WithinZoom(0, 3),
cluster.WithPointSize(60),
cluster.WithTileSize(256),
cluster.WithNodeSize(64))
result := c.GetTile(0, 0, 4)
fmt.Printf("%+v", result)
// Output: [{X:-3350 Y:253 zoom:0 ID:22 NumPoints:1 Included:[0]} {X:-2418 Y:165 zoom:0 ID:62 NumPoints:1 Included:[0]}]
}