mirror of
https://github.com/HDT3213/godis.git
synced 2025-11-03 11:02:17 +08:00
refactor project structure
This commit is contained in:
39
lib/geohash/geohash_test.go
Normal file
39
lib/geohash/geohash_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package geohash
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestToRange(t *testing.T) {
|
||||
neighbor := []byte{0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00}
|
||||
range_ := 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 != range_[0] {
|
||||
t.Error("incorrect lower")
|
||||
}
|
||||
if expectedUpper != range_[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)
|
||||
}
|
||||
Reference in New Issue
Block a user