ConcurrentMapBasedLongUnaryOperatorMemoizerTest.java 文件源码

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

项目:memoization.java 作者:
/**
*
*/
@Test
public void shouldUseSetCacheKeyAndValue() {
    // given
    final ConcurrentMap<Long, Long> cache = new ConcurrentHashMap<>();
    final LongUnaryOperator operator = input -> input;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongUnaryOperatorMemoizer<Long> memoizer = new ConcurrentMapBasedLongUnaryOperatorMemoizer<>(
            cache, keyFunction, operator);

    // then
    memoizer.applyAsLong(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", 123L,
            memoizer.viewCacheForTest().values().iterator().next().longValue());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号