class PlaylistTest(unittest.TestCase): def setUp(self): self.my_song = Song("Solder Of Frortune", "Deep Purple", "Stormbringer", "3:14") self.second_song = Song("I Stand Alone", "Godsmack", "Awake", "4:30") self.rock = Playlist("Rock songs", True) self.songs = [self.my_song, self.second_song] self.rock.add_songs(self.songs) def test_playlist_constructor(self): self.assertTrue(isinstance(self.rock, Playlist)) def test_add_song(self): self.assertEqual(self.rock.playlist, self.songs) def test_remove_song(self): self.rock.remove_song(self.my_song) self.assertEqual(self.rock.playlist, [self.second_song]) def test_remove_song_fail(self): self.rock.remove_song(self.my_song) with self.assertRaises(NoSuchSong): self.rock.remove_song(self.my_song) def test_add_songs(self): self.assertEqual(self.rock.playlist, self.songs) def test_total_length(self): self.assertEqual(self.rock.total_length(), "0:07:44") def test_artists(self): histogram = {"Deep Purple": 1, "Godsmack": 1} self.assertEqual(self.rock.artists(), histogram) def test_repeat(self): self.assertEqual(self.rock.next_song(), self.my_song) self.assertEqual(self.rock.next_song(), self.second_song) self.assertEqual(self.rock.next_song(), self.my_song) def test_no_more_songs(self): self.rock.change_repeat(False) self.assertEqual(self.rock.next_song(), self.my_song) self.assertEqual(self.rock.next_song(), self.second_song) with self.assertRaises(NoMoreSongs): self.rock.next_song() self.rock.change_shuffle(True) self.rock.next_song() self.rock.next_song() with self.assertRaises(NoMoreSongs): self.rock.next_song() def test_shuffle(self): self.rock.change_shuffle(True) bard = Song("The Bard's Song", "Blind Guardian", "Somwhere Far Beyond", "3:28") self.rock.add_song(bard) a = self.rock.next_song() b = self.rock.next_song() c = self.rock.next_song() self.assertTrue(a != b and c != a and c != b)