def setUp(self): recommender = Popular() recommender.init_recommender() self.evaluator = Evaluator(recommender, can_repeat=False) self.samples = [ Event(User(0), Item(0), 1), Event(User(0), Item(1), 1), Event(User(1), Item(2), 1), Event(User(0), Item(3), 1), Event(User(2), Item(4), 1), Event(User(1), Item(4), 1), Event(User(0), Item(5), 1), Event(User(2), Item(1), 1), Event(User(0), Item(6), 1), Event(User(2), Item(0), 1) ]
def setUp(self): self.recommender = Popular() self.recommender.initialize()
class PopularTestCase(TestCase): def setUp(self): self.recommender = Popular() self.recommender.initialize() def test_register_user(self): self.recommender.register(User(0)) self.assertEqual(self.recommender.n_user, 1) def test_register_item(self): self.recommender.register(Item(0)) self.assertEqual(self.recommender.n_item, 1) def test_update(self): self.recommender.register(User(0)) self.recommender.register(Item(0)) self.recommender.update(Event(User(0), Item(0), 1)) self.assertEqual(self.recommender.n_user, 1) self.assertEqual(self.recommender.n_item, 1) assert_array_equal(self.recommender.freq, np.array([1])) def test_score(self): self.recommender.register(User(0)) self.recommender.register(Item(0)) self.recommender.update(Event(User(0), Item(0), 1)) self.assertEqual(self.recommender.score(User(0), np.array([0])), 1)
def create(): rec = Popular() rec.init_recommender() return rec
def setUp(self): self.recommender = Popular() self.recommender.init_params() self.recommender.init_recommender()