public final class CachingRecommenderTest extends TasteTestCase {
@Test
public void testRecommender() throws Exception {
MutableInt recommendCount = new MutableInt();
Recommender mockRecommender = new MockRecommender(recommendCount);
Recommender cachingRecommender = new CachingRecommender(mockRecommender);
cachingRecommender.recommend(1, 1);
assertEquals(1, recommendCount.intValue());
cachingRecommender.recommend(2, 1);
assertEquals(2, recommendCount.intValue());
cachingRecommender.recommend(1, 1);
assertEquals(2, recommendCount.intValue());
cachingRecommender.recommend(2, 1);
assertEquals(2, recommendCount.intValue());
cachingRecommender.refresh(null);
cachingRecommender.recommend(1, 1);
assertEquals(3, recommendCount.intValue());
cachingRecommender.recommend(2, 1);
assertEquals(4, recommendCount.intValue());
cachingRecommender.recommend(3, 1);
assertEquals(5, recommendCount.intValue());
// Results from this recommend() method can be cached...
IDRescorer rescorer = NullRescorer.getItemInstance();
cachingRecommender.refresh(null);
cachingRecommender.recommend(1, 1, rescorer);
assertEquals(6, recommendCount.intValue());
cachingRecommender.recommend(2, 1, rescorer);
assertEquals(7, recommendCount.intValue());
cachingRecommender.recommend(1, 1, rescorer);
assertEquals(7, recommendCount.intValue());
cachingRecommender.recommend(2, 1, rescorer);
assertEquals(7, recommendCount.intValue());
// until you switch Rescorers
cachingRecommender.recommend(1, 1, null);
assertEquals(8, recommendCount.intValue());
cachingRecommender.recommend(2, 1, null);
assertEquals(9, recommendCount.intValue());
cachingRecommender.refresh(null);
cachingRecommender.estimatePreference(1, 1);
assertEquals(10, recommendCount.intValue());
cachingRecommender.estimatePreference(1, 2);
assertEquals(11, recommendCount.intValue());
cachingRecommender.estimatePreference(1, 2);
assertEquals(11, recommendCount.intValue());
}