Esempio n. 1
0
 def test_points_generator(self):
     answer = {i for i in self.searcher.points_generator(self.board)}
     true = {
         Point(1, 1),
         Point(2, 2)
     }
     self.assertEqual(true, answer)
Esempio n. 2
0
 def test_swap(self):
     """ test swapping two points """
     p1 = Point(0, 0)
     p2 = Point(0, 1)
     self.board.swap(p1, p2)
     correct = np.array([[1, 0], [2, 0]])
     self.assertEqual(correct.tolist(), self.board.board.tolist())
Esempio n. 3
0
 def test_search_moves(self):
     true = {
         (Point(1, 0), (1, 0)),
         (Point(2, 0), (-1, 0)),
     }
     answer = self.moves_searcher.search_moves(board=self.board_wimmove,
                                               all_moves=True)
     self.assertEqual(true, answer)
Esempio n. 4
0
 def test_search_moves(self):
     true = {
         (Point(2, 0), (0, 1)),
         (Point(2, 1), (0, -1)),
     }
     answer = self.moves_searcher.search_moves(board=self.board,
                                               all_moves=True)
     self.assertEqual(true, answer)
Esempio n. 5
0
    def test_availability(self):
        with self.assertRaises(ImmovableShapeError):
            self.board_wimove.move(Point(0, 0), Point(0, 1))

        with self.assertRaises(ImmovableShapeError):
            self.board_wimove.swap(Point(0, 0), Point(1, 1))

        with self.assertRaises(ImmovableShapeError):
            self.board_wimove.delete({Point(0, 0)})
Esempio n. 6
0
    def test_bad_swap(self):
        old_board = self.game.board.board.copy()
        answer = self.game.swap(Point(0, 0), Point(0, 1))

        with self.subTest(returns_zero=True):
            self.assertTrue(answer == 0)

        with self.subTest(same_board=True):
            self.assertEqual(old_board.tolist(),
                             self.game.board.board.tolist())
Esempio n. 7
0
 def test_get_shape(self):
     """ test getting shape of points """
     points = [Point(0, 0), Point(1, 1)]
     correct_answers = [
         self.board.board[0, 0],
         self.board.board[1, 1],
     ]
     board_answers = [self.board.get_shape(point) for point in points]
     for ind, point in enumerate(points):
         with self.subTest(point=point.get_coord()):
             self.assertEqual(correct_answers[ind], board_answers[ind])
Esempio n. 8
0
 def test_move(self):
     point = Point(1, 1)
     direction = Point(-1, 0)
     correct = np.array([
         [0, 0],
         [2, 1]
     ])
     self.board.move(point, direction)
     self.assertEqual(
         self.board.board.tolist(), correct.tolist()
     )
Esempio n. 9
0
 def test_delete(self):
     points = {Point(0, 0), Point(1, 1)}
     deleted_board = np.array([
         [np.nan, 1.],
         [2., np.nan]
     ], dtype='float')
     self.board.delete(points)
     self.assertTrue(
         np.allclose(
             self.board.board,
             deleted_board,
             equal_nan=True))
Esempio n. 10
0
 def test_get_bad_shape(self):
     """ test getting shapes of incorrect points """
     points = [
         Point(-1, 0),
         Point(-1, -1),
         Point(1, -1),
         Point(10, 0),
         Point(0, 2),
     ]
     for point in points:
         with self.subTest(point=point.get_coord()):
             with self.assertRaises(OutOfBoardError):
                 self.board.get_shape(point)
Esempio n. 11
0
 def get_validate_actions(self):
     possible = self.__game.get_all_possible_moves()
     validate_actions = []
     for point, direction in possible:
         newpoint =  point +  Point(*direction)
         validate_actions.append((newpoint, point))
     return validate_actions
Esempio n. 12
0
 def get_available_actions(self):
     """ calculate available actions for current board sizes """
     actions = []
     directions = [[1, 0], [0, 1]]
     for dir_ in directions:
         for point in self.__points_generator():
             dir_p = Point(*dir_)
             new_point = point + dir_p
             try:
                 _ = self.__game.board[new_point]
                 actions.append((point, new_point))
             except OutOfBoardError:
                 continue
     return actions
Esempio n. 13
0
 def __get_available_actions(self):
     """ calculate available actions for current board sizes """
     actions = set()
     directions = self.__get_directions(board_ndim=BOARD_NDIM)
     for point in self.__points_generator():
         for axis_dirs in directions:
             for dir_ in axis_dirs:
                 dir_p = Point(*dir_)
                 new_point = point + dir_p
                 try:
                     _ = self.__game.board[new_point]
                     actions.add(frozenset((point, new_point)))
                 except OutOfBoardError:
                     continue
     return list(actions)
Esempio n. 14
0
 def test_mul(self):
     true = Point(-5, -10)
     result = Point(5, 10) * -1
     self.assertEqual(true, result)
Esempio n. 15
0
 def test_add(self):
     """ test summation of two points """
     true = Point(0, 1)
     result = self.point1 + self.point2
     self.assertEqual(true.get_coord(), result.get_coord())
Esempio n. 16
0
 def __points_generator(self):
     """ iterates over points on the board """
     rows, cols = self.__game.board.board_size
     points = [Point(i, j) for i, j in product(range(rows), range(cols))]
     for point in points:
         yield point
Esempio n. 17
0
 def setUp(self):
     self.point1 = Point(1, 1)
     self.point2 = Point(-1, 0)
Esempio n. 18
0
 def test_sub(self):
     true = Point(-1, -1)
     result = Point(0, 0) - Point(1, 1)
     self.assertEqual(true, result)