forked from gnagel/ggeohash
/
utils_test.go
39 lines (32 loc) · 938 Bytes
/
utils_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
package ggeohash
import "testing"
import "github.com/orfjackal/gospec/src/gospec"
func TestUtilsSpecs(t *testing.T) {
// Setup the suite
r := gospec.NewRunner()
// Add new specs here:
r.AddSpec(UtilsSpecs)
// Execute the suite
gospec.MainGoTest(r, t)
}
// Helpers
func UtilsSpecs(c gospec.Context) {
//
// Verify the conversion methods return the correct input/output
//
c.Specify("Converts ints to bytes and back again", func() {
// This is important to get right ...
// The GeoHash algorithm depends on this being fast and consistent
src := "0123456789bcdefghjkmnpqrstuvwxyz"
for i := 0; i < 32; i++ {
// What is the character at "i"
src_at := byte(src[i])
// Map the position to the byte
byte_at := convertIndexToByte(i)
c.Expect(byte_at, gospec.Equals, src_at)
// Map the byte back to the position
index_at := convertByteToIndex(byte_at)
c.Expect(index_at, gospec.Equals, i)
}
})
}