You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package sieve
|
|
|
|
|
|
|
|
import (
|
|
|
|
"slices"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSieveCache(t *testing.T) {
|
|
|
|
cache := NewCache(3)
|
|
|
|
cache.Put("a", "A")
|
|
|
|
cache.Put("b", "B")
|
|
|
|
cache.Put("c", "C")
|
|
|
|
cache.Put("d", "D")
|
|
|
|
cache.Put("b", "B")
|
|
|
|
cache.Put("e", "E")
|
|
|
|
cache.Put("a", "A")
|
|
|
|
|
|
|
|
expectedKeys := []string{"a", "b", "e"}
|
|
|
|
count := 0
|
|
|
|
cache.Range(func(k, _ string) bool {
|
|
|
|
count++
|
|
|
|
if !slices.Contains(expectedKeys, k) {
|
|
|
|
t.Fail()
|
|
|
|
t.Errorf("unexpected key in result: %s", k)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|