add tests for idToKeyBuf/idFromKeyBuf

master
Oliver Tonnhofer 2013-06-05 11:13:19 +02:00
parent b1de9ebfdd
commit 4a61314f32
1 changed files with 23 additions and 0 deletions

23
cache/db_test.go vendored
View File

@ -3,6 +3,7 @@ package cache
import (
"goposm/element"
"io/ioutil"
"math/rand"
"os"
"testing"
)
@ -155,3 +156,25 @@ func BenchmarkReadWay(b *testing.B) {
}
}
func TestIds(t *testing.T) {
for i := 0; i < 10000; i++ {
id := rand.Int63()
if idFromKeyBuf(idToKeyBuf(id)) != id {
t.Fatal()
}
}
// check that id buffers are in lexical order
var id = int64(0)
var prevKey string
for i := 0; i < 100; i++ {
id += rand.Int63n(1e12)
buf := idToKeyBuf(id)
if prevKey > string(buf) {
t.Fatal()
}
prevKey = string(buf)
}
}