public void recommend() { var dataModelMock = new DynamicMock(typeof(IDataModel)); var preferencesFromUserMock = new DynamicMock(typeof(IPreferenceArray)); var candidateItemsStrategyMock = new DynamicMock(typeof(ICandidateItemsStrategy)); var factorizerMock = new DynamicMock(typeof(IFactorizer)); var factorization = new Factorization_recommend_TestMock(); FastIDSet candidateItems = new FastIDSet(); candidateItems.Add(5L); candidateItems.Add(3L); factorizerMock.ExpectAndReturn("Factorize", factorization); dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUserMock.MockInstance, (1L)); candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", candidateItems, 1L, preferencesFromUserMock.MockInstance, dataModelMock.MockInstance); //EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization); SVDRecommender svdRecommender = new SVDRecommender( (IDataModel)dataModelMock.MockInstance, (IFactorizer)factorizerMock.MockInstance, (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance); IList <IRecommendedItem> recommendedItems = svdRecommender.Recommend(1L, 5); Assert.AreEqual(2, recommendedItems.Count); Assert.AreEqual(3L, recommendedItems[0].GetItemID()); Assert.AreEqual(2.0f, recommendedItems[0].GetValue(), EPSILON); Assert.AreEqual(5L, recommendedItems[1].GetItemID()); Assert.AreEqual(1.0f, recommendedItems[1].GetValue(), EPSILON); dataModelMock.Verify(); candidateItemsStrategyMock.Verify(); factorizerMock.Verify(); Assert.AreEqual(2, factorization.getItemFeaturesCallCount); Assert.AreEqual(2, factorization.getUserFeaturesCallCount); //EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization); }
public void recommend() { var dataModelMock = new DynamicMock( typeof(IDataModel) ); var preferencesFromUserMock = new DynamicMock( typeof(IPreferenceArray) ); var candidateItemsStrategyMock = new DynamicMock( typeof(ICandidateItemsStrategy) ); var factorizerMock = new DynamicMock( typeof(IFactorizer) ); var factorization = new Factorization_recommend_TestMock(); FastIDSet candidateItems = new FastIDSet(); candidateItems.Add(5L); candidateItems.Add(3L); factorizerMock.ExpectAndReturn("Factorize", factorization); dataModelMock.ExpectAndReturn("GetPreferencesFromUser", preferencesFromUserMock.MockInstance, (1L)); candidateItemsStrategyMock.ExpectAndReturn("GetCandidateItems", candidateItems, 1L, preferencesFromUserMock.MockInstance, dataModelMock.MockInstance); //EasyMock.replay(dataModel, candidateItemsStrategy, factorizer, factorization); SVDRecommender svdRecommender = new SVDRecommender( (IDataModel)dataModelMock.MockInstance, (IFactorizer)factorizerMock.MockInstance, (ICandidateItemsStrategy)candidateItemsStrategyMock.MockInstance); IList<IRecommendedItem> recommendedItems = svdRecommender.Recommend(1L, 5); Assert.AreEqual(2, recommendedItems.Count); Assert.AreEqual(3L, recommendedItems[0].GetItemID()); Assert.AreEqual(2.0f, recommendedItems[0].GetValue(), EPSILON); Assert.AreEqual(5L, recommendedItems[1].GetItemID()); Assert.AreEqual(1.0f, recommendedItems[1].GetValue(), EPSILON); dataModelMock.Verify(); candidateItemsStrategyMock.Verify(); factorizerMock.Verify(); Assert.AreEqual(2, factorization.getItemFeaturesCallCount); Assert.AreEqual(2, factorization.getUserFeaturesCallCount); //EasyMock.verify(dataModel, candidateItemsStrategy, factorizer, factorization); }