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.
1717package  lru
1818
1919import  (
20+ 	"fmt" 
2021	"testing" 
2122)
2223
@@ -71,3 +72,26 @@ func TestRemove(t *testing.T) {
7172		t .Fatal ("TestRemove returned a removed entry" )
7273	}
7374}
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