add tests for idToKeyBuf/idFromKeyBuf
parent
b1de9ebfdd
commit
4a61314f32
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue