Example #1
0
 def test_first_movie_in_watchlist(self):
     watchlist = WatchList()
     movie1 = Movie("Moana", 2016)
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
     assert watchlist.first_movie_in_watchlist() == movie1
Example #2
0
 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
Example #3
0
    def test_select_movie_to_watch(self):
        watchlist = WatchList()
        movie1 = Movie("Moana", 2016)
        movie2 = Movie("Ice Age", 2002)
        movie3 = Movie("Guardians of the Galaxy", 2012)
        watchlist.add_movie(movie1)
        watchlist.add_movie(movie2)
        watchlist.add_movie(movie3)

        assert watchlist.select_movie_to_watch(0) == movie1
        # ^ note: could've just done "== Movie("Moana", 2016)" since __eq__ is defined by same title and year
        assert watchlist.select_movie_to_watch(1) == movie2
        assert watchlist.select_movie_to_watch(
            3) == None  # tests that it gives None if range out of bounds
Example #4
0
    def test_iterable(self):
        # note, a for loop uses '__iter__' (and '__next__' on the iterable object returned from __iter__)
        # so checking a for loop works, and correctly, is sufficient
        watchlist = WatchList()

        movie1 = Movie("Moana", 2016)
        movie2 = Movie("Ice Age", 2002)
        movie3 = Movie("Guardians of the Galaxy", 2012)
        watchlist.add_movie(movie1)
        watchlist.add_movie(movie2)
        watchlist.add_movie(movie3)

        # one way to do it
        a_list = [movie1, movie2, movie3]
        index = 0
        for movie in watchlist:
            assert movie == a_list[index]
            index += 1
Example #5
0
    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
Example #6
0
 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
Example #7
0
 def test_init_and_size(self):
     watchlist = WatchList()
     assert watchlist.size(
     ) == 0  # check starts with 0 movies in watchlist (assumes size works)