diff --git a/README.md b/README.md index 10fd9a0c3..e037dd599 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ $ source venv/bin/activate - *What type of input do we need to test this case?* - *What is the expected output for the given input?* - Remove the lines that contain `@pytest.mark.skip()` for the test(s) you want to run. - + 3. Run the test(s)! - *See the [Details About How to Run Tests](#details-about-how-to-run-tests) section below for more information on how to run test(s).* diff --git a/tests/test_wave_01.py b/tests/test_wave_01.py index c033af09f..23fbc3ecd 100644 --- a/tests/test_wave_01.py +++ b/tests/test_wave_01.py @@ -4,7 +4,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_successful_movie(): # Arrange movie_title = MOVIE_TITLE_1 @@ -19,7 +19,7 @@ def test_create_successful_movie(): assert new_movie["genre"] is GENRE_1 assert new_movie["rating"] == pytest.approx(RATING_1) -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_title_movie(): # Arrange movie_title = None @@ -32,7 +32,8 @@ def test_create_no_title_movie(): # Assert assert new_movie is None -@pytest.mark.skip() + +# @pytest.mark.skip() def test_create_no_genre_movie(): # Arrange movie_title = "Title A" @@ -45,7 +46,7 @@ def test_create_no_genre_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_create_no_rating_movie(): # Arrange movie_title = "Title A" @@ -58,7 +59,7 @@ def test_create_no_rating_movie(): # Assert assert new_movie is None -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watched(): # Arrange movie = { @@ -79,7 +80,7 @@ def test_adds_movie_to_user_watched(): assert updated_data["watched"][0]["genre"] is GENRE_1 assert updated_data["watched"][0]["rating"] is RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_adds_movie_to_user_watchlist(): # Arrange movie = { @@ -100,7 +101,7 @@ def test_adds_movie_to_user_watchlist(): assert updated_data["watchlist"][0]["genre"] is GENRE_1 assert updated_data["watchlist"][0]["rating"] is RATING_1 -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_empty_watched(): # Arrange janes_data = { @@ -118,12 +119,20 @@ def test_moves_movie_from_watchlist_to_empty_watched(): # Assert assert len(updated_data["watchlist"]) is 0 assert len(updated_data["watched"]) is 1 + assert updated_data["watchlist"] == [] + assert { + "title": MOVIE_TITLE_1, + "genre": GENRE_1, + "rating": RATING_1 + } in updated_data["watched"] + + # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_moves_movie_from_watchlist_to_watched(): # Arrange movie_to_watch = HORROR_1 @@ -141,12 +150,14 @@ def test_moves_movie_from_watchlist_to_watched(): # Assert assert len(updated_data["watchlist"]) is 1 assert len(updated_data["watched"]) is 2 + assert HORROR_1 in updated_data["watched"] + assert FANTASY_2 in updated_data["watched"] # ******************************************************************************************* # ****** Add assertions here to test that the correct movie was added to "watched" ********** # ******************************************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_does_nothing_if_movie_not_in_watchlist(): # Arrange movie_to_watch = HORROR_1 diff --git a/tests/test_wave_02.py b/tests/test_wave_02.py index 3a588299e..198e395b3 100644 --- a/tests/test_wave_02.py +++ b/tests/test_wave_02.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_calculates_watched_average_rating(): # Arrange janes_data = clean_wave_2_data() @@ -14,7 +14,7 @@ def test_calculates_watched_average_rating(): assert average == pytest.approx(3.58333) assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_empty_watched_average_rating_is_zero(): # Arrange janes_data = { @@ -27,7 +27,7 @@ def test_empty_watched_average_rating_is_zero(): # Assert assert average == pytest.approx(0.0) -@pytest.mark.skip() +# @pytest.mark.skip() def test_most_watched_genre(): # Arrange janes_data = clean_wave_2_data() @@ -39,7 +39,7 @@ def test_most_watched_genre(): assert popular_genre == "Fantasy" assert janes_data == clean_wave_2_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_genre_is_None_if_empty_watched(): # Arrange janes_data = { diff --git a/tests/test_wave_03.py b/tests/test_wave_03.py index 7c42a63c4..7495f7350 100644 --- a/tests/test_wave_03.py +++ b/tests/test_wave_03.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -16,7 +16,7 @@ def test_my_unique_movies(): assert INTRIGUE_2 in amandas_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_my_not_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -28,7 +28,7 @@ def test_my_not_unique_movies(): # Arrange assert len(amandas_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies(): # Arrange amandas_data = clean_wave_3_data() @@ -43,7 +43,7 @@ def test_friends_unique_movies(): assert FANTASY_4 in friends_unique_movies assert amandas_data == clean_wave_3_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_unique_movies_not_duplicated(): # Arrange amandas_data = clean_wave_3_data() @@ -54,12 +54,37 @@ def test_friends_unique_movies_not_duplicated(): # Arrange assert len(friends_unique_movies) == 3 + assert HORROR_1 in friends_unique_movies + assert INTRIGUE_3 in friends_unique_movies + assert FANTASY_4 in friends_unique_movies # ************************************************************************************************* # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** # ************************************************************************************************** +def test_friends_have_no_movies_watched(): + amandas_data= { + "watched": [ + HORROR_1, + FANTASY_1, + INTRIGUE_1 + ], + "friends": [ + { + "watched": [] + }, + { + "watched": [] + } + ] + } + + # Act + friends_unique_movies = get_friends_unique_watched(amandas_data) + + # Arrange + assert len(friends_unique_movies) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_friends_not_unique_movies(): # Arrange amandas_data = { diff --git a/tests/test_wave_04.py b/tests/test_wave_04.py index 72888410f..8cb037a87 100644 --- a/tests/test_wave_04.py +++ b/tests/test_wave_04.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_get_available_friend_rec(): # Arrange amandas_data = clean_wave_4_data() @@ -16,7 +16,7 @@ def test_get_available_friend_rec(): assert FANTASY_4b in recommendations assert amandas_data == clean_wave_4_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_no_available_friend_recs(): # Arrange amandas_data = { diff --git a/tests/test_wave_05.py b/tests/test_wave_05.py index 8ce5b57db..a4e8eda4a 100644 --- a/tests/test_wave_05.py +++ b/tests/test_wave_05.py @@ -2,7 +2,7 @@ from viewing_party.party import * from tests.test_constants import * -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec(): # Arrange sonyas_data = clean_wave_5_data() @@ -17,7 +17,7 @@ def test_new_genre_rec(): assert FANTASY_4b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_watched(): # Arrange sonyas_data = { @@ -38,7 +38,7 @@ def test_new_genre_rec_from_empty_watched(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_genre_rec_from_empty_friends(): # Arrange sonyas_data = { @@ -52,12 +52,17 @@ def test_new_genre_rec_from_empty_friends(): } ] } + # Act + recommendations = get_new_rec_by_genre(sonyas_data) + # Assert + assert len(recommendations) == 0 + # ********************************************************************* - # ****** Complete the Act and Assert Portions of theis tests ********** + # ****** Complete the Act and Assert Portions of this tests ********** # ********************************************************************* -@pytest.mark.skip() +# @pytest.mark.skip() def test_unique_rec_from_favorites(): # Arrange sonyas_data = clean_wave_5_data() @@ -71,7 +76,7 @@ def test_unique_rec_from_favorites(): assert INTRIGUE_2b in recommendations assert sonyas_data == clean_wave_5_data() -@pytest.mark.skip() +# @pytest.mark.skip() def test_unique_from_empty_favorites(): # Arrange sonyas_data = { @@ -92,7 +97,7 @@ def test_unique_from_empty_favorites(): # Assert assert len(recommendations) == 0 -@pytest.mark.skip() +# @pytest.mark.skip() def test_new_rec_from_empty_friends(): # Arrange sonyas_data = { diff --git a/viewing_party/party.py b/viewing_party/party.py index 6d34a6b5f..4f2329f18 100644 --- a/viewing_party/party.py +++ b/viewing_party/party.py @@ -1,23 +1,229 @@ # ------------- WAVE 1 -------------------- +MOVIE_TITLE_1 = "It Came from the Stack Trace" +GENRE_1 = "Horror" +RATING_1 = 3.5 def create_movie(title, genre, rating): - pass + movie_dict= {} + if not title: + return None + elif not genre : + return None + elif not rating: + return None + else: + movie_dict["title"]= title + movie_dict["genre"]= genre + movie_dict["rating"] = rating + return movie_dict + +def add_to_watched(user_data, movie): + if movie: + user_data['watched'].append(movie) + return user_data + return None + + +def add_to_watchlist(user_data, movie): + if movie : + user_data["watchlist"].append(movie) + return user_data + return None + +def watch_movie(user_data, title): + if title: + if user_data['watchlist']: + watchlist_data = user_data['watchlist'] + for item in watchlist_data: + if item['title'] == title: + watchlist_data.remove(item) + watched_data = user_data["watched"] + watched_data.append(item) + return user_data + return None + # ----------------------------------------- # ------------- WAVE 2 -------------------- # ----------------------------------------- +def get_watched_avg_rating(user_data): + watched_data = user_data['watched'] + average_rating = [] + total_rating = 0 + if not watched_data: + return 0.0 + elif watched_data: + for movie in watched_data: + average_rating.append(movie['rating']) + for rating in average_rating: + total_rating += rating + average = float(total_rating/ len(average_rating)) + return average + + + + # Psudo code + # takes in user_data + # user_data_structure: {watched:[{movie:title, genre:type, rating:number}{}{}]} + # if watch list is empty --> return 0.0 + # go into watched list and get movie ratings + # Append values to list + # In loop add all ratings + # len list to get denom for average + # return average rating + + +import statistics +from statistics import mode +def get_most_watched_genre(user_data): +# psudo +# access watched +# count how many of each genre in dictrionary +# return most frequently watched +# if emtpy return none + + + watched_data = user_data["watched"] + genre_list= [] + if watched_data == []: + return None + for movie in watched_data: + if movie['genre']: + genre_list.append(movie['genre']) + most_watched_genre = mode(genre_list) + return most_watched_genre + + + # ----------------------------------------- # ------------- WAVE 3 -------------------- # ----------------------------------------- +def get_unique_watched(user_data): + # Psudo + # user_data = {watched: [{movie}{movie}], friends:[{watched:[{movie}]}[watched:{movie}][{watched:{movie}}]]} + # access watched and friends watched + # compare dictionaries--> if they have the title that is not in the other list + # append list with movies if True + # titles in users watched to titles friends have not watched + # user_watched = user_data['watched'] + # print(user_data) + + + user_watched = user_data['watched'] + list_friends = user_data['friends'] + user_unique = [] + for movie in user_watched: + if is_movie_unique(movie,list_friends): + user_unique.append(movie) + return(user_unique) + +def is_movie_unique(movie, list_of_friends): + for friend in list_of_friends: + if movie in friend["watched"]: + return False + return True + + + + +# 2. The next three tests are about a `get_friends_unique_watched()` function. + + +def get_friends_unique_watched(user_data): + + user_watched = user_data['watched'] + list_friends = user_data['friends'] + friends_unique = [] + + + for friend in list_friends: + for movie in friend['watched']: + if is_friends_movie_unique(movie, user_watched) and movie not in friends_unique: + friends_unique.append(movie) + return(friends_unique) + +def is_friends_movie_unique(movie, user_watched_list): + if movie in user_watched_list: + return False + else: + return True + + + + + + # ----------------------------------------- # ------------- WAVE 4 -------------------- # ----------------------------------------- +def get_available_recs(user_data): + + subs = user_data["subscriptions"] + avail_recs = [] + no_recs = [] + if get_friends_unique_watched == []: + return no_recs + else: + for streaming_services in subs: + for unique_movie in get_friends_unique_watched(user_data): + if streaming_services == unique_movie['host']: + avail_recs.append(unique_movie) + return avail_recs + + + + # ----------------------------------------- # ------------- WAVE 5 -------------------- # ----------------------------------------- + +def get_new_rec_by_genre(user_data): + # find users most watched genre + # add movies to watch list if user hasnt watched it , a friend has watched it, genre matches most watched + # return list of movies + rec_by_genre = [] + no_recs= [] + genre = get_most_watched_genre(user_data) + movie_list = get_friends_unique_watched(user_data) + if movie_list == []: + return no_recs + else: + for movie in movie_list: + if genre == movie['genre']: + rec_by_genre.append(movie) + return rec_by_genre + +# 2. There are also two tests about a `get_rec_from_favorites` function + +# Create a function named `get_rec_from_favorites` + +# - takes one parameter: `user_data` +# - `user_data` will have a field `"favorites"`. The value of `"favorites"` is a list of movie dictionaries +# - This represents the user's favorite movies +# - Then, determine a list of recommended movies. A movie should be added to this list if and only if: +# - The movie is in the user's `"favorites"` +# - None of the user's friends have watched it +# - Return the list of recommended movies +def get_rec_from_favorites(user_data): + favorite_recs = [] + user_unique = get_unique_watched(user_data) + user_faves= user_data["favorites"] + no_recs = [] + + for movies in user_faves: + if user_unique == []: + return no_recs + elif movies in user_unique: + favorite_recs.append(movies) + return favorite_recs + + + + +