-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbytes_shard_test.go
More file actions
45 lines (34 loc) · 896 Bytes
/
bytes_shard_test.go
File metadata and controls
45 lines (34 loc) · 896 Bytes
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
package lru
import (
"testing"
"unsafe"
)
func TestBytesShardPadding(t *testing.T) {
var s bytesshard
if n := unsafe.Sizeof(s); n != 128 {
t.Errorf("shard size is %d, not 128", n)
}
}
func TestBytesShardListSet(t *testing.T) {
var s bytesshard
s.Init(1024)
key := []byte("foobar")
value := []byte("42")
hash := uint32(wyhashHashbytes(key, 0))
s.Set(hash, key, value)
if index := s.listBack(); string(s.list[index].key) == string(key) {
t.Errorf("foobar should be list back: %v %s", index, s.list[index].key)
}
}
func TestBytesShardTableSet(t *testing.T) {
var s bytesshard
s.Init(1024)
key := []byte("foobar")
value := []byte("42")
hash := uint32(wyhashHashbytes(key, 0))
s.Set(hash, key, value)
i, ok := s.tableSet(hash, key, 123)
if v := s.list[i].value; !ok || string(v) != string(value) {
t.Errorf("foobar should be set to %s: %v %v", value, i, ok)
}
}