blob: decf81780755c7fd9c34bba4f3ca1f189713c734 [file] [log] [blame] [edit]
# This file reports differences detected by import.go since the last import.
# This is only for human review and not machine consumption.
# Please see go/thirdpartygo for more information.
# DO NOT EDIT. This must only be generated by //third_party/golang/import.go.
@@ import (
"math/rand"
"testing"
"time"
+
+ "google3/third_party/golang/cmp/cmp"
)
func init() {
@@ func TestARC_Peek(t *testing.T) {
t.Errorf("should not have updated recent-ness of 1")
}
}
+
+func TestARC_OnEvictedCallback(t *testing.T) {
+ type testCase struct {
+ size int
+ data []int
+ evicted []int
+ }
+
+ testCases := map[string]testCase{
+ "basic-lru-like": {
+ size: 2,
+ data: []int{1, 2, 3, 4},
+ evicted: []int{1, 2},
+ },
+ "t1-to-t2-promotion-simple": {
+ size: 4,
+ data: []int{1, 2, 1, 2, 3, 4, 5, 6},
+ evicted: []int{3, 4},
+ },
+ "adaptive-replacement-simple": {
+ size: 4,
+ data: []int{1, 2, 3, 4, 5, 6, 1, 2, 7, 8},
+ evicted: []int{1, 2, 3, 4, 1, 5},
+ },
+ "MFU-not-evicted-by-new-entries": {
+ size: 4,
+ data: []int{4, 4, 1, 2, 3, 4, 5, 6, 7, 8},
+ evicted: []int{1, 2, 3, 5},
+ },
+ "t2-full-b2-empty-new-items": {
+ size: 4,
+ data: []int{
+ // fill t2, b2 should be empty since its target size is zero
+ 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
+ // insert "new" items
+ 1, 2, 3, 4,
+ },
+ evicted: []int{1, 2, 3, 4, 5, 1, 2, 3},
+ },
+ }
+
+ runTest := func(t *testing.T, tc testCase) {
+ evicted := []int{}
+ c, err := NewARCWithEvict(tc.size, func(key interface{}, _ interface{}) {
+ evicted = append(evicted, key.(int))
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ for _, val := range tc.data {
+ c.Add(val, val)
+ }
+
+ if !cmp.Equal(tc.evicted, evicted) {
+ t.Errorf("Expectations mismatch.\nWant: %+v\nGot: %+v", tc.evicted, evicted)
+ }
+ }
+
+ for name, tc := range testCases {
+ t.Run(name, func(t *testing.T) { runTest(t, tc) })
+ }
+}