Этот коммит содержится в:
Chris
2018-02-28 14:07:11 -06:00
коммит произвёл Christopher Speller
родитель 2fba6fa799
Коммит 600528e1cf
2 изменённых файлов: 43 добавлений и 103 удалений

Просмотреть файл

@@ -11,14 +11,7 @@ import "testing"
import "time"
func TestLRU(t *testing.T) {
evictCounter := 0
onEvicted := func(k interface{}, v interface{}) {
evictCounter += 1
}
l, err := NewLruWithEvict(128, onEvicted)
if err != nil {
t.Fatalf("err: %v", err)
}
l := NewLru(128)
for i := 0; i < 256; i++ {
l.Add(i, i)
@@ -27,10 +20,6 @@ func TestLRU(t *testing.T) {
t.Fatalf("bad len: %v", l.Len())
}
if evictCounter != 128 {
t.Fatalf("bad evict count: %v", evictCounter)
}
for i, k := range l.Keys() {
if v, ok := l.Get(k); !ok || v != k || v != i+128 {
t.Fatalf("bad key: %v", k)
@@ -73,26 +62,6 @@ func TestLRU(t *testing.T) {
}
}
// test that Add return true/false if an eviction occurred
func TestLRUAdd(t *testing.T) {
evictCounter := 0
onEvicted := func(k interface{}, v interface{}) {
evictCounter += 1
}
l, err := NewLruWithEvict(1, onEvicted)
if err != nil {
t.Fatalf("err: %v", err)
}
if l.Add(1, 1) || evictCounter != 0 {
t.Errorf("should not have an eviction")
}
if !l.Add(2, 2) || evictCounter != 1 {
t.Errorf("should have an eviction")
}
}
func TestLRUExpire(t *testing.T) {
l := NewLru(128)