github.com/hkspirt/lru@v0.0.0-20180910065046-1c4838c29ec4/lru_test.go (about) 1 //---------------- 2 //Func :LRU Container Testing 3 //Author: xjh 4 //Date : 2018/09/10 5 //Note : 6 //---------------- 7 package lru 8 9 import ( 10 "fmt" 11 "testing" 12 ) 13 14 func TestLruContainer_PushFront(t *testing.T) { 15 lc := NewLruContainer(10) 16 for idx := 0; idx < 100; idx++ { 17 lc.PushFront(idx%10, idx) 18 } 19 fmt.Println(lc.Len()) 20 21 fmt.Println(lc.Get(5)) 22 fmt.Println(lc.Get(4)) 23 24 lc.Del(7) 25 26 for idx := 0; idx < 10; idx++ { 27 fmt.Println(lc.PopBack()) 28 } 29 30 fmt.Println(lc.Get(4)) 31 fmt.Println(lc.Get(5)) 32 33 fmt.Println(lc.Len()) 34 } 35 36 var glc = NewLruContainer(1000) 37 var idx int 38 39 func BenchmarkLruContainer_PushFront(b *testing.B) { 40 glc.PushFront(idx, idx) 41 } 42 43 func BenchmarkLruContainer_Get(b *testing.B) { 44 glc.Get(idx) 45 }