mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-06 01:07:06 +08:00
40 lines
903 B
Go
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)
|
|
}
|