mirror of https://github.com/perkeep/perkeep.git
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
/*
|
|
Copyright 2011 Google Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package lru
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestLRU(t *testing.T) {
|
|
c := New(2)
|
|
|
|
expectMiss := func(k string) {
|
|
v, ok := c.Get(k)
|
|
if ok {
|
|
t.Fatalf("expected cache miss on key %q but hit value %v", k, v)
|
|
}
|
|
}
|
|
|
|
expectHit := func(k string, ev interface{}) {
|
|
v, ok := c.Get(k)
|
|
if !ok {
|
|
t.Fatalf("expected cache(%q)=%v; but missed", k, ev)
|
|
}
|
|
if !reflect.DeepEqual(v, ev) {
|
|
t.Fatalf("expected cache(%q)=%v; but got %v", k, ev, v)
|
|
}
|
|
}
|
|
|
|
expectMiss("1")
|
|
c.Add("1", "one")
|
|
expectHit("1", "one")
|
|
|
|
c.Add("2", "two")
|
|
expectHit("1", "one")
|
|
expectHit("2", "two")
|
|
|
|
c.Add("3", "three")
|
|
expectHit("3", "three")
|
|
expectHit("2", "two")
|
|
expectMiss("1")
|
|
}
|