Ejemplo n.º 1
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room(1, 6)
        self.new_song = Song('The Wizard', 'Black Sabbath')
        self.new_guest = Guest('Toni', 600,
                               Song('Fear of the Dark', 'Iron Maiden'))

    def test_room_has_number(self):
        self.assertEqual(1, self.room.number)

    def test_room_has_a_playlist(self):
        self.assertEqual([], self.room.playlist)

    def test_add_song_to_playlist(self):
        self.room.add_song_to_playlist(self.new_song)
        self.assertEqual([self.new_song], self.room.playlist)

    def test_check_in_guest_to_room(self):
        self.room.check_in_guest_to_room(self.new_guest)
        self.assertEqual([self.new_guest], self.room.guests)

    def test_check_out_guest_from_room(self):
        self.room.check_in_guest_to_room(self.new_guest)
        self.room.check_out_guest_from_room(self.new_guest)
        self.assertEqual([], self.room.guests)

    def test_check_out_guest_from_empty_room(self):
        self.room.check_out_guest_from_room(self.new_guest)
        self.assertEqual([], self.room.guests)

    def test_check_in_guest_to_room_full_capacity(self):
        self.room.guests = [
            'guest1', 'guest2', 'guest3', 'guest4', 'guest5', 'guest6'
        ]
        self.assertEqual('Room is full.',
                         self.room.check_in_guest_to_room(self.new_guest))

    def test_put_fee_on_tab(self):
        self.room.put_fee_on_tab(50)
        self.assertEqual(50, self.room.tab)
Ejemplo n.º 2
0
class TestRoom(unittest.TestCase):

    def setUp(self):
        self.Large_Room = Room("Large Room", 12, 8, 0)
        self.Medium_Room = Room("Medium Room", 8, 10, 0)
        self.Small_Room = Room("Small Room", 4, 15, 0)

        self.Ewan = Guest("Ewan", 20, "Africa")
        self.Shufan = Guest("Shufan", 50, "Wannabe")
        self.Freddie = Guest("Freddie", 100, "Bohemian Rhapsody")
        self.Mariah = Guest("Mariah", 5000, "Never Gonna Give You Up")
        self.Floyd = Guest("Floyd", 150, "We Like To Party")
        self.Ross = Guest("Ross", 5, "Danger Zone")

        self.Bohemian_Rhapsody = Song("Bohemian Rhapsody", "Queen", "Classic Rock")
        self.Africa = Song("Africa", "Toto", "Classic Rock")
        self.Wannabe = Song("Wannabe", "Spice Girls", "90s Pop")
        self.Never_Gonna_Give_You_Up = Song("Never Gonna Give You Up", "Rick Astley", "80s Pop")
        self.We_Like_To_Party = Song("We Like To Party", "Vengaboys", "90s Pop")
        self.Danger_Zone = Song("Danger Zone", "Kenny Loggins", "80s Pop")


    def test_room_has_name(self):
        self.assertEqual("Large Room", self.Large_Room.name)

    def test_room_has_capacity(self):
        self.assertEqual(8, self.Medium_Room.capacity)

    def test_room_has_fee(self):
        self.assertEqual(15, self.Small_Room.fee)

    def test_can_guest_afford_room__true_if_can(self):
        self.assertEqual(True, self.Small_Room.can_guest_afford_room(self.Ewan, self.Small_Room))

    def test_can_guest_afford_room__false_if_cannot(self):
        self.assertEqual(False, self.Small_Room.can_guest_afford_room(self.Ross, self.Small_Room))

    def test_check_in_guest(self):
        self.Small_Room.check_in_guest(self.Mariah, self.Small_Room)
        self.assertEqual(1, self.Small_Room.count_guests_in_room())

    def test_cannot_check_in_guest_with_insufficient_funds(self):
        self.Small_Room.check_in_guest(self.Ross, self.Small_Room)
        self.assertEqual(0, self.Small_Room.count_guests_in_room())

    def test_cannot_check_in_more_guests_than_room_capacity1(self):
        self.Small_Room.check_in_guest(self.Mariah, self.Small_Room)
        self.Small_Room.check_in_guest(self.Freddie, self.Small_Room)
        self.Small_Room.check_in_guest(self.Shufan, self.Small_Room)
        self.Small_Room.check_in_guest(self.Floyd, self.Small_Room)
        self.Small_Room.check_in_guest(self.Ewan, self.Small_Room)
        self.assertEqual(4, self.Small_Room.count_guests_in_room())


    def test_funds_added_to_till_at_check_in(self):
        self.Small_Room.check_in_guest(self.Mariah, self.Small_Room)
        self.assertEqual(15, self.Small_Room.till)

    def test_check_in_multiple_guests(self):
        self.Small_Room.check_in_guest(self.Mariah, self.Small_Room)
        self.Small_Room.check_in_guest(self.Freddie, self.Small_Room)
        self.Small_Room.check_in_guest(self.Shufan, self.Small_Room)
        self.Small_Room.check_in_guest(self.Floyd, self.Small_Room)
        self.assertEqual(4, self.Small_Room.count_guests_in_room())

    def test_check_out_guest1(self):
        self.Small_Room.check_in_guest(self.Freddie, self.Small_Room)
        self.Small_Room.check_out_guest(self.Freddie, self.Small_Room)
        self.assertEqual(0, self.Small_Room.count_guests_in_room())

    def test_check_out_guest2(self):
        self.Small_Room.check_in_guest(self.Mariah, self.Small_Room)
        self.Small_Room.check_in_guest(self.Freddie, self.Small_Room)
        self.Small_Room.check_out_guest(self.Freddie, self.Small_Room)
        self.assertEqual(1, self.Small_Room.count_guests_in_room())

    def test_songs_can_be_added_to_playlist(self):
        self.Small_Room.add_song_to_playlist(self.Africa.title)
        self.assertEqual(1, self.Small_Room.count_songs_in_playlist())

    def test_multiple_songs_can_be_added_to_playlist(self):
        self.Small_Room.add_song_to_playlist(self.Africa.title)
        self.Small_Room.add_song_to_playlist(self.Wannabe.title)
        self.assertEqual(2, self.Small_Room.count_songs_in_playlist())

    def test_songs_can_be_removed_from_playlist(self):
        self.Small_Room.add_song_to_playlist(self.Africa.title)
        self.Small_Room.add_song_to_playlist(self.Wannabe.title)
        self.Small_Room.remove_song_from_playlist(self.Wannabe.title)
        self.assertEqual(1, self.Small_Room.count_songs_in_playlist())

    def test_guest_recognises_favourite_song(self):
        self.Small_Room.check_in_guest(self.Ewan, self.Small_Room)
        self.Small_Room.add_song_to_playlist(self.Africa)
        print(self.Small_Room.playlist)
        self.assertEqual("THAT'S MY JAM!", self.Small_Room.thats_my_jam(self.Ewan))
