Пример #1
0
    def test_build_floor(self):
        """Base case for building a floor onto a building.

        We create a custom board and place two workers on it, and
        test building floors at different levels & from
        different positions on the same cell.
        """
        board = Board([[0, 1, 2, 3, 4, 0]], {
            self.workers[0]: (0, 0),
            self.workers[1]: (0, 2)
        })
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.EAST), 1)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[1]),
                             Direction.WEST), 1)
        board.build_floor(self.workers[0], Direction.EAST)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.EAST), 2)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[1]),
                             Direction.WEST), 2)
        board.build_floor(self.workers[1], Direction.WEST)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[1]),
                             Direction.WEST), 3)
Пример #2
0
 def test_get_height_off_board(self):
     """Case for getting the height of a building off of the board."""
     board = Board([[0, 3]], {self.workers[0]: (0, 0)})
     with self.assertRaises(IndexError) as context:
         board.get_height(board.worker_position(self.workers[0]),
                          Direction.NORTH)
     self.assertTrue("Cannot place a worker out of board bounds" in str(
         context.exception))
Пример #3
0
 def test_get_height(self):
     """Base case for getting the height of a building."""
     board = Board([[0, 3]], {self.workers[0]: (0, 0)})
     self.assertEqual(
         board.get_height(board.worker_position(self.workers[0]),
                          Direction.EAST), 3)
     self.assertEqual(
         board.get_height(board.worker_position(self.workers[0]),
                          Direction.STAY), 0)
Пример #4
0
 def test_build_floor_on_worker(self):
     """Case for building a floor on top of another worker."""
     board = Board(workers={
         self.workers[0]: (0, 0),
         self.workers[1]: (1, 1)
     })
     self.assertEqual(
         board.get_height(board.worker_position(self.workers[0]),
                          Direction.SOUTHEAST), 0)
     board.build_floor(self.workers[0], Direction.SOUTHEAST)
     self.assertTrue(board.is_occupied((1, 1)))
     self.assertEqual(
         board.get_height(board.worker_position(self.workers[0]),
                          Direction.SOUTHEAST), 1)
Пример #5
0
    def test_move_worker_onto_building(self):
        """Case for moving a worker onto a building.

        In this case, the building is 1 floor higher than the current worker
        """
        board = Board([[0, 1]], {self.workers[0]: (0, 0)})
        self.assertEqual(board.worker_position(self.workers[0]), (0, 0))
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.STAY), 0)
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.EAST), 1)
        board.move_worker(self.workers[0], Direction.EAST)
        self.assertEqual(board.worker_position(self.workers[0]), (0, 1))
        self.assertEqual(
            board.get_height(board.worker_position(self.workers[0]),
                             Direction.STAY), 1)