def test_does_not_accept_missing_key(self): lock = maze.Lock() lock.add_fitting_key("blue") accepts = lock.accepts("red") self.assertFalse(accepts)
def test_accepts_fitting_key(self): lock = maze.Lock() lock.add_fitting_key("blue") accepts = lock.accepts("blue") self.assertTrue(accepts)
def test_add_duplicate_fitting_key(self): lock = maze.Lock() lock.add_fitting_key("blue") lock.add_fitting_key("blue") self.assertEqual(lock.fitting_keys, ["blue"])
def test_cannot_unlock_door_missing_key(self): keyring = maze.Keyring() lock = maze.Lock() keyring.add_key("blue") lock.add_fitting_key("red") door = maze.Door(maze.Room(), maze.Room(), lock) can_unlock = keyring.can_unlock(door) self.assertFalse(can_unlock)
def test_can_unlock_door_having_key(self): key = "blue" keyring = maze.Keyring() lock = maze.Lock() keyring.add_key(key) lock.add_fitting_key(key) door = maze.Door(maze.Room(), maze.Room(), lock) can_unlock = keyring.can_unlock(door) self.assertTrue(can_unlock)
def test_cannot_move_through_locked_door_without_key(self): room_a = maze.Room("A") room_b = maze.Room("B") lock = maze.Lock() lock.add_fitting_key("blue") room_a.add_north_door(room_b, lock) player = maze.Player(room_a) player.move_through(room_a.north_door) self.assertEqual(player.current_room, room_a)