Пример #1
0
 def test_add_none(self, fit_mock):
     recommender = Recommender(self.dpp_matrix, self.n_components)
     recommender.add({})
     expected_x = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
     np.testing.assert_array_equal(recommender.dpp_vector, expected_x)
     np.testing.assert_array_equal(
         fit_mock.call_args[0][0],
         expected_x.reshape(1, -1)
     )
     fit_mock.assert_called_once()
Пример #2
0
 def test_propose_empty_add(self, randint_mock):
     index = 0
     randint_mock.return_value = index
     proposed = np.argmax(self.dpp_matrix[0])  # 14
     recommender = Recommender(self.dpp_matrix, self.n_components)
     recommender.add({})
     np.testing.assert_array_equal(
         recommender.matching_dataset,
         self.dpp_matrix[index, :],
     )
     pipeline_index = recommender.propose()
     assert randint_mock.call_count == 2
     assert pipeline_index == proposed
Пример #3
0
 def test_add_twice(self, fit_mock):
     recommender = Recommender(self.dpp_matrix, self.n_components)
     recommender.add({1: 2, 3: 4, 5: 1})
     expected_x_1 = np.array(
         [0, 2, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
     )
     np.testing.assert_array_equal(recommender.dpp_vector, expected_x_1)
     np.testing.assert_array_equal(
         fit_mock.call_args[0][0],
         expected_x_1.reshape(1, -1)
     )
     recommender.add({1: 1, 6: 3, 9: 4})
     expected_x_2 = np.array(
         [0, 1, 0, 4, 0, 1, 3, 0, 0, 4, 0, 0, 0, 0, 0, 0]
     )
     np.testing.assert_array_equal(recommender.dpp_vector, expected_x_2)
     np.testing.assert_array_equal(
         fit_mock.call_args[0][0],
         expected_x_2.reshape(1, -1)
     )
     self.assertEqual(fit_mock.call_count, 2)