From 438c57e8475e6624062ed3f6a10db5fe2dd0d3be Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 4 Feb 2015 09:15:57 +0100 Subject: [PATCH] a few tests for CCCache.lru --- src/data/CCCache.ml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/data/CCCache.ml b/src/data/CCCache.ml index e65b2e2f..2c1d152e 100644 --- a/src/data/CCCache.ml +++ b/src/data/CCCache.ml @@ -293,6 +293,24 @@ let lru (type a) ?(eq=default_eq_) ?(hash=default_hash_) size = iter=L.iter c; } +(*$T + let eq (i1,_)(i2,_) = i1=i2 and hash (i,_) = CCInt.hash i in \ + let c = lru ~eq ~hash 2 in \ + ignore (with_cache c CCFun.id (1, true)); \ + ignore (with_cache c CCFun.id (1, false)); \ + with_cache c CCFun.id (1, false) = (1, true) +*) + +(*$T + let f = (let r = ref 0 in fun _ -> incr r; !r) in \ + let c = lru 2 in \ + let res1 = with_cache c f 1 in \ + let res2 = with_cache c f 2 in \ + let res3 = with_cache c f 3 in \ + let res1_bis = with_cache c f 1 in \ + res1 <> res2 && res2 <> res3 && res3 <> res1_bis && res1_bis <> res1 +*) + module UNBOUNDED(X:HASH) = struct module H = Hashtbl.Make(X)