This repository was archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_test.go
More file actions
75 lines (62 loc) · 1.51 KB
/
random_test.go
File metadata and controls
75 lines (62 loc) · 1.51 KB
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
package goturf_test
import (
"testing"
. "github.com/crra/goturf"
"github.com/mmcloughlin/geohash"
"github.com/stretchr/testify/assert"
)
func newWorldBbox() *Bbox {
return &Bbox{
LonMin: -180,
LatMin: -90,
LonMax: 180,
LatMax: 90,
}
}
func TestNewRandomPoint(t *testing.T) {
t.Run("Returns a point with and without bbox", func(t *testing.T) {
bboxes := []*Bbox{
newWorldBbox(),
nil,
}
for _, bbox := range bboxes {
got := NewRandomPoint(bbox)
assert.NotNil(t, got)
}
})
t.Run("Consecutive points are different", func(t *testing.T) {
const runs = 5
// Use a set to collect unique values
results := map[string]bool{}
for i := 0; i < runs; i++ {
point := NewRandomPoint(nil)
results[geohash.Encode(point.Lat(), point.Lon())] = true
}
// Number of elements in the set
assert.Equal(t, runs, len(results))
})
}
func TestNewRandomPoints(t *testing.T) {
t.Run("Right number of points", func(t *testing.T) {
expectations := []struct {
number uint
bbox *Bbox
}{
{0, nil},
{0, newWorldBbox()},
{1, nil},
{1, newWorldBbox()},
}
for _, e := range expectations {
got := NewRandomPoints(e.number, e.bbox)
assert.NotNil(t, got)
assert.Equal(t, len(got.Features), int(e.number))
for _, f := range got.Features {
assert.NotNil(t, f)
assert.Equal(t, "Feature", f.Type)
assert.NotNil(t, f.Geometry)
assert.Equal(t, "Point", string(f.Geometry.Type))
}
}
})
}