-
Notifications
You must be signed in to change notification settings - Fork 22
Ocelots - Lisa Utsett #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| from viewing_party.party import * | ||
| from tests.test_constants import * | ||
|
|
||
| @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"] == GENRE_1 | ||
| assert new_movie["rating"] == pytest.approx(RATING_1) | ||
|
|
||
| @pytest.mark.skip() | ||
|
|
||
| def test_create_no_title_movie(): | ||
| # Arrange | ||
| movie_title = None | ||
|
|
@@ -32,7 +32,7 @@ def test_create_no_title_movie(): | |
| # Assert | ||
| assert new_movie is None | ||
|
|
||
| @pytest.mark.skip() | ||
|
|
||
| def test_create_no_genre_movie(): | ||
| # Arrange | ||
| movie_title = "Title A" | ||
|
|
@@ -45,7 +45,6 @@ def test_create_no_genre_movie(): | |
| # Assert | ||
| assert new_movie is None | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_create_no_rating_movie(): | ||
| # Arrange | ||
| movie_title = "Title A" | ||
|
|
@@ -58,7 +57,6 @@ def test_create_no_rating_movie(): | |
| # Assert | ||
| assert new_movie is None | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_adds_movie_to_user_watched(): | ||
| # Arrange | ||
| movie = { | ||
|
|
@@ -79,7 +77,7 @@ def test_adds_movie_to_user_watched(): | |
| assert updated_data["watched"][0]["genre"] == GENRE_1 | ||
| assert updated_data["watched"][0]["rating"] == RATING_1 | ||
|
|
||
| @pytest.mark.skip() | ||
|
|
||
| def test_adds_movie_to_user_watchlist(): | ||
| # Arrange | ||
| movie = { | ||
|
|
@@ -100,7 +98,6 @@ def test_adds_movie_to_user_watchlist(): | |
| assert updated_data["watchlist"][0]["genre"] == GENRE_1 | ||
| assert updated_data["watchlist"][0]["rating"] == RATING_1 | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_moves_movie_from_watchlist_to_empty_watched(): | ||
| # Arrange | ||
| janes_data = { | ||
|
|
@@ -118,13 +115,11 @@ def test_moves_movie_from_watchlist_to_empty_watched(): | |
| # Assert | ||
| assert len(updated_data["watchlist"]) == 0 | ||
| assert len(updated_data["watched"]) == 1 | ||
|
|
||
| raise Exception("Test needs to be completed.") | ||
| assert updated_data["watched"][0]['title'] == MOVIE_TITLE_1 | ||
| # ******************************************************************************************* | ||
| # ****** Add assertions here to test that the correct movie was added to "watched" ********** | ||
| # ******************************************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_moves_movie_from_watchlist_to_watched(): | ||
| # Arrange | ||
| movie_to_watch = HORROR_1 | ||
|
|
@@ -142,13 +137,12 @@ def test_moves_movie_from_watchlist_to_watched(): | |
| # Assert | ||
| assert len(updated_data["watchlist"]) == 1 | ||
| assert len(updated_data["watched"]) == 2 | ||
|
|
||
| raise Exception("Test needs to be completed.") | ||
| assert updated_data["watched"][1]['title'] == movie_to_watch["title"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README isn't explicit about what order we should add movies to the list assert movie_to_watch in updated_data["watched"]
# Another option:
assert HORROR_1 in updated_data["watched"] |
||
|
|
||
| # ******************************************************************************************* | ||
| # ****** Add assertions here to test that the correct movie was added to "watched" ********** | ||
| # ******************************************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_does_nothing_if_movie_not_in_watchlist(): | ||
| # Arrange | ||
| movie_to_watch = HORROR_1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| from viewing_party.party import * | ||
| from tests.test_constants import * | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_my_unique_movies(): | ||
| # Arrange | ||
| amandas_data = clean_wave_3_data() | ||
|
|
@@ -16,7 +15,6 @@ def test_my_unique_movies(): | |
| assert INTRIGUE_2 in amandas_unique_movies | ||
| assert amandas_data == clean_wave_3_data() | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_my_not_unique_movies(): | ||
| # Arrange | ||
| amandas_data = clean_wave_3_data() | ||
|
|
@@ -28,7 +26,6 @@ def test_my_not_unique_movies(): | |
| # Assert | ||
| assert len(amandas_unique_movies) == 0 | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_friends_unique_movies(): | ||
| # Arrange | ||
| amandas_data = clean_wave_3_data() | ||
|
|
@@ -43,7 +40,6 @@ def test_friends_unique_movies(): | |
| assert FANTASY_4 in friends_unique_movies | ||
| assert amandas_data == clean_wave_3_data() | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_friends_unique_movies_not_duplicated(): | ||
| # Arrange | ||
| amandas_data = clean_wave_3_data() | ||
|
|
@@ -54,13 +50,12 @@ def test_friends_unique_movies_not_duplicated(): | |
|
|
||
| # Assert | ||
| assert len(friends_unique_movies) == 3 | ||
| assert friends_unique_movies.count(INTRIGUE_3) == 1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice check for assert INTRIGUE_3 in friends_unique_movies
assert HORROR_1 in friends_unique_movies
assert FANTASY_4 in friends_unique_movies |
||
|
|
||
| raise Exception("Test needs to be completed.") | ||
| # ************************************************************************************************* | ||
| # ****** Add assertions here to test that the correct movies are in friends_unique_movies ********** | ||
| # ************************************************************************************************** | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_friends_not_unique_movies(): | ||
| # Arrange | ||
| amandas_data = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
| from viewing_party.party import * | ||
| from tests.test_constants import * | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_new_genre_rec(): | ||
| # Arrange | ||
| sonyas_data = clean_wave_5_data() | ||
|
|
@@ -17,7 +16,6 @@ def test_new_genre_rec(): | |
| assert FANTASY_4b in recommendations | ||
| assert sonyas_data == clean_wave_5_data() | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_new_genre_rec_from_empty_watched(): | ||
| # Arrange | ||
| sonyas_data = { | ||
|
|
@@ -38,7 +36,6 @@ def test_new_genre_rec_from_empty_watched(): | |
| # Assert | ||
| assert len(recommendations) == 0 | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_new_genre_rec_from_empty_friends(): | ||
| # Arrange | ||
| sonyas_data = { | ||
|
|
@@ -53,12 +50,17 @@ def test_new_genre_rec_from_empty_friends(): | |
| ] | ||
| } | ||
|
|
||
| raise Exception("Test needs to be completed.") | ||
| # Act | ||
| recommendations = get_new_rec_by_genre(sonyas_data) | ||
|
|
||
| # Assert | ||
| assert len(recommendations) == 0 | ||
|
Comment on lines
+54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great act & assert steps! |
||
|
|
||
| #raise Exception("Test needs to be completed.") | ||
| # ********************************************************************* | ||
| # ****** Complete the Act and Assert Portions of theis tests ********** | ||
| # ********************************************************************* | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_unique_rec_from_favorites(): | ||
| # Arrange | ||
| sonyas_data = clean_wave_5_data() | ||
|
|
@@ -72,7 +74,6 @@ def test_unique_rec_from_favorites(): | |
| assert INTRIGUE_2b in recommendations | ||
| assert sonyas_data == clean_wave_5_data() | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_unique_from_empty_favorites(): | ||
| # Arrange | ||
| sonyas_data = { | ||
|
|
@@ -94,7 +95,6 @@ def test_unique_from_empty_favorites(): | |
| # Assert | ||
| assert len(recommendations) == 0 | ||
|
|
||
| @pytest.mark.skip() | ||
| def test_new_rec_from_empty_friends(): | ||
| # Arrange | ||
| sonyas_data = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,129 @@ | ||
| # ------------- WAVE 1 -------------------- | ||
|
|
||
| def create_movie(title, genre, rating): | ||
| pass | ||
| if not title or not genre or not rating: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of the truthy/falsy values to check for empty strings or |
||
| return None | ||
| else: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it doesn't change the result of our function, I recommend removing the If an |
||
| return { "title": title, | ||
| "genre": genre, | ||
| "rating": rating | ||
| } | ||
|
|
||
| def add_to_watched(user_data, movie): | ||
| user_data["watched"].append(movie) | ||
| return user_data | ||
|
|
||
| def add_to_watchlist(user_data, movie): | ||
| user_data["watchlist"].append(movie) | ||
| return user_data | ||
|
|
||
| def watch_movie(user_data, title): | ||
| for movie in user_data["watchlist"]: | ||
| if movie["title"] == title: | ||
| add_to_watched(user_data, movie) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice code reuse! |
||
| user_data["watchlist"].remove(movie) | ||
| break | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of |
||
| return user_data | ||
|
|
||
|
|
||
| # ----------------------------------------- | ||
| # ------------- WAVE 2 -------------------- | ||
| # ----------------------------------------- | ||
| def get_watched_avg_rating(user_data): | ||
| sum = 0.0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something to note: the names |
||
| user_data_len = len(user_data["watched"]) | ||
|
Comment on lines
+33
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider moving the instantiation of |
||
| if user_data_len >0: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little bit personal taste, but I often prefer to reverse the validation check and use it like a guard clause at the top of the function. This can let us take the main logic of our function out of an if-statement so it is prominent and clear rather than indented. For me, this makes code easier to read, but you may feel differently or work on a team that has guidelines for how they structure validation checks. We can also use the truthy/falsy value of if not user_data["watched"]:
return 0.0
sum = 0.0
for movie in user_data["watched"]:
sum += movie["rating"]
return sum / len(user_data["watched"]) |
||
| for movie in user_data["watched"]: | ||
| sum += movie["rating"] | ||
|
Comment on lines
+36
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice approach! Another way we could do this is using list comprehensions and the # The list comprehension inside the `sum` call pulls the value of the
# `rating` key out of each item in the list `user_data['watched']`
sum = sum(movie["rating"] for movie in user_data["watched"])
return sum / len(user_data["watched"]) |
||
|
|
||
| return sum/user_data_len | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PEP8 guide on whitespace recommends we always place a single space on either side of an operator. This makes it easier for folks to visually process a line of code and see the groups of related statements in an expression. If you'd like more info, I suggest checking out the style guide for whitespace in expressions and statements: https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements |
||
| else: | ||
| return sum | ||
|
|
||
|
|
||
| def get_most_watched_genre(user_data): | ||
| most_watched_dict = {} | ||
| user_data_len = len(user_data["watched"]) | ||
|
|
||
| if user_data_len > 0: | ||
| for movie in user_data["watched"]: | ||
| if movie["genre"] in most_watched_dict: | ||
| most_watched_dict[movie["genre"]] += 1 | ||
| else: | ||
| most_watched_dict[movie["genre"]] = 0 | ||
|
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a tradeoff of using a little more space for another variable, but to make the code a little easier to read and reduce how many times we need to access for movie in user_data["watched"]:
movie_genre = movie["genre"]
if movie_genre in most_watched_dict:
most_watched_dict[movie_genre] += 1
else:
most_watched_dict[movie_genre] = 1
Comment on lines
+49
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an off by one error in how the genres are counted; if we want an accurate count, we would need to start the counter at 1 rather than 0. As an example, let's say we have a list with only one |
||
|
|
||
| most_watched_genre = max(most_watched_dict, key=most_watched_dict.get) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of a frequency map and |
||
| return most_watched_genre | ||
| else: | ||
| return None | ||
|
|
||
| # ----------------------------------------- | ||
| # ------------- WAVE 3 -------------------- | ||
| # ----------------------------------------- | ||
| def get_unique_watched(user_data): | ||
| unique_movies = [] | ||
| friends_movies = set() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of |
||
|
|
||
| for friend in user_data["friends"]: | ||
| for movie in friend["watched"]: | ||
| friends_movies.add(movie["title"]) | ||
|
|
||
| for user_movie in user_data["watched"]: | ||
| if user_movie["title"] not in friends_movies: | ||
| unique_movies.append(user_movie) | ||
|
|
||
| return unique_movies | ||
|
|
||
| def get_friends_unique_watched(user_data): | ||
| unique_movies = [] | ||
| user_movies = [] | ||
|
|
||
| for user_movie in user_data["watched"]: | ||
| user_movies.append(user_movie["title"]) | ||
|
Comment on lines
+79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we don't need complicated logic to transform data, a common way to fill a list in Python is using a list comprehension: user_movies = [movie["title"] for movie in user_data["watched"]]Here's a resource on list comprehensions if you want more info: https://realpython.com/list-comprehension-python/ |
||
|
|
||
| for friend in user_data["friends"]: | ||
| for movie in friend["watched"]: | ||
| if movie["title"] not in user_movies and movie not in unique_movies: | ||
| unique_movies.append(movie) | ||
|
|
||
| return unique_movies | ||
|
Comment on lines
+78
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing wrong with this organization, but I want to suggest a slight change that can help readers, especially in longer functions. Instead of declaring all our variables at the top of a function, I recommend creating them just before you need to use them. This help reduce needing to jump around the function or scroll up the page to remind ourselves of what a variable holds. user_movies = []
for user_movie in user_data["watched"]:
user_movies.append(user_movie["title"])
unique_movies = []
for friend in user_data["friends"]:
... |
||
|
|
||
| # ----------------------------------------- | ||
| # ------------- WAVE 4 -------------------- | ||
| # ----------------------------------------- | ||
|
|
||
| def get_available_recs(user_data): | ||
| friends_recs = [] | ||
| friends_unique_data = get_friends_unique_watched(user_data) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice code reuse! |
||
|
|
||
| if len(friends_unique_data) >0 and len(user_data["watched"])> 0: | ||
| for movie in friends_unique_data: | ||
| if movie["host"] in user_data["subscriptions"]: | ||
| friends_recs.append(movie) | ||
|
Comment on lines
+100
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice algorithm! Another way we could approach filtering the # list comprehension
result = [movie for movie in friends_unique_data if movie["host"] in user_data["subscriptions"]]This line is a bit long, in practice we would split a statement like this across lines, use some extra variables, or shorten some naming to keep under the PEP8 guide of 79 characters max per line: # list comprehension
result = [movie for movie in friends_unique_data
if movie["host"] in user_data["subscriptions"]] |
||
|
|
||
| return friends_recs | ||
|
|
||
|
|
||
| # ----------------------------------------- | ||
| # ------------- WAVE 5 -------------------- | ||
| # ----------------------------------------- | ||
|
|
||
| def get_new_rec_by_genre(user_data): | ||
| rec_by_genre = [] | ||
| most_watched_genre = get_most_watched_genre(user_data) | ||
| recs = get_available_recs(user_data) | ||
| for movie in recs: | ||
| if movie["genre"] == most_watched_genre: | ||
| rec_by_genre.append(movie) | ||
|
|
||
| return rec_by_genre | ||
|
Comment on lines
+112
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though this solution passes the current test suite, it isn't doing what the problem statement asks. The test
|
||
|
|
||
| def get_rec_from_favorites(user_data): | ||
| rec_from_favorites = [] | ||
| unique_watched = get_unique_watched(user_data) | ||
|
|
||
| if len(user_data["favorites"]) >0: | ||
| for movie in unique_watched: | ||
| if movie in user_data["favorites"]: | ||
| rec_from_favorites.append(movie) | ||
| return rec_from_favorites | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice assertion for the title! In this case where the test is checking individual keys of a dictionary, I recommend including assertions for all of the relevant keys.