@@ -41,3 +41,48 @@ func TestClock_EvictsWhenHandFindsColdPage(t *testing.T) {
4141 t .Fatalf ("expected to evict 'a' second, got %q ok=%v" , key , ok )
4242 }
4343}
44+
45+ func TestClock_ZeroCapacity_NoOp (t * testing.T ) {
46+ clk , err := NewClockAlgorithm (0 )
47+ if err != nil {
48+ t .Fatalf ("NewClockAlgorithm error: %v" , err )
49+ }
50+
51+ clk .Set ("a" , 1 )
52+ if _ , ok := clk .Get ("a" ); ok {
53+ t .Fatalf ("expected Get to miss on zero-capacity cache" )
54+ }
55+
56+ if key , ok := clk .Evict (); ok || key != "" {
57+ t .Fatalf ("expected no eviction on zero-capacity, got %q ok=%v" , key , ok )
58+ }
59+ }
60+
61+ func TestClock_Delete_RemovesItem (t * testing.T ) {
62+ clk , err := NewClockAlgorithm (2 )
63+ if err != nil {
64+ t .Fatalf ("NewClockAlgorithm error: %v" , err )
65+ }
66+
67+ clk .Set ("a" , 1 )
68+ clk .Set ("b" , 2 )
69+ clk .Delete ("a" )
70+
71+ if _ , ok := clk .Get ("a" ); ok {
72+ t .Fatalf ("expected 'a' to be deleted" )
73+ }
74+
75+ // Evict should not return deleted key
76+ // Loop a couple of times due to potential decrements
77+ for i := 0 ; i < 3 ; i ++ {
78+ if key , ok := clk .Evict (); ok {
79+ if key == "a" {
80+ t .Fatalf ("did not expect to evict deleted key 'a'" )
81+ }
82+ if key == "b" {
83+ return
84+ }
85+ }
86+ }
87+ t .Fatalf ("expected to eventually evict 'b'" )
88+ }
0 commit comments