-
Notifications
You must be signed in to change notification settings - Fork 46
/
util_test.go
61 lines (53 loc) · 1.24 KB
/
util_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
package geohash
import (
"math"
"math/rand"
)
func RandomPoint() (lat, lng float64) {
lat = -90 + 180*rand.Float64()
lng = -180 + 360*rand.Float64()
return
}
func RandomPoints(n int) [][2]float64 {
points := make([][2]float64, n)
for i := 0; i < n; i++ {
lat, lng := RandomPoint()
points[i] = [2]float64{lat, lng}
}
return points
}
func RandomBox() Box {
lat1, lng1 := RandomPoint()
lat2, lng2 := RandomPoint()
return Box{
MinLat: math.Min(lat1, lat2),
MaxLat: math.Max(lat1, lat2),
MinLng: math.Min(lng1, lng2),
MaxLng: math.Max(lng1, lng2),
}
}
func RandomStringGeohashWithPrecision(chars uint) string {
const alphabet = "0123456789bcdefghjkmnpqrstuvwxyz"
b := make([]byte, chars)
for i := uint(0); i < chars; i++ {
b[i] = alphabet[rand.Intn(32)]
}
return string(b)
}
func RandomStringGeohashesWithPrecision(n int, chars uint) []string {
geohashes := make([]string, n)
for i := 0; i < n; i++ {
geohashes[i] = RandomStringGeohashWithPrecision(chars)
}
return geohashes
}
func RandomIntGeohash() uint64 {
return (uint64(rand.Uint32()) << 32) | uint64(rand.Uint32())
}
func RandomIntGeohashes(n int) []uint64 {
geohashes := make([]uint64, n)
for i := 0; i < n; i++ {
geohashes[i] = RandomIntGeohash()
}
return geohashes
}