Inheritance: NReco.CF.Taste.Impl.Model.AbstractDataModel
        public void testStrategy()
        {
            List<IPreference> prefsOfUser123 = new List<IPreference>();
            prefsOfUser123.Add(new GenericPreference(123L, 1L, 1.0f));

            List<IPreference> prefsOfUser456 = new List<IPreference>();
            prefsOfUser456.Add(new GenericPreference(456L, 1L, 1.0f));
            prefsOfUser456.Add(new GenericPreference(456L, 2L, 1.0f));

            List<IPreference> prefsOfUser789 = new List<IPreference>();
            prefsOfUser789.Add(new GenericPreference(789L, 1L, 0.5f));
            prefsOfUser789.Add(new GenericPreference(789L, 3L, 1.0f));

            IPreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray(prefsOfUser123);

            FastByIDMap<IPreferenceArray> userData = new FastByIDMap<IPreferenceArray>();
            userData.Put(123L, prefArrayOfUser123);
            userData.Put(456L, new GenericUserPreferenceArray(prefsOfUser456));
            userData.Put(789L, new GenericUserPreferenceArray(prefsOfUser789));

            IDataModel dataModel = new GenericDataModel(userData);

            ICandidateItemsStrategy strategy =
            new SamplingCandidateItemsStrategy(1, 1, 1, dataModel.GetNumUsers(), dataModel.GetNumItems());

            FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, dataModel);
            Assert.True(candidateItems.Count() <= 1);
            Assert.False(candidateItems.Contains(1L));
        }
コード例 #2
0
        public void testSerialization()
        {
            GenericDataModel model = (GenericDataModel)getDataModel();

            var formatter = new BinaryFormatter();
            var ms        = new MemoryStream();

            formatter.Serialize(ms, model);
            ms.Position = 0;

            GenericDataModel newModel = (GenericDataModel)formatter.Deserialize(ms);

            Assert.AreEqual(model.GetNumItems(), newModel.GetNumItems());
            Assert.AreEqual(model.GetNumUsers(), newModel.GetNumUsers());
            Assert.True(model.GetPreferencesFromUser(1L).Equals(newModel.GetPreferencesFromUser(1L)));
            Assert.True(model.GetPreferencesForItem(1L).Equals(newModel.GetPreferencesForItem(1L)));
            Assert.AreEqual(model.GetRawUserData(), newModel.GetRawUserData());
        }