def test_watchlist_remove_movie(): watchlist = WatchList() movie = Movie("Moana", 2016) watchlist.add_movie(movie) watchlist.remove_movie("") assert len(watchlist.watchlist) == 1 watchlist.remove_movie(movie) assert len(watchlist.watchlist) == 0 watchlist.remove_movie(movie) assert len(watchlist.watchlist) == 0
def test_watchlist_size(): watchlist = WatchList() assert watchlist.size() == 0 movie1 = Movie("Moana", 2016) movie2 = Movie("Frozen", 2014) watchlist.add_movie(movie1) assert watchlist.size() == 1 watchlist.add_movie(movie2) assert watchlist.size() == 2 watchlist.remove_movie(movie1) assert watchlist.size() == 1
def test_watchlist_select_movie_to_watch(): watchlist = WatchList() movie1 = Movie("Moana", 2016) movie2 = Movie("Frozen", 2014) assert watchlist.select_movie_to_watch(0) is None watchlist.add_movie(movie1) assert watchlist.select_movie_to_watch(0) == movie1 assert watchlist.select_movie_to_watch(1) is None watchlist.add_movie(movie2) assert watchlist.select_movie_to_watch(1) == movie2 watchlist.remove_movie(movie1) assert watchlist.select_movie_to_watch(1) is None assert watchlist.select_movie_to_watch(0) == movie2 assert watchlist.select_movie_to_watch("0") is None assert watchlist.select_movie_to_watch(-1) is None
def test_watchlist_iterator(): watchlist = WatchList() movie1 = Movie("Moana", 2016) movie2 = Movie("Frozen", 2014) watchlist.add_movie(movie1) watchlist.add_movie(movie2) i = iter(watchlist) # test __iter__ assert i == watchlist.__iter__() # test __next__ assert next(i) == watchlist.watchlist[0] == movie1 assert next(i) == watchlist.watchlist[1] == movie2 with pytest.raises(StopIteration): next(i)
def test_watchlist_add_movie(): watchlist = WatchList() movie1 = Movie("Moana", 2016) movie2 = Movie("Frozen", 2014) watchlist.add_movie(movie1) assert len(watchlist.watchlist) == 1 assert watchlist.watchlist[0] == movie1 watchlist.add_movie(movie2) assert len(watchlist.watchlist) == 2 assert watchlist.watchlist[1] == movie2 watchlist.add_movie(movie1) assert len(watchlist.watchlist) == 2 watchlist.add_movie("") assert len(watchlist.watchlist) == 2
def test_watch_list_iter_and_next(): watchlist9 = WatchList() watchlist9.add_movie(Movie("Moana", 2016)) watchlist9.add_movie(Movie("Transformers", 2007)) watchlist9.add_movie(Movie("Ice Age", 2002)) watchlist_iter1 = iter(watchlist9) assert repr(next(watchlist_iter1)) == "<Movie Moana, 2016>" assert repr(next(watchlist_iter1)) == "<Movie Transformers, 2007>" assert repr(next(watchlist_iter1)) == "<Movie Ice Age, 2002>"
def test_watch_list_next_out_of_range(): watchlist10 = WatchList() watchlist10.add_movie(Movie("Moana", 2016)) watchlist10.add_movie(Movie("Transformers", 2007)) watchlist10.add_movie(Movie("Ice Age", 2002)) watchlist_iter2 = iter(watchlist10) assert repr(next(watchlist_iter2)) == "<Movie Moana, 2016>" assert repr(next(watchlist_iter2)) == "<Movie Transformers, 2007>" assert repr(next(watchlist_iter2)) == "<Movie Ice Age, 2002>" with pytest.raises(StopIteration): print(next(watchlist_iter2))
def test_watch_list_select_movie_out_of_range(): watchlist8 = WatchList() watchlist8.add_movie(Movie("Moana", 2016)) watchlist8.add_movie(Movie("Transformers", 2007)) watchlist8.add_movie(Movie("Ice Age", 2002)) assert repr(watchlist8.select_movie_to_watch(3)) == "None"
def test_watch_list_select_movie(): watchlist7 = WatchList() watchlist7.add_movie(Movie("Moana", 2016)) watchlist7.add_movie(Movie("Transformers", 2007)) watchlist7.add_movie(Movie("Ice Age", 2002)) assert repr(watchlist7.select_movie_to_watch(2)) == "<Movie Ice Age, 2002>"
def test_watch_list_add_and_remove_movie(): watchlist6 = WatchList() watchlist6.add_movie(Movie("Moana", 2016)) watchlist6.remove_movie(Movie("Moana", 2016)) assert watchlist6.watch_list == [] assert watchlist6.size() == 0
def test_watch_list_remove_movie(): watchlist5 = WatchList() watchlist5.add_movie(Movie("Moana", 2016)) watchlist5.remove_movie(Movie("Transformers", 2007)) assert watchlist5.size() == 1 assert repr(watchlist5.first_movie_in_watchlist()) == "<Movie Moana, 2016>"
def test_watch_list_check_size(): watchlist4 = WatchList() watchlist4.add_movie(Movie("Moana", 2016)) watchlist4.add_movie(Movie("Ice Age", 2002)) assert watchlist4.size() == 2
def test_watch_list_add_same_movie(): watchlist3 = WatchList() watchlist3.add_movie(Movie("Moana", 2016)) watchlist3.add_movie(Movie("Moana", 2016)) assert repr(watchlist3.first_movie_in_watchlist()) == "<Movie Moana, 2016>"
def test_watch_list_add_movie(): watchlist2 = WatchList() watchlist2.add_movie(Movie("Moana", 2016)) assert repr(watchlist2.watch_list[0]) == "<Movie Moana, 2016>"
def test_watchlist_first_movie_in_watchlist(): watchlist = WatchList() assert watchlist.first_movie_in_watchlist() is None movie1 = Movie("Moana", 2016) watchlist.add_movie(movie1) assert watchlist.first_movie_in_watchlist() == movie1