/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
// given
final ConcurrentMap<Long, Integer> cache = new ConcurrentHashMap<>();
final LongToIntFunction function = input -> 123;
final LongFunction<Long> keyFunction = Long::valueOf;
// when
final ConcurrentMapBasedLongToIntFunctionMemoizer<Long> memoizer = new ConcurrentMapBasedLongToIntFunctionMemoizer<>(
cache, keyFunction, function);
// then
memoizer.applyAsInt(123L);
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", 123L,
memoizer.viewCacheForTest().keySet().iterator().next().longValue());
Assert.assertEquals("Memoization value does not match expectations", 123,
memoizer.viewCacheForTest().values().iterator().next().intValue());
}
ConcurrentMapBasedLongToIntFunctionMemoizerTest.java 文件源码
java
阅读 34
收藏 0
点赞 0
评论 0
项目:memoization.java
作者:
评论列表
文章目录