def test_find_common_elements(): #MatrixModel model_matrix = MatrixPreferenceDataModel(movies) source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Leopoldo Pires') assert_array_equal(np.array([[2.5, 3.5, 3.5, 3.0]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal(np.array([[2.5, 3.0, 3.5, 4.0]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Luciana Nunes') assert_array_equal(np.array([[3., 2.5, 3.5, 3.5, 3., 2.5]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal(np.array([[1.5, 3., 3.5, 5., 3., 3.5]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Maria Gabriela') assert_array_equal(np.array([[]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal(np.array([[]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_for_item('Snakes on a Plane') target_preferences = model_matrix.preferences_for_item('Superman Returns') assert_array_equal(np.array([[3., 3.5, 3.5, 3.5, 4.5, 4., 4.]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal(np.array([[3.5, 4., 5., 3.5, 4., 5., 3.]]), find_common_elements(source_preferences, target_preferences)[1]) model_matrix.set_preference('Maria Gabriela', 'Back to the Future', 3.5) source_preferences = model_matrix.preferences_for_item('Back to the Future') target_preferences = model_matrix.preferences_for_item('Superman Returns') assert_array_equal(np.array([[]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal(np.array([[]]), find_common_elements(source_preferences, target_preferences)[1])
def test_set_preference_value_MatrixPreferenceDataModel(): #Add model = MatrixPreferenceDataModel(movies) model.set_preference('Maria Gabriela', 'Superman Returns', 2.0) assert_equals(2.0, model.preference_value('Maria Gabriela', 'Superman Returns')) #Edit model = MatrixPreferenceDataModel(movies) model.set_preference('Marcel Caraciolo', 'Superman Returns', 1.0) assert_equals(1.0, model.preference_value('Marcel Caraciolo', 'Superman Returns')) #invalid assert_raises(UserNotFoundError, model.set_preference, 'Carlos', 'Superman Returns', 2.0)
def test_find_common_elements(): #MatrixModel model_matrix = MatrixPreferenceDataModel(movies) source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Leopoldo Pires') assert_array_equal( np.array([[2.5, 3.5, 3.5, 3.0]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal( np.array([[2.5, 3.0, 3.5, 4.0]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Luciana Nunes') assert_array_equal( np.array([[3., 2.5, 3.5, 3.5, 3., 2.5]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal( np.array([[1.5, 3., 3.5, 5., 3., 3.5]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_from_user('Marcel Caraciolo') target_preferences = model_matrix.preferences_from_user('Maria Gabriela') assert_array_equal( np.array([[]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal( np.array([[]]), find_common_elements(source_preferences, target_preferences)[1]) #MatrixModel source_preferences = model_matrix.preferences_for_item('Snakes on a Plane') target_preferences = model_matrix.preferences_for_item('Superman Returns') assert_array_equal( np.array([[3., 3.5, 3.5, 3.5, 4.5, 4., 4.]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal( np.array([[3.5, 4., 5., 3.5, 4., 5., 3.]]), find_common_elements(source_preferences, target_preferences)[1]) model_matrix.set_preference('Maria Gabriela', 'Back to the Future', 3.5) source_preferences = model_matrix.preferences_for_item( 'Back to the Future') target_preferences = model_matrix.preferences_for_item('Superman Returns') assert_array_equal( np.array([[]]), find_common_elements(source_preferences, target_preferences)[0]) assert_array_equal( np.array([[]]), find_common_elements(source_preferences, target_preferences)[1])