<s> import numpy as np <EOL> from numpy . testing import assert_array_equal <EOL> from nose . tools import assert_raises , assert_equals <EOL> from . . classes import MatrixPreferenceDataModel , MatrixBooleanPrefDataModel <EOL> from . . utils import UserNotFoundError , ItemNotFoundError <EOL> from ... datasets import load_sample_songs <EOL> movies = { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { } } <EOL> movies = { '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT> , '<STR_LIT>' : <NUM_LIT:1.0> , '<STR_LIT>' : <NUM_LIT> } , <EOL> '<STR_LIT>' : { } } <EOL> def test_basic_methods_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( { } ) <EOL> assert_equals ( model . dataset , { } ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . item_ids ( ) ) <EOL> assert_equals ( True , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , model . items_count ( ) ) <EOL> assert_equals ( - np . inf , model . maximum_preference_value ( ) ) <EOL> assert_equals ( np . inf , model . minimum_preference_value ( ) ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_equals ( model . dataset , movies ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , model . item_ids ( ) ) <EOL> assert_equals ( True , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:6> , model . items_count ( ) ) <EOL> assert_equals ( <NUM_LIT> , model . maximum_preference_value ( ) ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . minimum_preference_value ( ) ) <EOL> assert_equals ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] , model [ '<STR_LIT>' ] ) <EOL> elements = [ pref for pref in model ] <EOL> assert_array_equal ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] , elements [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> songs = load_sample_songs ( ) <EOL> model = MatrixPreferenceDataModel ( songs . data ) <EOL> assert_equals ( model . dataset , songs . data ) <EOL> assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) , <EOL> model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) , model . item_ids ( ) ) <EOL> assert_equals ( True , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . items_count ( ) ) <EOL> assert_equals ( <NUM_LIT> , model . maximum_preference_value ( ) ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . minimum_preference_value ( ) ) <EOL> assert_equals ( [ ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT:2> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> ) , ( <NUM_LIT:4> , <NUM_LIT> ) , ( <NUM_LIT:5> , <NUM_LIT> ) , ( <NUM_LIT:6> , <NUM_LIT> ) , ( <NUM_LIT:7> , <NUM_LIT> ) ] , model [ <NUM_LIT:1> ] ) <EOL> elements = [ pref for pref in model ] <EOL> assert_array_equal ( [ ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT:2> , <NUM_LIT> ) , ( <NUM_LIT:3> , <NUM_LIT> ) , ( <NUM_LIT:4> , <NUM_LIT> ) , ( <NUM_LIT:5> , <NUM_LIT> ) , ( <NUM_LIT:6> , <NUM_LIT> ) , ( <NUM_LIT:7> , <NUM_LIT> ) ] , <EOL> elements [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> def test_preferences_from_user_exists_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , <EOL> model . preferences_from_user ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , model . preferences_from_user ( '<STR_LIT>' , order_by_id = False ) ) <EOL> def test_preferences_from_user_exists_no_preferences_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . preferences_from_user ( '<STR_LIT>' ) ) <EOL> def test_preferences_from_user_non_existing_user_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_raises ( UserNotFoundError , model . preferences_from_user , '<STR_LIT>' ) <EOL> def test_item_ids_from_user_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . items_from_user ( '<STR_LIT>' ) ) <EOL> def test_preferences_for_item_existing_item_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , <EOL> model . preferences_for_item ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) , ( '<STR_LIT>' , <NUM_LIT> ) ] ) , <EOL> model . preferences_for_item ( '<STR_LIT>' , order_by_id = False ) ) <EOL> def test_preferences_for_item_existing_item_no_preferences_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . preferences_for_item , '<STR_LIT>' ) <EOL> def test_preferences_for_item_non_existing_item_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_raises ( ItemNotFoundError , model . preferences_for_item , '<STR_LIT>' ) <EOL> def test_preference_value_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_equals ( <NUM_LIT> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_preference_value__invalid_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> assert_raises ( UserNotFoundError , model . preference_value , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_raises ( ItemNotFoundError , model . preference_value , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_array_equal ( np . nan , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_set_preference_value_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> model . set_preference ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) <EOL> assert_equals ( <NUM_LIT> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> model . set_preference ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1.0> ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_raises ( UserNotFoundError , model . set_preference , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) <EOL> def test_remove_preference_value_MatrixPreferenceDataModel ( ) : <EOL> model = MatrixPreferenceDataModel ( movies ) <EOL> model . remove_preference ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_array_equal ( np . nan , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_raises ( ItemNotFoundError , model . remove_preference , '<STR_LIT>' , '<STR_LIT>' ) <EOL> movies_boolean = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ ] <EOL> } <EOL> songs_boolean = { <NUM_LIT:1> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <NUM_LIT:2> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> <NUM_LIT:3> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] , <NUM_LIT:4> : [ <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> <NUM_LIT:5> : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <NUM_LIT:6> : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] , <EOL> <NUM_LIT:7> : [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:8> ] , <NUM_LIT:8> : [ <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:7> ] } <EOL> def test_basic_methods_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( { } ) <EOL> assert_equals ( model . dataset , { } ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . item_ids ( ) ) <EOL> assert_equals ( False , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:0> , model . items_count ( ) ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_equals ( model . dataset , movies_boolean ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , model . item_ids ( ) ) <EOL> assert_equals ( False , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:6> , model . items_count ( ) ) <EOL> assert_array_equal ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , model [ '<STR_LIT>' ] ) <EOL> elements = [ pref for pref in model ] <EOL> assert_array_equal ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , elements [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> songs = load_sample_songs ( ) <EOL> model = MatrixBooleanPrefDataModel ( songs . data ) <EOL> assert_equals ( model . dataset , songs_boolean ) <EOL> assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) , <EOL> model . user_ids ( ) ) <EOL> assert_array_equal ( np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) , model . item_ids ( ) ) <EOL> assert_equals ( False , model . has_preference_values ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . users_count ( ) ) <EOL> assert_equals ( <NUM_LIT:8> , model . items_count ( ) ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . maximum_preference_value ( ) ) <EOL> assert_equals ( <NUM_LIT:0.0> , model . minimum_preference_value ( ) ) <EOL> assert_array_equal ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , model [ <NUM_LIT:1> ] ) <EOL> elements = [ pref for pref in model ] <EOL> assert_array_equal ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] , <EOL> elements [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> assert ( "<STR_LIT>" in model . __str__ ( ) ) <EOL> def test_preferences_from_user_exists_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . preferences_from_user ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . preferences_from_user ( '<STR_LIT>' , order_by_id = False ) ) <EOL> def test_preferences_from_user_exists_no_preferences_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_array_equal ( np . array ( [ ] , <EOL> dtype = '<STR_LIT>' ) , model . preferences_from_user ( '<STR_LIT>' ) ) <EOL> def test_preferences_from_user_non_existing_user_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_raises ( UserNotFoundError , model . preferences_from_user , '<STR_LIT>' ) <EOL> def test_item_ids_from_user_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . items_from_user ( '<STR_LIT>' ) ) <EOL> def test_preferences_for_item_existing_item_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . preferences_for_item ( '<STR_LIT>' ) ) <EOL> assert_array_equal ( np . array ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> model . preferences_for_item ( '<STR_LIT>' , order_by_id = False ) ) <EOL> def test_preferences_for_item_existing_item_no_preferences_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_array_equal ( np . array ( [ ] ) , model . preferences_for_item , '<STR_LIT>' ) <EOL> def test_preferences_for_item_non_existing_item_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_raises ( ItemNotFoundError , model . preferences_for_item , '<STR_LIT>' ) <EOL> def test_preference_value_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_preference_value__invalid_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> assert_raises ( UserNotFoundError , model . preference_value , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_raises ( ItemNotFoundError , model . preference_value , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_array_equal ( np . NaN , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def test_set_preference_value_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> model . set_preference ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> model . set_preference ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_equals ( <NUM_LIT:1.0> , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_raises ( UserNotFoundError , model . set_preference , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_remove_preference_value_MatrixBooleanPrefDataModel ( ) : <EOL> model = MatrixBooleanPrefDataModel ( movies_boolean ) <EOL> model . remove_preference ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert_array_equal ( np . NaN , model . preference_value ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert_raises ( ItemNotFoundError , model . remove_preference , '<STR_LIT>' , '<STR_LIT>' ) </s>
