def test_add_movie(self): watchlist = WatchList() watchlist.add_movie(Movie("Star Wars", 1999)) assert watchlist.size() == 1 # tests that add and size are working.. watchlist.add_movie(Movie("Star Wars", 1999)) assert watchlist.size( ) == 1 # test that indeed a duplicate movie can't be added
def test_remove_movie(self): watchlist = WatchList() movie1 = Movie("Star Wars", 1999) watchlist.add_movie(movie1) assert watchlist.size() == 1 watchlist.remove_movie(movie1) assert watchlist.size() == 0 # tests it removes a movie if it is there watchlist.remove_movie(movie1) assert watchlist.size( ) == 0 # tests it does nothing if movie not there
def test_size( self ): # this test is a bit silly since most the other tests rely on size working? watchlist = WatchList() assert watchlist.size() == 0 watchlist.remove_movie(Movie("Star Wars", 1999)) assert watchlist.size() == 0 # ^ I believe this is a great test, checking that remove_movie # doesn't subtract 1 from size unless a movie is indeed removed watchlist.add_movie(Movie("Star Wars", 1999)) assert watchlist.size() == 1 watchlist.add_movie(Movie("Ice Age", 2002)) assert watchlist.size() == 2 watchlist.add_movie(Movie("Guardians of the Galaxy", 2012)) assert watchlist.size() == 3 watchlist.remove_movie(Movie("Star Wars", 1999)) # ^ as per note above note, __eq___ is defined by same title and year, so this should do the job of removing assert watchlist.size( ) == 2 # test size reacts to movies being removed
def test_init_and_size(self): watchlist = WatchList() assert watchlist.size( ) == 0 # check starts with 0 movies in watchlist (assumes size works)