ConcurrentMapBasedLongToIntFunctionMemoizerTest.java 文件源码

java
阅读 34 收藏 0 点赞 0 评论 0

项目:memoization.java 作者:
/**
*
*/
@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());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号