Files
redis-go/lib/geohash/geohash_test.go
2021-05-13 08:56:07 +08:00

40 lines
903 B
Go

package geohash
import (
"fmt"
"math"
"testing"
)
func TestToRange(t *testing.T) {
neighbor := []byte{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00}
geoRange := toRange(neighbor, 36)
expectedLower := ToInt([]byte{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00})
expectedUpper := ToInt([]byte{0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00})
if expectedLower != geoRange[0] {
t.Error("incorrect lower")
}
if expectedUpper != geoRange[1] {
t.Error("incorrect upper")
}
}
func TestEncode(t *testing.T) {
lat0 := 48.669
lng0 := -4.32913
hash := Encode(lat0, lng0)
str := ToString(FromInt(hash))
if str != "gbsuv7zt7zntw" {
t.Error("encode error")
}
lat, lng := Decode(hash)
if math.Abs(lat-lat0) > 1e-6 || math.Abs(lng-lng0) > 1e-6 {
t.Error("decode error")
}
}
func TestGetNeighbours(t *testing.T) {
ranges := GetNeighbours(90, 180, 630*1000)
fmt.Printf("%#v", ranges)
}