github.com/phuslu/lru@v1.0.16-0.20240421170520-46288a2fd47c/bytes_shard_test.go (about) 1 package lru 2 3 import ( 4 "testing" 5 "unsafe" 6 ) 7 8 func TestBytesShardPadding(t *testing.T) { 9 var s bytesshard 10 11 if n := unsafe.Sizeof(s); n != 128 { 12 t.Errorf("shard size is %d, not 128", n) 13 } 14 } 15 16 func TestBytesShardListSet(t *testing.T) { 17 var s bytesshard 18 s.Init(1024) 19 20 key := []byte("foobar") 21 value := []byte("42") 22 hash := uint32(wyhash_HashBytes(key, 0)) 23 24 s.Set(hash, key, value) 25 26 if index := s.list_Back(); string(s.list[index].key) == string(key) { 27 t.Errorf("foobar should be list back: %v %s", index, s.list[index].key) 28 } 29 } 30 31 func TestBytesShardTableSet(t *testing.T) { 32 var s bytesshard 33 s.Init(1024) 34 35 key := []byte("foobar") 36 value := []byte("42") 37 hash := uint32(wyhash_HashBytes(key, 0)) 38 39 s.Set(hash, key, value) 40 41 i, ok := s.table_Set(hash, key, 123) 42 if v := s.list[i].value; !ok || string(v) != string(value) { 43 t.Errorf("foobar should be set to %s: %v %v", value, i, ok) 44 } 45 }