File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ limitations under the License.
17
17
package lru
18
18
19
19
import (
20
+ "fmt"
20
21
"testing"
21
22
)
22
23
@@ -71,3 +72,26 @@ func TestRemove(t *testing.T) {
71
72
t .Fatal ("TestRemove returned a removed entry" )
72
73
}
73
74
}
75
+
76
+ func TestEvict (t * testing.T ) {
77
+ evictedKeys := make ([]Key , 0 )
78
+ onEvictedFun := func (key Key , value interface {}) {
79
+ evictedKeys = append (evictedKeys , key )
80
+ }
81
+
82
+ lru := New (20 )
83
+ lru .OnEvicted = onEvictedFun
84
+ for i := 0 ; i < 22 ; i ++ {
85
+ lru .Add (fmt .Sprintf ("myKey%d" , i ), 1234 )
86
+ }
87
+
88
+ if len (evictedKeys ) != 2 {
89
+ t .Fatalf ("got %d evicted keys; want 2" , len (evictedKeys ))
90
+ }
91
+ if evictedKeys [0 ] != Key ("myKey0" ) {
92
+ t .Fatalf ("got %v in first evicted key; want %s" , evictedKeys [0 ], "myKey0" )
93
+ }
94
+ if evictedKeys [1 ] != Key ("myKey1" ) {
95
+ t .Fatalf ("got %v in second evicted key; want %s" , evictedKeys [1 ], "myKey1" )
96
+ }
97
+ }
You can’t perform that action at this time.
0 commit comments