(** The bounded FIFO cache: hits, misses, eviction order, and no-op re-adds. *) let test_find_and_add () = let cache = Ogit.Cache.create ~capacity:4 in Alcotest.(check (option int)) "miss" None (Ogit.Cache.find cache "a"); Ogit.Cache.add cache "a" 1; Alcotest.(check (option int)) "hit" (Some 1) (Ogit.Cache.find cache "a") let test_eviction () = let cache = Ogit.Cache.create ~capacity:2 in Ogit.Cache.add cache "a" 1; Ogit.Cache.add cache "b" 2; Ogit.Cache.add cache "c" 3; Alcotest.(check (option int)) "oldest evicted" None (Ogit.Cache.find cache "a"); Alcotest.(check (option int)) "second kept" (Some 2) (Ogit.Cache.find cache "b"); Alcotest.(check (option int)) "newest kept" (Some 3) (Ogit.Cache.find cache "c") let test_readd_is_noop () = let cache = Ogit.Cache.create ~capacity:2 in Ogit.Cache.add cache "a" 1; Ogit.Cache.add cache "a" 9; Alcotest.(check (option int)) "value unchanged" (Some 1) (Ogit.Cache.find cache "a") let suite = ( "cache", [ Alcotest.test_case "find and add" `Quick test_find_and_add; Alcotest.test_case "eviction" `Quick test_eviction; Alcotest.test_case "re-add is a no-op" `Quick test_readd_is_noop; ] )