コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
 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)
コード例 #4
0
 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)
コード例 #5
0
 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)
コード例 #6
0
 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
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
0
 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
コード例 #15
0
 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
コード例 #16
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
コード例 #17
0
 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
コード例 #18
0
 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
コード例 #19
0
 def test_is_checkedin_returns_true_when_checkedin(self):
     hotel = Hotel(10)
     guest = hotel.checkin("John")
     assert guest.is_checkedin(hotel)
コード例 #20
0
 def test_cannot_create_hotel_with_invalid_number_of_rooms2(self, n):
     with pytest.raises(Exception):
         Hotel(n)
コード例 #21
0
 def test_valid_hotel_creation(self, n):
     Hotel(n)
コード例 #22
0
 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)
コード例 #23
0
 def test_is_checkedin_fails_with_invalid_guest_name_type(self, n, name):
     h = Hotel(n)
     with pytest.raises(ValueError):
         h.is_checkedin(name)
コード例 #24
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)
コード例 #25
0
 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)