github.com/coyove/sdss@v0.0.0-20231129015646-c2ec58cca6a2/contrib/bitmap/lru_test.go (about)

     1  package bitmap
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  	"testing"
     7  )
     8  
     9  func TestCache_Add(t *testing.T) {
    10  	base := New(0).RoughSizeBytes()
    11  
    12  	c := NewLRUCache(10 * base)
    13  
    14  	for i := 0; i < 10; i++ {
    15  		c.Add("key"+strconv.Itoa(i), New(int64(i)))
    16  	}
    17  
    18  	for i := 0; i < 10; i++ {
    19  		v := c.Get("key" + strconv.Itoa(i))
    20  		if v.start != int64(i) {
    21  			t.Error("Add failed")
    22  		}
    23  	}
    24  
    25  	c.Add("key10", New(10))
    26  	if ok := c.Get("key0"); ok != nil {
    27  		t.Error("key0 should be removed")
    28  	}
    29  
    30  	fmt.Println(c.cache)
    31  }