public void LFU_CanGetOrAdd2() { var cache = new LFUCache <int>(2); var factoryUsed = false; cache.GetOrAdd("MyKey1", () => { factoryUsed = true; return(5); }); var result = cache.GetOrAdd("MyKey1", () => { Assert.Fail("Should not use factory"); return(-1); }); Assert.IsTrue(factoryUsed); Assert.AreEqual(5, result); }
public void LFU_CanGetOrAdd3() { var cache = new LFUCache <int>(2); Assert.IsTrue(cache.TryAdd("MyKey1", 100)); var result = cache.GetOrAdd("MyKey1", () => { Assert.Fail("Should not use factory"); return(-1); }); Assert.AreEqual(100, result); }