class TestGuest(unittest.TestCase): def setUp(self): self.guest = Guest("Cam", 100.00, "My Favourite Song", "My Favourite Artist") self.song = Song("My Favourite Song", "My Favourite Artist") self.room = Room(1, 10) def test_guest_has_name(self): self.assertEqual("Cam", self.guest.name) def test_guest_has_wallet(self): self.assertEqual(100.00, self.guest.wallet) def test_guest_has_fav_song(self): self.assertEqual("My Favourite Song", self.guest.fav_song) def test_guest_has_fav_artist(self): self.assertEqual("My Favourite Artist", self.guest.fav_artist) def test_pay_entry(self): self.guest.pay_entry(10.00) self.assertEqual(90.00, self.guest.wallet) def test_cheer_for_song(self): self.room.add_song(self.song) self.room.play_song() self.assertEqual("This is my favourite song, yeehaw", self.guest.cheer_for_favourite_song(self.song))
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): self.room1 = Room(1, 1) self.song1 = Song("Wouldn't it be nice", "Beach Boys") self.song2 = Song("Hello Nasty", "Beastie Boys") self.guest1 = Guest("Lewis Saunders", 30.00, self.song2) def test_room_has_number(self): self.assertEquals(1, self.room1.room_no) def test_room_has_capacity(self): self.assertEqual(1, self.room1.capacity) def test_check_in(self): self.room1.check_guest_into_room(self.guest1) self.assertEqual(1, len(self.room1.guests)) def test_check_in_at_capacity(self): self.room1.check_guest_into_room(self.guest1) self.room1.check_guest_into_room(self.guest1) self.assertEqual(1, len(self.room1.guests)) def test_check_out(self): self.room1.check_guest_into_room(self.guest1) self.room1.check_guest_out_of_room(self.guest1) self.assertEqual(0, len(self.room1.guests)) def test_add_song(self): self.room1.add_song(self.song1) self.assertEqual(1, len(self.room1.songs)) def test_fav_song(self): self.room1.add_song(self.song2) self.assertEqual("Oh now THIS is my JAM WHOO!", self.room1.check_fav_song(self.guest1)) def test_take_entry_fee_has_money(self): self.room1.take_entry(self.guest1, 10.00) self.assertEqual(10.0, self.room1.till) def test_take_entry_fee_not_enough_money(self): self.room1.take_entry(self.guest1, 31.00) self.assertEqual(0, self.room1.till)
class TestRoom(unittest.TestCase): def setUp(self): self.room = Room("Bollywood", 3, 5, 10) # self.room_2 = Room("Tollywood", 5, 10, 20) self.guest = Guest("Abhi", 20, 30) # self.guest_2 = Guest("Rakesh", 29, 20) # self.guest_3 = Guest("Tarun", 40, 60) self.song = Song("Sunoh", "Lucky Ali", 3.25, "Oh Sanam...") # self.song_2 = Song("Rockstar", "Mohit Chauhan", 4.00, "Saada Haq...") # self.song_3 = Song("Kedarnath", "Amit", 5.25, "Namo Shankara...") def test_room_has_name(self): self.assertEqual("Bollywood", self.room.name) def test_room_has_min_capacity(self): self.assertEqual("3", self.room.min_capacity) def test_room_has_cost(self): self.assertEqual("10", self.room.cost) def test_guest_check_in_room(self): guest = Guest("Abhi", 20, 30) self.room.check_in(guest) self.assertEqual(1, self.guest_count()) def test_guest_check_out_room(self): guest = Guest("Abhi", 20, 30) self.room.check_in(guest) self.room.check_out(guest) self.assertEqual(0, self.guest_count()) def test_room_can_add_a_song(self): self.room.add_song(self.song_1) self.assertEqual(1, self.room.total_song(self.song_1)) def test_add_waiting_list(self): self.room.add_to_waiting_list(self, guest) self.assertequal(1, self.room.waiting_list_length())
class TestRoom(unittest.TestCase): def setUp(self): self.room1 = Room("Room 1", 2, 5) self.room2 = Room("Room 2", 3, 7.5) self.guest1 = Guest("Sam", 5) self.guest2 = Guest("Bob", 10) self.guest3 = Guest("Joe", 15) self.song1 = Song("People Like Us") self.song2 = Song("Waterloo") self.song3 = Song("Ice Cream") def test_create_room(self): self.assertEqual("Room 1", self.room1.name) def test_add_song_to_room(self): self.room1.add_song(self.song1.name) self.assertEqual(1, len(self.room1.song_list)) def test_check_room_song_list(self): self.room1.add_song(self.song1.name) self.room1.add_song(self.song2.name) self.room1.add_song(self.song3.name) self.assertEqual(["People Like Us", "Waterloo", "Ice Cream"], self.room1.song_list) def test_check_in_guest(self): self.room1.check_in_guest(self.guest1.name) self.assertEqual(1, len(self.room1.guest_list)) def test_check_out_guest(self): self.room1.check_in_guest(self.guest1.name) self.room1.check_in_guest(self.guest2.name) self.room1.check_out_guest(self.guest1.name) self.assertEqual(1, len(self.room1.guest_list)) self.assertEqual(['Bob'], self.room1.guest_list) def test_check_room_capacity(self): self.assertEqual(2, self.room1.capacity) def test_room_capacity_exceeded(self): self.room1.check_in_guest(self.guest1.name) self.room1.check_in_guest(self.guest2.name) self.assertEqual("Room full!", self.room1.check_in_guest(self.guest3.name)) self.assertEqual(['Sam', 'Bob'], self.room1.guest_list) def test_charge_entry_fee(self): self.room1.charge_entry_fee(self.guest1) self.room1.charge_entry_fee(self.guest2) self.assertEqual(10, self.room1.cash_total) def test_cant_charge_entry_fee(self): self.room2.charge_entry_fee(self.guest1) self.room2.charge_entry_fee(self.guest2) self.assertEqual(False, self.room2.charge_entry_fee(self.guest1)) self.assertEqual(7.5, self.room2.cash_total)
class TestRoom(unittest.TestCase): def setUp(self): self.song_1 = Song("Highway to Hell", "AC/DC") self.song_2 = Song("The Clansman", "Iron Maiden") self.song_3 = Song("Ace of Spades", "Motorhead") self.songs = [self.song_1, self.song_2, self.song_3] self.jack = Guest("Jack", 20, self.song_1) self.victor = Guest("Victor", 15, self.song_2) self.isa = Guest("Isa", 100, self.song_3) self.guests = [self.jack, self.victor, self.isa] self.winston = Guest("Winston", 10, self.song_2) self.room = Room("The Metal Room", 3, 10) def test_room_has_name(self): self.assertEqual("The Metal Room", self.room.name) def test_room_has_no_guests_at_start(self): self.assertEqual(0, self.room.number_of_guests()) def test_room_has_no_songs_at_start(self): self.assertEqual(0, self.room.number_of_songs()) def test_room_has_capacity(self): self.assertEqual(3, self.room.get_capacity()) def test_room_till_starts_empty(self): self.assertEqual(0, self.room.till) def test_can_add_to_till(self): self.room.add_to_till(10) self.assertEqual(10, self.room.till) def test_can_check_in_guest(self): self.room.check_in_guest(self.victor) self.assertEqual(1, self.room.number_of_guests()) def test_can_check_in_multiple_guests(self): self.room.check_in_guests(self.guests) self.assertEqual(3, self.room.number_of_guests()) def test_can_check_guest_out(self): self.room.check_in_guest(self.victor) self.room.check_out_guest(self.victor) self.assertEqual(0, self.room.number_of_guests()) def test_can_add_song_to_room(self): song = Song("The Number of the Beast", "Iron Maiden") self.room.add_song(song) self.assertEqual(1, self.room.number_of_songs()) def test_can_add_multiple_songs_to_room(self): self.room.add_songs(self.songs) self.assertEqual(3, self.room.number_of_songs()) def test_room_has_free_spaces_equal_to_capacity_at_start(self): self.assertEqual(3, self.room.free_spaces()) def test_free_spaces_goes_down_when_guest_checked_in(self): self.room.check_in_guest(self.victor) self.assertEqual(2, self.room.free_spaces()) def test_cannot_check_in_guest_if_room_is_full(self): self.room.check_in_guests(self.guests) self.room.check_in_guest(self.winston) self.assertEqual(3, self.room.number_of_guests()) def test_cannot_check_in_multiple_guest_if_not_enough_free_space(self): self.room.check_in_guest(self.winston) self.room.check_in_guests(self.guests) self.assertEqual(1, self.room.number_of_guests()) def test_room_has_fee(self): self.assertEqual(10, self.room.fee) def test_can_check_guest_if_cannot_afford_it(self): self.room.check_in_guest(self.winston) self.assertEqual(1, self.room.number_of_guests()) self.assertEqual(10, self.room.till) self.assertEqual(0, self.winston.cash) def test_cannot_check_guest_in_if_cannot_afford_it(self): tam = Guest("Tam", 2, self.song_1) self.room.check_in_guest(tam) self.assertEqual(0, self.room.number_of_guests()) self.assertEqual(0, self.room.till) self.assertEqual(2, tam.cash) def test_cheers_for_guests_fave_song(self): self.room.check_in_guest(self.winston) songs = self.songs self.assertEqual("Whoo Hoo!", self.room.guests[0].cheer(songs))
class TestRoom(unittest.TestCase): def setUp(self): self.room_01 = Room("The Party Room", 4, 5.00) self.room_02 = Room("The Date Room", 2, 10.00) self.drink_01 = Drink("Gaffer's Home Brew", 5, 1.20) self.drink_02 = Drink("Dry Martini", 2, 3.40) self.drink_03 = Drink("Margarita", 2, 3.40) self.drink_04 = Drink("Manhattan", 2, 3.40) self.drink_05 = Drink("Sazerac", 3, 4.25) self.drink_06 = Drink("Highball", 1, 2.60) self.song_01 = Song("Come on Eileen", "Dexys Midnight Runners") self.song_02 = Song("Mr Blue Sky", "ELO") self.song_03 = Song("Bat out of Hell", "Meatloaf") self.song_04 = Song("You're so Vain", "Carly Simon") self.song_05 = Song("Tubthumping", "Chumbawamba") self.song_06 = Song("Accidentally in Love", "Counting Crows") self.guest_01 = Guest("Frodo Baggins", 51, 30.50, self.song_04, self.drink_06) self.guest_02 = Guest("Samwise Gamgee", 36, 10.75, self.song_03, self.drink_01) self.guest_03 = Guest("Meriadoc Brandybuck", 37, 23.60, self.song_01, self.drink_05) self.guest_04 = Guest("Peregrin Took", 29, 17.85, self.song_05, self.drink_03) def test_room_has_name(self): name = self.room_01.name self.assertEqual("The Party Room", name) def test_room_pax_starts_at_0(self): pax = len(self.room_01.guests) self.assertEqual(0, pax) def test_room_songs_start_at_0(self): songs = len(self.room_01.songs) self.assertEqual(0, songs) def test_room_has_guest_limit(self): limit = self.room_02.limit self.assertEqual(2, limit) def test_room_bill_starts_at_0(self): self.assertEqual(0.00, self.room_01.bill) def test_room_can_check_out_customer(self): self.room_02.check_in_guest(self.guest_02) self.assertEqual(1, len(self.room_02.guests)) def test_room_has_entry_fee(self): fee = self.room_01.fee self.assertEqual(5, fee) def test_room_can_check_out_guest(self): self.room_02.check_in_guest(self.guest_02) self.room_02.check_out_guest(self.guest_02) self.assertEqual(0, len(self.room_02.guests)) def test_empty_room(self): self.room_02.check_in_guest(self.guest_02) self.room_02.check_in_guest(self.guest_04) self.room_02.empty_room() self.assertEqual(0, len(self.room_02.guests)) def test_song_can_be_added_to_room(self): self.room_02.add_song(self.song_02) self.assertEqual(1, len(self.room_02.songs)) def test_full_room_will_not_take_guest(self): self.room_02.check_in_guest(self.guest_03) self.room_02.check_in_guest(self.guest_04) self.room_02.check_in_guest(self.guest_02) self.assertEqual(2, len(self.room_02.guests)) def test_bill_can_increase(self): self.room_01.increase_bill(3.75) self.assertEqual(round(self.room_01.bill, 2), 3.75)
class TestRoom(unittest.TestCase): def setUp(self): self.room = Room("Cover Your Ears!", 15, 10) self.room_small = Room("Tight Squeeze", 1, 15) self.song = Song("Hold a chicken in the air") self.song_not_fav = Song("Put that chair back") # fav_song should be song object, not just a string self.guest = Guest("Sid The Sloth", 33.25, "Hold a chicken in the air") # like... # self.guest = Guest("Sid The Sloth", 33.25, song) # fav_song should be song object, not just a string self.guest_no_money = Guest("Scrooge", 3.99, "Yeah, right!") # like... # self.guest_no_money = Guest("Scrooge", 3.99, song_not_fav) def test_room_has_name(self): self.assertEqual("Cover Your Ears!", self.room.name) def test_room_has_capacity(self): self.assertEqual(15, self.room.capacity) def test_room_has_entry_fee(self): self.assertEqual(10, self.room.entry_fee) def test_room_start_at_0(self): self.assertEqual(0, self.room.guest_count()) def test_can_check_in_guest(self): self.room.check_in(self.guest) self.assertEqual(1, self.room.guest_count()) def test_can_find_guess_by_name(self): # Add guest to room self.room.check_in(self.guest) # 'Extract' guest object from room, using their name guest = self.room.check_out("Sid The Sloth") self.assertEqual("Sid The Sloth", guest.name) def test_song_start_at_0(self): self.assertEqual(0, self.room.song_count()) def test_can_add_song(self): self.room.add_song(self.song) self.assertEqual(1, self.room.song_count()) def test_capacity_for_more_guests(self): self.assertEqual(True, self.room.check_capacity()) def test_capacity_no_more_guests(self): self.room_small.check_in(self.guest) self.assertEqual(False, self.room_small.check_capacity()) def test_guest_has_funds(self): self.assertEqual(True, self.room_small.confirm_guest_has_funds(self.guest)) def test_guest_has_not_funds(self): self.assertEqual( False, self.room.confirm_guest_has_funds(self.guest_no_money)) def test_take_fee_from_guest(self): # Take fee from the guest self.room.take_fee_from_guest(self.guest) # The guest should now have 10 less than before self.assertEqual(23.25, self.guest.money) def test_take_no_fee_from_guest(self): # Try to take fee from the guest - this ones doesn't have sufficient funds self.room_small.take_fee_from_guest(self.guest_no_money) # The guest should still have the same amount of money as before. self.assertEqual(3.99, self.guest_no_money.money) def test_for_guest_fav_song(self): self.room.add_song(self.song) self.assertEqual("Whoo!", self.room.look_for_guest_fav_song(self.guest)) def test_for_no_guest_fav_song(self): self.room.add_song(self.song_not_fav) self.assertEqual(None, self.room.look_for_guest_fav_song(self.guest))
class TestRoom(unittest.TestCase): def setUp(self): self.song = Song("Don't Stop Believin'", "Journey") self.room = Room(1, 2, 10) self.guest = Guest("Tim", 32, 20.5, self.song) self.guest_2 = Guest("Beyonce", 38, 3.2) def test_room_has_number(self): self.assertEqual(1, self.room.number) def test_room_has_capacity(self): self.assertEqual(2, self.room.capacity) def test_room_has_entry_fee(self): self.assertEqual(10, self.room.entry_fee) def test_room_has_entry_fee_default(self): no_fee_argument_room = Room(1, 2) self.assertEqual(0, no_fee_argument_room.entry_fee) def test_room_has_bartab(self): self.assertEqual(Bartab, type(self.room.bartab)) def test_room_has_songs_property(self): self.assertEqual(list, type(self.room.songs)) def test_room_has_guests_property(self): self.assertEqual(list, type(self.room.guests)) def test_can_check_in_guest(self): self.room.check_in_guest(self.guest) self.assertEqual(1, len(self.room.guests)) def test_doesnt_check_in_guest_less_money_than_entry_fee(self): self.guest.wallet = 0 self.room.check_in_guest(self.guest) self.assertEqual(0, len(self.room.guests)) def test_cant_check_in_guest_over_capacity(self): self.room.check_in_guest(self.guest) self.room.check_in_guest(self.guest) self.room.check_in_guest(self.guest) self.assertEqual(2, len(self.room.guests)) def test_guest_check_in_reduces_guest_money_if_fee(self): self.room.check_in_guest(self.guest) self.assertEqual(10.5, self.guest.wallet) def test_check_in_produces_bartab_receipt_item(self): self.room.check_in_guest(self.guest) self.assertEqual(1, len(self.room.bartab.receipt)) def test_check_in_with_fav_song_cheers(self): self.room.add_song(self.song) self.assertEqual("Whoo! They have my favourite song!", self.room.check_in_guest(self.guest)) def test_check_in_without_fav_song_does_not_cheer(self): self.assertEqual(None, self.room.check_in_guest(self.guest)) def test_can_check_out_guest_exists(self): self.room.check_in_guest(self.guest) self.room.check_out_guest(self.guest) self.assertEqual(0, len(self.room.guests)) def test_can_check_out_guest_doesnt_exists(self): self.room.check_in_guest(self.guest) self.room.check_out_guest(self.guest_2) self.assertEqual(1, len(self.room.guests)) def test_can_add_songs_to_room(self): self.room.add_song(self.song) self.assertEqual(1, len(self.room.songs))
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 TestGuest(unittest.TestCase): def setUp(self): self.guest = Guest("Bob", 10, "Eurovison Sing-Along") self.room1 = Room("Room 1", 2, 5) def test_create_guest(self): self.assertEqual("Bob", self.guest.name) def test_get_favorite_song(self): self.assertEqual("Eurovison Sing-Along", self.guest.favourite_song) def test_can_pay_money(self): self.assertEqual(True, self.guest.check_enough_money(5)) def test_cant_pay_money(self): self.assertEqual(False, self.guest.check_enough_money(15)) def test_pay_money(self): self.guest.pay_money(5) self.assertEqual(5, self.guest.money) def test_cheer_favorite_song(self): # self.room1 = Room("Room 1", 2, 5) self.room1.add_song("Waterloo") self.room1.add_song("Ice Cream") self.room1.add_song("Eurovison Sing-Along") self.room1.add_song("Nobody's Love") self.assertEqual("WHOOOOHOOO!", self.guest.cheer_favourite_song(self.room1)) def test_no_favorite_song_playing(self): # self.room1 = Room("Room 1", 2, 5) self.room1.add_song("Sucker") self.room1.add_song("Say Something") self.room1.add_song("Don't Be Sad") self.room1.add_song("Love You More") self.assertEqual("Sad face :(", self.guest.cheer_favourite_song(self.room1))
class TestGuest(unittest.TestCase): def setUp(self): self.room_01 = Room("The Party Room", 4, 5.00) self.room_02 = Room("The Date Room", 2, 10.00) self.drink_01 = Drink("Gaffer's Home Brew", 5, 1.20) self.drink_02 = Drink("Dry Martini", 2, 3.40) self.drink_03 = Drink("Margarita", 2, 3.40) self.drink_04 = Drink("Manhattan", 2, 3.40) self.drink_05 = Drink("Sazerac", 3, 4.25) self.drink_06 = Drink("Highball", 1, 2.60) self.song_01 = Song("Come on Eileen", "Dexys Midnight Runners") self.song_02 = Song("Mr Blue Sky", "ELO") self.song_03 = Song("Bat out of Hell", "Meatloaf") self.song_04 = Song("You're so Vain", "Carly Simon") self.song_05 = Song("Tubthumping", "Chumbawamba") self.song_06 = Song("Accidentally in Love", "Counting Crows") self.guest_01 = Guest("Frodo Baggins", 51, 30.50, self.song_04, self.drink_06) self.guest_02 = Guest("Samwise Gamgee", 36, 10.75, self.song_03, self.drink_01) self.guest_03 = Guest("Meriadoc Brandybuck", 37, 23.60, self.song_01, self.drink_05) self.guest_04 = Guest("Peregrin Took", 29, 17.85, self.song_05, self.drink_03) def test_guest_has_name(self): name = self.guest_01.name self.assertEqual("Frodo Baggins", name) def test_guest_has_age(self): age = self.guest_01.age self.assertEqual(51, age) def test_guest_has_wallet(self): wallet = round(self.guest_02.wallet, 2) self.assertEqual(10.75, wallet) def test_wallet_can_decrease(self): self.guest_04.decrease_wallet(4.85) self.assertEqual(round(self.guest_04.wallet, 2), 13.00) def test_guest_can_pay_entry(self): self.guest_03.pay_entry(self.room_01) self.assertEqual(round(self.guest_03.wallet, 2), 18.60) self.assertEqual(round(self.room_01.bill, 2), 5.00) def test_guest_has_favourite_song(self): fav_song = self.guest_01.fav_song self.assertEqual(self.song_04, fav_song) def test_reacts_to_fav_song(self): self.room_01.add_song(self.song_01) reaction = self.guest_03.react_to_song(self.room_01) self.assertEqual("Wahey!", reaction) def test_guest_has_favourite_drink(self): fav = self.guest_02.fav_drink self.assertEqual(self.drink_01, fav) def test_guest_can_afford_drink_false(self): self.guest_02.pay_entry(self.room_02) result = self.guest_02.can_afford(self.drink_01) self.assertEqual(False, result) def test_guest_can_afford_drink_true(self): self.guest_01.pay_entry(self.room_02) result = self.guest_01.can_afford(self.drink_01) self.assertEqual(True, result) def test_guest_singing_prowess_starts_at_0(self): confidence = self.guest_02.singing_prowess self.assertEqual(0, confidence) def test_prowess_can_increase(self): self.guest_02.increase_prowess(5) self.assertEqual(5, self.guest_02.singing_prowess) def test_customer_can_buy_drink(self): self.guest_03.pay_entry(self.room_01) self.guest_03.buy_drink(self.drink_05, self.room_01) self.assertEqual(14.35, round(self.guest_03.wallet, 2)) self.assertEqual(9.25, round(self.room_01.bill, 2)) self.assertEqual(3, self.guest_03.singing_prowess)
class TestRoom(unittest.TestCase): def setUp(self): self.room_1 = Room("Yellow Submarine", 8, 50) self.room_2 = Room("Purple Rain", 10, 60) self.room_3 = Room("Blue Monday", 12, 70) self.room_4 = Room("Black and White Town", 15, 80) self.room_5 = Room("Pink Cadillac", 20, 90) self.room_6 = Room("99 Red Baloons", 22, 100) self.guest_1 = Guest("Eddie Vedder", "Black", 500) self.guest_2 = Guest("Kurt Cobain", "Teen Spirit", 300) self.guest_3 = Guest("Billy Corgan", "1979", 500) self.guest_4 = Guest("Chris Cornell", "The Day I Tried To Live", 385) self.guest_5 = Guest("Zack De la Rocha", "Testify", 500) self.guest_6 = Guest("Chino Moreno", "Change In the House of Flies", 350) self.guest_7 = Guest("Shirley Manson", "Only Happy When it Rains", 500) self.guest_8 = Guest("PJ Harvey", "This is Love", 300) self.song_1 = Song("Tether", "Chvrches", "Synth Pop") self.song_2 = Song("Questions and Answers", "Biffy Clyro", "Alt Rock") self.song_3 = Song("The Wrong Car", "The Twilight Sad", "Post Punk") self.song_4 = Song("Fast Blood", "Frightened Rabbit", "Indie Folk") self.song_5 = Song("Scottish Fiction", "Idlewild", "Indie") # @unittest.skip("Delete this line to run the test") def test_room_name(self): self.assertEqual("Yellow Submarine", self.room_1.name) # @unittest.skip("Delete this line to run the test") def test_check_in(self): self.room_1.check_in(self.guest_1.name) self.assertEqual(1, len(self.room_1.guests)) # @unittest.skip("Delete this line to run the test") def test_check_out(self): self.room_1.check_in(self.guest_1.name) self.room_1.check_in(self.guest_2.name) self.room_1.check_out(self.guest_1.name) self.assertEqual(1, len(self.room_1.guests)) # @unittest.skip("Delete this line to run the test") def test_add_song(self): self.room_1.add_song(self.song_1.title, self.song_1.artist, self.song_1.genre) self.room_1.add_song(self.song_2.title, self.song_2.artist, self.song_2.genre) self.assertEqual(2, len(self.room_1.playlist)) # @unittest.skip("Delete this line to run the test") def test_room_at_capacity(self): self.room_1.check_in(self.guest_1.name) self.room_1.check_in(self.guest_2.name) self.room_1.check_in(self.guest_3.name) self.room_1.check_in(self.guest_4.name) self.room_1.check_in(self.guest_5.name) self.room_1.check_in(self.guest_6.name) self.room_1.check_in(self.guest_7.name) self.room_1.check_in(self.guest_8.name) self.assertEqual("Sorry, you can't go in to that room, it's full.", self.room_1.room_at_capacity()) # @unittest.skip("Delete this line to run the test") def test_charge_for_share_of_room(self): self.room_1.check_in(self.guest_1) self.room_1.check_in(self.guest_2) self.room_1.check_in(self.guest_3) self.room_1.check_in(self.guest_4) self.room_1.charge_for_share_of_room(self.guest_1) self.assertEqual(487.5, self.guest_1.wallet) # @unittest.skip("Delete this line to run the test") def test_search_for_song(self): self.room_1.add_song(self.song_1.title, self.song_1.artist, self.song_1.genre) self.room_1.add_song(self.song_2.title, self.song_2.artist, self.song_2.genre) self.room_1.add_song(self.song_3.title, self.song_1.artist, self.song_1.genre) self.room_1.add_song(self.song_4.title, self.song_2.artist, self.song_2.genre) self.room_1.add_song(self.song_5.title, self.song_2.artist, self.song_2.genre) self.room_1.playlist = [self.song_1, self.song_2, self.song_3, self.song_4, self.song_5] found_track = self.room_1.search_for_song("The Wrong Car") self.assertEqual("The Wrong Car", found_track)
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)