class TestRoom(unittest.TestCase): def setUp(self): # self.room1 = Room("Osaka", 5, 20) self.room = Room("Tokyo", 3, 20) self.song1 = Song("Fleetwood Mac", "The Chain") self.song2 = Song("Dubliners", "The Rocky Road to Dublin") self.song3 = Song("Kate Bush", "Wuthering Heights") self.guest1 = Guest("Stevie", 39, "The Chain", 10) self.guest2 = Guest("Luke", 45, "The Rocky Road to Dublin", 150) self.guest3 = Guest("Cathy", 31, "Wuthering Heights", 200) def test_room_name(self): room_name = "Tokyo" self.assertEqual(room_name, self.room.name) def test_room_capacity(self): self.assertEqual(3, self.room.capacity) def test_room_fee(self): self.assertEqual(20, self.room.fee) def test_song_start_at_0(self): self.assertEqual(0, self.room.song_count()) def test_add_song(self): self.room.add_song(self.song1) self.assertEqual(1, self.room.song_count()) def test_room_current_capacity(self): self.assertEqual(0, self.room.current_capacity()) def test_add_guest(self): self.room.add_guest(self.guest1) self.assertEqual(1, self.room.current_capacity()) def test_find_song(self): song = "The Chain" self.room.find_song(self.room.song_list) self.assertEqual(song, self.guest1.fav_song) def test_check_in(self): self.room.check_in(self.guest1) self.assertEqual(["Stevie"], self.room.guest_list)
class TestRoom(unittest.TestCase): def setUp(self): # Set up song and room objecs self.guest = Guest("Santa") self.guest1 = Guest("Emma") self.guest2 = Guest("Simon") self.guest3 = Guest("Anthony") self.guest4 = Guest("Lauchy") self.song = Song("Always look on the bright side of life", "Monty Python") self.song1 = Song("Bohemian Rhapsody", "Queen") self.song2 = Song("Can't get you out of my head", "Kylie Minogue") self.song3 = Song("I wanna dance with sombody", "Whitney Houston") self.song4 = Song("Build me up buttercup", "The Foundations") self.song5 = Song("Achy breaky heart", "Billy Ray Sirus") self.song6 = Song("Baggy Trousers", "Madness") self.song7 = Song("I believe in a thing called love", "The Darkness") self.song8 = Song("Video games", "Lana Del Rey") self.song9 = Song("Hurt", "Christina Aguilera") self.song10 = Song("Let it go", "Frozen") self.song11 = Song("Shake it off", "Taylor Swift") self.song12 = Song("Baby shark", "Pink Fong") # Set up playlist for rooms self.room1_playlist = [self.song1, self.song2] self.room2_playlist = [self.song4, self.song5] self.room3_playlist = [self.song7, self.song8] self.room4_playlist = [self.song10, self.song11] self.room1 = Room("Popular Songs", self.room1_playlist, [], self.song, self.guest) self.room2 = Room("Easy Songs", self.room2_playlist, [self.guest2, self.guest3], self.song, self.guest) self.room3 = Room("Hard Songs", self.room3_playlist, [], self.song, self.guest) self.room4 = Room("Kids Songs", self.room4_playlist, [], self.song, self.guest) # Initial Tests def test_room_has_name(self): self.assertEqual("Easy Songs", self.room2.name) def test_another_room__number(self): self.assertEqual("Kids Songs", self.room4.name) def test_check_room_has_guestlidt(self): self.assertEqual(0, len(self.room1.guestlist)) def test_check_add_guest_to_guestlist(self): self.room1.add_guest(self.guest1) self.assertEqual(1, len(self.room1.guestlist)) def test_remove_guest_from_room(self): self.room2.remove_guest(self.guest3) self.assertEqual(1, len(self.room2.guestlist)) def test_room_has_playlist(self): self.assertEqual(2, len(self.room3.playlist)) def test_add_song_to_playlist(self): self.room3.playlist_add(self.song9) self.assertEqual(3, len(self.room3.playlist))
class TestRoom(unittest.TestCase): def setUp(self): self.room = Room("Room 1", 3, 5.00, 100.00) self.song_1 = Song("Africa", "Toto") self.song_2 = Song("Purple Rain", "Prince") self.song_3 = Song("Dancing Queen", "Abba") self.guest_1 = Guest("Elton", 30.00, "Purple Rain") self.guest_2 = Guest("Dolly", 40.00, "Wannabe") self.guest_3 = Guest("Kylie", 50.00, "Africa") self.guest_4 = Guest("Bruce", 50.00, "Enter Sandman") def test_room_has_name(self): self.assertEqual("Room 1", self.room.room_name) def test_room_start_with_empty_song_list(self): self.assertEqual(0, len(self.room.song_list)) def test_room_starts_with_empty_guest_list(self): self.assertEqual(0, len(self.room.guests)) def test_can_add_song(self): self.room.add_song(self.song_1) self.room.add_song(self.song_2) self.assertEqual(2, len(self.room.song_list)) def test_can_add_guest(self): self.room.add_guest(self.guest_1) self.assertEqual(1, len(self.room.guests)) def test_can_remove_guest(self): self.room.add_guest(self.guest_1) self.room.add_guest(self.guest_2) self.room.remove_guest(self.guest_1) self.assertEqual(1, len(self.room.guests)) def test_room_has_guest_limit(self): self.room.add_guest(self.guest_1) self.room.add_guest(self.guest_2) self.room.add_guest(self.guest_3) self.assertEqual("Sorry, no space left!", self.room.add_guest(self.guest_4)) def test_room_can_take_entry_fee(self): self.room.add_guest(self.guest_1) self.room.add_guest(self.guest_2) self.room.take_entry_fee(self.room.entry_fee) self.assertEqual(110.00, self.room.total_cash) self.assertEqual(25.00, self.guest_1.wallet) self.assertEqual(35.00, self.guest_2.wallet) def test_guest_can_search_for_favourite_song_found(self): self.room.add_song(self.song_1) self.room.add_song(self.song_2) self.room.add_song(self.song_3) self.room.add_guest(self.guest_1) self.room.add_guest(self.guest_2) self.assertEqual("Whoo!", self.room.search_for_favourite_song(self.guest_1)) def test_guest_can_search_for_favourite_song_not_found(self): self.room.add_song(self.song_1) self.room.add_song(self.song_2) self.room.add_song(self.song_3) self.room.add_guest(self.guest_1) self.room.add_guest(self.guest_2) self.assertEqual("I don't like this room.", self.room.search_for_favourite_song(self.guest_2))
class TestRoom(unittest.TestCase): def setUp(self): # Drinks self.drink_1 = Drink("Tennents", 3.50, True) self.drink_2 = Drink("Coca Cola", 2.00, False) # Songs self.song_1 = Song("Shake It Off", "Taylor Swift", 219) self.song_2 = Song("Sweet Caroline", "Neil Diamond", 201) self.song_3 = Song("YMCA", "Village People", 287) self.song_4 = Song("I'm Gonna Be (500 Miles)", "The Proclaimers", 217) # Guests self.guest_1 = Guest("Alice", 43, 30.00, self.song_3) self.guest_2 = Guest("Bob", 45, 60.00, self.song_3) self.guest_3 = Guest("Charlie", 21, 15.50, self.song_3) self.guest_4 = Guest("David", 17, 10.00, self.song_2) self.guest_5 = Guest("Emma", 24, 29.95, self.song_2) self.guest_6 = Guest("Freddie", 31, 5.00, self.song_1) group_1 = [self.guest_1, self.guest_2, self.guest_3, self.guest_4, self.guest_5] # Rooms self.room_1 = Room(1, 4) self.room_2 = Room(2, 5) self.room_2.guests = group_1 # Class attribute tests def test_room_has_number(self): self.assertEqual(1, self.room_1.room_number) def test_room_has_empty_playlist(self): self.assertEqual(0, len(self.room_1.playlist)) def test_room_has_no_guests(self): self.assertEqual(0, len(self.room_1.guests)) # Methods that affect playlist def test_song_added_to_playlist(self): self.room_1.add_song(self.song_1) self.assertEqual(1, len(self.room_1.playlist)) def test_add_song_3_times__returns_playlist_len_3(self): self.room_1.add_song(self.song_1) self.room_1.add_song(self.song_1) self.room_1.add_song(self.song_1) self.assertEqual(3, len(self.room_1.playlist)) def test_favourite_song_on_playlist__returns_message(self): group_2 = [self.guest_1, self.guest_4, self.guest_6] self.room_1.guests = group_2 self.room_1.add_song(self.song_1) self.assertEqual("Whoo!", self.room_1.favourite_song_on_playlist(self.guest_1)) def test_favourite_song_on_playlist__returns_None(self): group_2 = [self.guest_1, self.guest_4, self.guest_6] self.room_1.guests = group_2 self.room_1.add_song(self.song_4) self.assertIsNone(self.room_1.favourite_song_on_playlist(self.guest_1)) def test_play_song__removes_played_song(self): playlist_1 = [self.song_1, self.song_2, self.song_3] self.room_1.playlist = playlist_1 self.assertEqual("Now playing: Shake It Off by Taylor Swift", self.room_1.play_song(self.song_1)) self.assertEqual(2, len(self.room_1.playlist)) # Methods that affect number of guests in room def test_add_guest_to_room(self): self.room_1.add_guest(self.guest_1, self.room_1) self.assertEqual(1, len(self.room_1.guests)) def test_add_guest_4_times__returns_guests_len_4(self): self.room_1.add_guest(self.guest_2, self.room_1) self.room_1.add_guest(self.guest_2, self.room_1) self.room_1.add_guest(self.guest_2, self.room_1) self.room_1.add_guest(self.guest_2, self.room_1) self.assertEqual(4, len(self.room_1.guests)) def test_remove_guest_from_room(self): self.room_2.remove_guest(self.guest_3) self.assertEqual(4, len(self.room_2.guests)) def test_remove_2_guests_from_room(self): self.room_2.remove_guest(self.guest_1) self.room_2.remove_guest(self.guest_5) self.assertEqual(3, len(self.room_2.guests)) def test_add_guest__rejects_guest_cannot_afford_entry(self): self.room_1.add_guest(self.guest_1, self.room_1) self.room_1.add_guest(self.guest_6, self.room_1) self.assertEqual(1, len(self.room_1.guests)) def test_add_guest__rejects_guest_room_at_capacity(self): self.room_2.add_guest(self.guest_1, self.room_2) self.assertEqual(5, len(self.room_2.guests)) # Methods that check room capacity def test_check_capacity_for_under_capacity__returns_True(self): has_capacity = self.room_1.check_capacity(self.room_1) self.assertEqual(True, has_capacity) def test_check_capacity_for_at_capacity__returns_False(self): at_capacity = self.room_2.check_capacity(self.room_2) self.assertEqual(False, at_capacity) # Methods that affect tab def test_add_drink_to_tab__adds_drink_price_to_tab(self): self.room_1.add_drink_to_tab(self.guest_2, self.drink_1) self.assertEqual(3.50, self.room_1.tab) self.assertEqual(56.50, self.guest_2.wallet) def test_add_entry_fee_to_tab__adds_entry_fee_to_tab(self): self.room_1.add_entry_fee_to_tab(self.guest_2) self.assertEqual(9.95, self.room_1.tab) self.assertEqual(50.05, self.guest_2.wallet) def test_clear_room__removes_guests_playlist_tab(self): self.room_1.add_guest(self.guest_2, self.room_1) self.assertEqual(1, len(self.room_1.guests)) self.assertEqual(9.95, self.room_1.tab) self.assertEqual(50.05, self.guest_2.wallet) self.room_1.add_song(self.song_1) self.assertEqual(1, len(self.room_1.playlist)) self.room_1.clear_room(self.room_1) self.assertEqual(0, len(self.room_1.guests)) self.assertEqual(0, len(self.room_1.playlist)) self.assertEqual(0.00, self.room_1.tab)