public void TestRecommender() { AtomicInteger recommendCount = new AtomicInteger(); Recommender mockRecommender = new MockRecommender(recommendCount); Recommender cachingRecommender = new CachingRecommender(mockRecommender); cachingRecommender.Recommend("1", 1); Assert.AreEqual(1, recommendCount.Value); cachingRecommender.Recommend("2", 1); Assert.AreEqual(2, recommendCount.Value); cachingRecommender.Recommend("1", 1); Assert.AreEqual(2, recommendCount.Value); cachingRecommender.Recommend("2", 1); Assert.AreEqual(2, recommendCount.Value); cachingRecommender.Refresh(); cachingRecommender.Recommend("1", 1); Assert.AreEqual(3, recommendCount.Value); cachingRecommender.Recommend("2", 1); Assert.AreEqual(4, recommendCount.Value); cachingRecommender.Recommend("3", 1); Assert.AreEqual(5, recommendCount.Value); // Results from this recommend() method can't be cached: Rescorer<Item> rescorer = NullRescorer<Item>.Instance; cachingRecommender.Refresh(); cachingRecommender.Recommend("1", 1, rescorer); Assert.AreEqual(6, recommendCount.Value); cachingRecommender.Recommend("2", 1, rescorer); Assert.AreEqual(7, recommendCount.Value); cachingRecommender.Recommend("1", 1, rescorer); Assert.AreEqual(8, recommendCount.Value); cachingRecommender.Recommend("2", 1, rescorer); Assert.AreEqual(9, recommendCount.Value); cachingRecommender.Refresh(); cachingRecommender.EstimatePreference("test1", "1"); Assert.AreEqual(10, recommendCount.Value); cachingRecommender.EstimatePreference("test1", "2"); Assert.AreEqual(11, recommendCount.Value); cachingRecommender.EstimatePreference("test1", "2"); Assert.AreEqual(11, recommendCount.Value); }
internal MockRecommender(AtomicInteger recommendCount) { this.recommendCount = recommendCount; }