def test_after_checkin_guest_appear_as_checkedin(self, names, num): assume(len(names) < num) hotel = Hotel(num) for n in names: hotel.checkin(n) for n in names: assert hotel.is_checkedin(n)
def test_after_checkout_guest_appears_checkedout(self, names, num): assume(len(names) < num) hotel = Hotel(num) for n in names: hotel.checkin(n) for n in names: hotel.checkout(n) assert not hotel.is_checkedin(n)
def test_checkout_of_not_checkedin_guest(self, names1, names2, num): assume(len(names1) < num) assume(not (names1 & names2)) hotel = Hotel(num) for n in names1: hotel.checkin(n) for n in names2: hotel.checkout(n)
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_two_guests_with_same_name_cannot_be_checkedin(self, names, num): assume(len(names) < num) hotel = Hotel(num) for n in names: hotel.checkin(n) for n in names: with pytest.raises(ValueError): hotel.checkin(n)
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_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_guests_with_unique_name_can_be_checkedin(self, names, num): assume(len(names) < num) hotel = Hotel(num) for n in names: hotel.checkin(n) for n in names: hotel.checkout(n) for n in names: hotel.checkin(n)
def test_checkout_of_checkedin_guest(self, names, num): assume(len(names) < num) hotel = Hotel(num) for n in names: hotel.checkin(n) for n in names: hotel.checkout(n) for n in names: assert not hotel.is_checkedin(n)
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_every_guest_in_a_hotel_has_unique_keycard(self, names, num): assume(len(names) < num) hotel = Hotel(num) keycards = set() for n in names: g = hotel.checkin(n) kc = g.keycard assert kc not in keycards keycards.add(kc)
def test_checkins_beyond_capacity_will_not_occur(self, names, num): assume(len(names) > num) hotel = Hotel(num) names = list(names) for n in names[0:num]: hotel.checkin(n) for n in names[num:]: with pytest.raises(FullCapacityError): hotel.checkin(n)
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_two_checkedin_guests_are_not_assigned_the_same_room_number( 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 g1.room_number != g2.room_number
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
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
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_is_checkedin_returns_true_when_checkedin(self): hotel = Hotel(10) guest = hotel.checkin("John") assert guest.is_checkedin(hotel)
def test_cannot_create_hotel_with_invalid_number_of_rooms2(self, n): with pytest.raises(Exception): Hotel(n)
def test_valid_hotel_creation(self, n): Hotel(n)
def test_checkin_is_possible_if_hotel_is_not_full(self, names, num): assume(len(names) < num) h = Hotel(num) for n in names: h.checkin(n)
def test_is_checkedin_fails_with_invalid_guest_name_type(self, n, name): h = Hotel(n) with pytest.raises(ValueError): h.is_checkedin(name)
def test_room_of_fails_with_invalid_guest_name_type(self, n, name): h = Hotel(n) with pytest.raises(ValueError): h.room_of(name)
def test_is_checkedin_returns_false_when_not_checkedin(self): hotel = Hotel(10) guest = hotel.checkin("John") hotel.checkout("John") assert not guest.is_checkedin(hotel)