add tests for idToKeyBuf/idFromKeyBuf
parent
b1de9ebfdd
commit
4a61314f32
|
@ -3,6 +3,7 @@ package cache
|
||||||
import (
|
import (
|
||||||
"goposm/element"
|
"goposm/element"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"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