@@ -128,6 +128,25 @@ func TestLRU_Add(t *testing.T) {
128128	}
129129}
130130
131+ func  TestLRU_GetAndAdd (t  * testing.T ) {
132+ 	l , err  :=  NewLRU (1 , nil )
133+ 	if  err  !=  nil  {
134+ 		t .Fatalf ("err: %v" , err )
135+ 	}
136+ 	if  previous , ok , evicted  :=  l .GetAndAdd (1 , 1 ); ok  ||  evicted  {
137+ 		t .Errorf ("1 should not be found, eviction should not be: %v, %v, %v" , previous , ok , evicted )
138+ 	}
139+ 	if  previous , ok , evicted  :=  l .GetAndAdd (1 , 10 ); ! ok  ||  previous  !=  1  ||  evicted  {
140+ 		t .Errorf ("1 should be returned as previous value, eviction should not be: %v, %v, %v" , previous , ok , evicted )
141+ 	}
142+ 	if  v , ok  :=  l .Get (1 ); ! ok  ||  v  !=  10  {
143+ 		t .Errorf ("1 should be set to 10: %v, %v" , v , ok )
144+ 	}
145+ 	if  previous , ok , evicted  :=  l .GetAndAdd (2 , 2 ); ok  ||  ! evicted  {
146+ 		t .Errorf ("2 should not be found, eviction should be: %v, %v, %v" , previous , ok , evicted )
147+ 	}
148+ }
149+ 
131150// Test that Contains doesn't update recent-ness 
132151func  TestLRU_Contains (t  * testing.T ) {
133152	l , err  :=  NewLRU (2 , nil )
0 commit comments