Added test cases

Signed-off-by: adoerr <me@andreasdoerr.de>
This commit is contained in:
adoerr 2016-06-14 14:19:49 +02:00
parent 6c0efdd46f
commit 5fbc69fe58
1 changed files with 36 additions and 0 deletions

View File

@ -23,3 +23,39 @@ func TestABC(t *testing.T) {
t.Fatalf("bad geohash %v,%v %v,%v", lat, lon, lat2, lon2) t.Fatalf("bad geohash %v,%v %v,%v", lat, lon, lat2, lon2)
} }
} }
// TestEqualsWebserviceHash checks whether an encoded geohash is equal to a
// geohash encoded by geohash.org for identical lat/lon values.
func TestEqualsWebserviceHash(t *testing.T) {
lat, lon := 27.173117, 78.042122
hash, err := Encode(lat, lon, 12)
if err != nil {
t.Fatal(err)
}
hash2 := "tsz6xfswchpu"
if hash != hash2 {
t.Errorf("geohash should be equal %v, %v", hash, hash2)
}
}
func TestNearbyHasCommonPrefix(t *testing.T) {
lat, lon := 27.174583139355413, 78.04258346557617
hash, err := Encode(lat, lon, 32)
if err != nil {
t.Fatal(err)
}
lat2, lon2 := 27.174559277910305, 78.04163932800293
hash2, err := Encode(lat2, lon2, 32)
if err != nil {
t.Fatal(err)
}
// common prefix should be at least of length 7
pref := hash[:7]
pref2 := hash2[:7]
if pref != pref2 {
t.Errorf("prefix should be equal %v, %v", pref, pref2)
}
}