github.com/saintwish/kv@v1.0.4/kv1s/kv1s_test.go (about)

     1  package kv1s
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestSetGet_KeyString(t *testing.T) {
     9  	cache := New[string, string](2048, 32)
    10  	cache.Set("unicorns", "are cool")
    11  
    12  	if res := cache.Get("unicorns"); res != "are cool" {
    13  		t.Errorf("Result was incorrect, got: %s, want: %s.", res, "are cool")
    14  	}
    15  }
    16  
    17  func TestSetGet_KeyInt(t *testing.T) {
    18  	cache := New[int, string](2048, 32)
    19  	cache.Set(1337, "leet haxiors")
    20  
    21  	if res := cache.Get(1337); res != "leet haxiors" {
    22  		t.Errorf("Result was incorrect, got: %s, want: %s.", res, "leet haxiors")
    23  	}
    24  }
    25  
    26  func TestFlush(t *testing.T) {
    27  	cache := New[int, string](2048, 32)
    28  	cache.SetOnDeleted(func(k int, v string){
    29  		fmt.Println(k)
    30  	})
    31  
    32  	cache.Set(1337, "leet haxiors")
    33  	cache.Set(1338, "leet haxiors1")
    34  	cache.Set(3434, "leet haxiors2")
    35  	cache.Set(5465, "leet haxiors3")
    36  
    37  	cache.Flush()
    38  }