class TestRoom(unittest.TestCase):

# Testing that classes have been Setup OK

    def setUp(self):

        self.song_1 = Song('S001', 'Nickleback', 'Faraway')
        self.song_2 = Song('S002', 'The Weekend', 'Save Your Tears')
        self.song_3 = Song('S003', 'Daxten', 'Somewhere Out There')

        playlist_1 = [self.song_1, self.song_2]

        self.guest_1 = Guest('Joey Tribbiani', 100.00, 'Entrance Hallway', 'S001')
        self.guest_2 = Guest('Ross Gellar', 75.00, 'Entrance Hallway', 'S002')
        self.guest_3 = Guest('Chandler Bing', 50.00, 'Pop Paradise', 'S002')

        current_visitors_1 = [self.guest_1,  self.guest_2]

        self.room = Room('Pop Paradise', 30, 5.00, 0.00, current_visitors_1, playlist_1)

    def test_room_has__name(self):
        self.assertEqual('Pop Paradise', self.room.room_name)

    def test_room_has__capacity(self):
        self.assertEqual(30, self.room.capacity)

    def test_room_has__fee(self):
        self.assertEqual(5.00, self.room.fee)

    def test_room_has__total_income(self):
        self.assertEqual(0, self.room.total_income)

    def test_room_has__visitors(self):
        self.assertEqual(2, len(self.room.current_visitors))

    def test_room_has_playlist(self):
        self.assertEqual(2, len(self.room.playlist))

#  Testing Methods to add song to playlist

    def test_adding_song_to_a_playlist(self):
        self.room.add_song_to_playlist(self.song_3)
        self.assertEqual(3, len(self.room.playlist))

# Testing Methods needed for guests entering and leaving rooms

    # Basic Check-in/out 

    def test_basic_checkin(self):
        self.room.basic_checkin(self.guest_3)
        self.assertEqual(3, len(self.room.current_visitors))

    def test_basic_checkin(self):
        self.room.basic_checkout(self.guest_1)
        self.assertEqual(1, len(self.room.current_visitors))

    # Advanced Check-in/out

    def test_count_guests(self):
        self.assertEqual(2, self.room.count_visitors())    

    def test_room_can_take_fee(self):
        self.assertEqual(5.00, self.room.collects_fee(self.room.fee))

    # def test_advanced_checkin(self):
        # Add test here

    # def test_advanced_checkout(self):
        # Add test here


#  Test Method needed to check for guest favourite song.

    def test_check_favourite(self):
        self.assertEqual('Woo!', self.room.check_favourite(self.guest_3.favourite_song))