let%expect_test _ = let print_list print_ele xs = let rec iter pre post = function | [] -> print_string post | x :: xs -> print_string pre; print_ele x; iter ";" "]" xs in iter "[" "[]" xs in let print_history_nl ch k = print_list print_int (Cache.find_all ch k); print_newline () in let ch = Cache.make 4 in Cache.add ch "x" 1; Cache.add ch "y" 2; Cache.add ch "y" 3; Cache.add ch "z" 4; print_history_nl ch "x"; [%expect {| [1] |}]; print_history_nl ch "y"; [%expect {| [3;2] |}]; print_history_nl ch "z"; [%expect {| [4] |}]; print_history_nl ch "w"; [%expect {| [] |}]; Cache.add ch "w" 5; (* evict "x:=1" *) print_history_nl ch "x"; [%expect {| [] |}]; print_history_nl ch "y"; [%expect {| [3;2] |}]; print_history_nl ch "z"; [%expect {| [4] |}]; print_history_nl ch "w"; [%expect {| [5] |}]; Cache.add ch "w" 6; (* evict "y:=2" *) print_history_nl ch "x"; [%expect {| [] |}]; print_history_nl ch "y"; [%expect {| [3] |}]; print_history_nl ch "z"; [%expect {| [4] |}]; print_history_nl ch "w"; [%expect {| [6;5] |}]; Cache.add ch "x" 7; (* evict "y:=3" *) Cache.add ch "w" 8; (* evict "z:=4" *) print_history_nl ch "x"; [%expect {| [7] |}]; print_history_nl ch "y"; [%expect {| [] |}]; print_history_nl ch "z"; [%expect {| [] |}]; print_history_nl ch "w"; [%expect {| [8;6;5] |}];