v0.0.42
This commit is contained in:
@@ -12,7 +12,7 @@ func init() {
|
||||
}
|
||||
|
||||
func TestResultCache1(t *testing.T) {
|
||||
cache := NewLRUMap(8)
|
||||
cache := NewLRUMap[string](8)
|
||||
verifyLRUList(cache, t)
|
||||
|
||||
key := randomKey()
|
||||
@@ -39,7 +39,7 @@ func TestResultCache1(t *testing.T) {
|
||||
if !ok {
|
||||
t.Errorf("cache TryGet returned no value")
|
||||
}
|
||||
if !eq(cacheval, val) {
|
||||
if cacheval != val {
|
||||
t.Errorf("cache TryGet returned different value (%+v <> %+v)", cacheval, val)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestResultCache1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResultCache2(t *testing.T) {
|
||||
cache := NewLRUMap(8)
|
||||
cache := NewLRUMap[string](8)
|
||||
verifyLRUList(cache, t)
|
||||
|
||||
key1 := "key1"
|
||||
@@ -150,7 +150,7 @@ func TestResultCache2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResultCache3(t *testing.T) {
|
||||
cache := NewLRUMap(8)
|
||||
cache := NewLRUMap[string](8)
|
||||
verifyLRUList(cache, t)
|
||||
|
||||
key1 := "key1"
|
||||
@@ -160,20 +160,20 @@ func TestResultCache3(t *testing.T) {
|
||||
cache.Put(key1, val1)
|
||||
verifyLRUList(cache, t)
|
||||
|
||||
if val, ok := cache.TryGet(key1); !ok || !eq(val, val1) {
|
||||
if val, ok := cache.TryGet(key1); !ok || val != val1 {
|
||||
t.Errorf("Value in cache should be [val1]")
|
||||
}
|
||||
|
||||
cache.Put(key1, val2)
|
||||
verifyLRUList(cache, t)
|
||||
|
||||
if val, ok := cache.TryGet(key1); !ok || !eq(val, val2) {
|
||||
if val, ok := cache.TryGet(key1); !ok || val != val2 {
|
||||
t.Errorf("Value in cache should be [val2]")
|
||||
}
|
||||
}
|
||||
|
||||
// does a basic consistency check over the internal cache representation
|
||||
func verifyLRUList(cache *LRUMap, t *testing.T) {
|
||||
func verifyLRUList[TData any](cache *LRUMap[TData], t *testing.T) {
|
||||
size := 0
|
||||
|
||||
tailFound := false
|
||||
@@ -250,23 +250,10 @@ func randomKey() string {
|
||||
return strconv.FormatInt(rand.Int63(), 16)
|
||||
}
|
||||
|
||||
func randomVal() LRUData {
|
||||
func randomVal() string {
|
||||
v, err := langext.NewHexUUID()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
func eq(a LRUData, b LRUData) bool {
|
||||
v1, ok1 := a.(*string)
|
||||
v2, ok2 := b.(*string)
|
||||
if ok1 && ok2 {
|
||||
if v1 == nil || v2 == nil {
|
||||
return false
|
||||
}
|
||||
return v1 == v2
|
||||
}
|
||||
|
||||
return false
|
||||
return v
|
||||
}
|
||||
|
Reference in New Issue
Block a user