def test_two_checkedin_guests_are_not_assigned_the_same_room1(
         self, names, num):
     assume(len(names) < num)
     hotel = Hotel(num)
     guests = []
     for n in names:
         guests.append(hotel.checkin(n))
     for g1 in guests:
         for g2 in guests:
             assert g1 == g2 or \
                 hotel.room_of(g1.guest_name) != hotel.room_of(g2.guest_name)
 def test_after_checkin_guest_has_been_assigned_room2(self, names, num):
     assume(len(names) < num)
     hotel = Hotel(num)
     guests = []
     for n in names:
         guests.append(hotel.checkin(n))
     for g in guests:
         assert isinstance(hotel.room_of(g.guest_name), Room)
 def test_after_checkin_guest_has_been_assigned_room1(self, names, num):
     assume(len(names) < num)
     hotel = Hotel(num)
     guests = []
     for n in names:
         guests.append(hotel.checkin(n))
     for g in guests:
         assert hotel.room_of(g.guest_name).room_number == g.room_number
 def test_every_room_in_a_hotel_has_unique_lock(self, names, num):
     assume(len(names) < num)
     hotel = Hotel(num)
     locks = set()
     for n in names:
         hotel.checkin(n)
         lock = hotel.room_of(n).lock
         assert lock not in locks
         locks.add(lock)
 def test_checkedin_guest_has_a_room(self, names1, names2, num):
     assume(len(names1) < num)
     assume(names1 & names2)
     hotel = Hotel(num)
     for n in names1:
         hotel.checkin(n)
     for n in names2:
         if hotel.is_checkedin(n):
             assert isinstance(hotel.room_of(n), Room)
 def test_after_checkout_guest_doesnot_have_room(self, names, num):
     assume(len(names) < num)
     hotel = Hotel(num)
     for n in names:
         hotel.checkin(n)
     for n in names:
         hotel.checkout(n)
         with pytest.raises(ValueError):
             assert hotel.room_of(n)
 def test_assigned_room_cannot_be_opened_with_old_keycard(
         self, names1, names2, num):
     assume(len(names1) == num)
     assume(not names1 & names2)
     hotel = Hotel(num)
     room2keycard = {}
     for n in names1:
         g = hotel.checkin(n)
         room2keycard[g.room_number] = g.keycard
         # without this line, unused keycard can render the lock
         # unlockable to subsequent keycards
         hotel.room_of(n).lock.can_be_unlocked(g.keycard)
     for n1, n2 in zip(names1, names2):
         hotel.checkout(n1)
         g = hotel.checkin(n2)
         room = hotel.room_of(n2)
         assert room.lock.can_be_unlocked(g.keycard)
         assert not room.lock.can_be_unlocked(room2keycard[room.room_number])
         room2keycard[g.room_number] = g.keycard
 def test_two_checkedin_guests_are_not_assigned_the_same_room2(
         self, names1, names2, num):
     assume(len(names2 | names1) <= num)
     assume(names1 & names2)
     hotel = Hotel(num)
     name2guest = {}
     for n in names1:
         name2guest[n] = hotel.checkin(n)
     for n1 in names2:
         if n1 in names1:
             hotel.checkout(n1)
             name2guest.pop(n1)
         else:
             g1 = hotel.checkin(n1)
             for n2 in name2guest:
                 assert name2guest[n2].room_number != \
                     g1.room_number
                 assert hotel.room_of(n2) != \
                     hotel.room_of(g1.guest_name)
             name2guest[n1] = g1
 def test_guest_having_a_room_is_checkedin(self, names1, names2, num):
     assume(len(names1) < num)
     assume(names1 & names2)
     hotel = Hotel(num)
     for n in names1:
         hotel.checkin(n)
     for n in names2:
         try:
             if isinstance(hotel.room_of(n), Room):
                 assert hotel.is_checkedin(n)
         except ValueError:
             pass
Пример #10
0
 def test_first_key_of_keycard_is_same_as_the_second_key_of_previous_card(
         self, names1, names2, num):
     assume(len(names1) == num)
     assume(not names1 & names2)
     hotel = Hotel(num)
     room2keycard = {}
     for n in names1:
         g = hotel.checkin(n)
         room2keycard[g.room_number] = g.keycard
     for n1, n2 in zip(names1, names2):
         hotel.checkout(n1)
         g = hotel.checkin(n2)
         assert g.keycard.first_key == \
             room2keycard[hotel.room_of(g.guest_name).room_number].second_key
Пример #11
0
 def test_room_of_fails_with_invalid_guest_name_type(self, n, name):
     h = Hotel(n)
     with pytest.raises(ValueError):
         h.room_of(name)