Exemple #1
0
    def test_equals_set_Node_Node(self):
        board_1 = self.create_board_13x13()
        board_2 = self.create_board_13x13()

        board_1[3, 3] = Node()  # empty node
        board_2[3, 3] = Node()  # empty node
        self.assertEqual(board_1, board_2)
Exemple #2
0
    def test_simple_board(self):
        builder = SvgDiagramBuilder()
        markers = [None, Circle(), Triangle(), Square(), Cross(), Label("A7")]
        board = Board()
        y = 1
        for marker in markers:
            board[1, y] = Node(Stone.Black, marker)
            board[3, y] = Node(Stone.White, marker)
            board[5, y] = Node(None, marker)
            y += 2

        board.black(16, 3).label(16, 3, "1") \
            .white(16, 5).label(16, 5, "2") \
            .black(17, 5).label(17, 5, "3") \
            .white(17, 6).label(17, 6, "4") \
            .black(17, 4).label(17, 4, "5") \
            .white(16, 6).label(16, 6, "6") \
            .black(14, 3).label(14, 3, "7") \
            .white(16, 10).label(16, 10, "8")

        tmp = tempfile.mkstemp()
        os.close(tmp[0])

        try:
            builder.build(board, file=tmp[1])
            self.assertTrue(filecmp.cmp("svg_expected/simple_expected.svg", tmp[1]))
        finally:
            os.remove(tmp[1])
            pass
Exemple #3
0
    def test_set_get_node_value_by_point(self):
        board = Board()
        node = Node()
        node.stone = Stone.Black
        board[Point(1, 1)] = node

        self.assertEqual(board[Point(1, 1)], node)
Exemple #4
0
    def test_set_get_node_value(self):
        board = Board()
        node = Node()
        node.stone = Stone.Black
        board[1, 1] = node

        self.assertEqual(board[1, 1], node)
Exemple #5
0
    def create_board_13x13(self):
        board = Board(13)
        board.comment = "Board for test"
        board.name = "Board 13x13"
        node = Node()
        node.stone = Stone.Black
        node.marker = Square()
        board[1, 1] = node

        return board
Exemple #6
0
    def test_equals_None_node_as_empty(self):
        board_1 = self.create_board_13x13()
        board_2 = self.create_board_13x13()

        board_1[3, 3] = Node()  # empty node
        board_1[4, 4] = None  # empty node

        self.assertEqual(board_1, board_2)
Exemple #7
0
    def test_empty_node_first(self):
        game_node = GameNode()
        game_node.empty = [Point(1, 1)]
        game_node.move = Move(Stone.White, Point(1, 1))
        board = self.create_board_13x13()
        board.apply(game_node)

        board_expected = self.create_board_13x13()
        board_expected[1, 1] = Node(stone=Stone.White)
        self.assertEqual(board_expected, board)
Exemple #8
0
    def test_apply_move_replace_stone(self):
        game_node = GameNode()
        game_node.add_white = [Point(1, 1)]
        board = self.create_board_13x13()
        board.apply(game_node)

        board_expected = self.create_board_13x13()
        board_expected[1, 1] = Node(stone=Stone.White, marker=Square())

        self.assertEqual(board_expected, board)
Exemple #9
0
    def test_apply_move(self):
        game_node = GameNode()
        game_node.add_black = [Point(2, 2), Point(12, 12)]
        game_node.add_white = [Point(3, 3), Point(11, 11)]
        game_node.empty = [Point(1, 1)]
        game_node.move = Move(Stone.Black, Point(7, 7))
        game_node.markups = [(Triangle(), Point(7, 7)), (Circle(), Point(5, 5))]

        board = self.create_board_13x13()
        board.apply(game_node)

        board_expected = self.create_board_13x13()
        board_expected[1, 1] = None
        board_expected[2, 2] = Node(stone=Stone.Black)
        board_expected[12, 12] = Node(stone=Stone.Black)
        board_expected[3, 3] = Node(stone=Stone.White)
        board_expected[11, 11] = Node(stone=Stone.White)
        board_expected[5, 5] = Node(marker=Circle())
        board_expected[7, 7] = Node(stone=Stone.Black, marker=Triangle())

        self.assertEqual(board_expected, board)