-
Notifications
You must be signed in to change notification settings - Fork 36
/
bytekey_test.go
54 lines (37 loc) · 1.36 KB
/
bytekey_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package offheap_test
import (
"testing"
"github.com/glycerine/offheap"
cv "github.com/glycerine/goconvey/convey"
)
func TestByteKeyInsertLookup(t *testing.T) {
h := offheap.NewByteKeyHashTable(8)
cv.Convey("inserting with a byte slice key using InsertBK should enable retrieving them with LookupBK", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
look, ok := h.LookupBK([]byte("hello"))
cv.So(ok, cv.ShouldEqual, false)
cv.So(look, cv.ShouldResemble, offheap.Val_t{})
ok = h.InsertBK([]byte("hello"), "world")
cv.So(ok, cv.ShouldEqual, true)
cv.So(h.Population, cv.ShouldEqual, 1)
val, ok := h.LookupBK([]byte("hello"))
cv.So(val.GetString(), cv.ShouldStartWith, "world")
cv.So(ok, cv.ShouldEqual, true)
})
}
func TestStringKeyInsertLookup(t *testing.T) {
h := offheap.NewStringHashTable(8)
cv.Convey("inserting with a byte slice key using InsertBK should enable retrieving them with LookupBK", t, func() {
cv.So(h.Population, cv.ShouldEqual, 0)
look, ok := h.LookupStringKey("hello")
cv.So(ok, cv.ShouldEqual, false)
cv.So(look, cv.ShouldResemble, offheap.Val_t{})
ok = h.InsertStringKey("hello", "world")
cv.So(ok, cv.ShouldEqual, true)
cv.So(h.Population, cv.ShouldEqual, 1)
//h.Dump()
val, ok := h.LookupStringKey("hello")
cv.So(val.GetString(), cv.ShouldStartWith, "world")
cv.So(ok, cv.ShouldEqual, true)
})
}