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
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
def generate(self, game, title=None): size = game.game_info.board_size num = 1 for node in [x for x in game.root.next_nodes if x.move is None]: board = Board(size) board.apply(node) if title is not None: board.name = "{} {}".format(title, num) num += 1 yield board
def test_simple_book_generator(self): child1 = GameNode() child1.add_black = [Point(7, 7)] child2 = GameNode() child2.add_white = [Point(3, 3)] child2.add_black = [Point(5, 5)] child3 = GameNode() child3.add_black = [Point(11, 11)] root = GameNode() root.add_next_node(child1) root.add_next_node(child2) root.add_next_node(child3) game = Game(13) game.game_info = GameInfo() game.game_info.board_size = 13 game.root = root board1 = Board(13).black(7, 7) board2 = Board(13).white(3, 3).black(5, 5) board3 = Board(13).black(11, 11) board1.name = "Problem 1" board2.name = "Problem 2" board3.name = "Problem 3" expected = [board1, board2, board3] generator = ProblemsBookGenerator() actual = [x for x in generator.generate(game, title="Problem")] self.assertEqual(expected, actual)
def test_снятие_камней_группа_в_углу(self): board = Board(13)\ .white(1, 2).white(2, 2).white(2, 1)\ .black(1, 3).black(2, 3).black(3, 1).black(3, 2)\ game_node = GameNode() game_node.move = Move(Stone.Black, Point(1, 1)) board.apply(game_node) board_expected = Board(13)\ .black(1, 1)\ .black(1, 3).black(2, 3).black(3, 1).black(3, 2)\ self.assertEqual(board_expected, board)
def test_simple_problem_book_9x9(self): parser = SgfParser() game = parser.load_game('testdata/problems9x9.sgf') board1 = Board(9).white(5, 1).white(7, 1).white(3, 2) board2 = Board(9).white(5, 1).white(7, 1).white(3, 1) board3 = Board(9).white(3, 1).white(5, 1).white(3, 2) board4 = Board(9).white(1, 1).white(2, 2).white(3, 1) expected_boards = [board1, board2, board3, board4] generator = ProblemsBookGenerator() actual = [x for x in generator.generate(game)] self.assertEqual(expected_boards, actual)
def test_снятие_камней_4_камня_в_центре(self): board = Board(13)\ .white(7, 6).white(6, 7).white(8, 7).white(7, 8)\ .black(7, 5).black(5, 7).black(9, 7).black(7, 9)\ .black(8, 8).black(6, 6).black(8, 6).black(6, 8) game_node = GameNode() game_node.move = Move(Stone.Black, Point(7, 7)) board.apply(game_node) board_expected = Board(13)\ .black(7, 5).black(5, 7).black(9, 7).black(7, 9)\ .black(8, 8).black(6, 6).black(8, 6).black(6, 8).black(7, 7) self.assertEqual(board_expected, board)
def test_out_of_range_index(self): board = Board() self.assertRaises(IndexError, lambda: board[0, 1]) self.assertRaises(IndexError, lambda: board[1, 0]) self.assertRaises(IndexError, lambda: board[20, 1]) self.assertRaises(IndexError, lambda: board[1, 20])
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)
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)
def test_simple_9x9_board(self): parser = SgfParser() actual = parser.load_game('testdata/test9x9.sgf') board = Board(9) node = actual.root while node is not None: board.apply(node) node = node.next_node expected_board = Board(9)\ .black(7, 9).white(8, 9)\ .black(6, 8).black(7, 8).white(8, 8)\ .black(3, 7).black(5, 7).black(7, 7).white(8, 7)\ .black(5, 6).black(6, 6).white(7, 6)\ .black(1, 5).black(2, 5).black(3, 5).black(4, 5).white(5, 5).white(6, 5).white(7, 5).white(9, 5)\ .black(1, 4).white(2, 4).black(3, 4).black(4, 4).black(5, 4).black(6, 4).white(7, 4).white(8, 4)\ .white(9, 4)\ .black(1, 3).white(2, 3).black(3, 3).white(4, 3).white(5, 3).black(6, 3).black(7, 3).black(8, 3)\ .white(9, 3)\ .white(1, 2).white(2, 2).white(3, 2).white(5, 2).black(6, 2).black(7, 2).white(8, 2)\ .white(4, 1).white(5, 1).white(6, 1).black(7, 1).white(9, 1) self.assertEqual(expected_board, board)
def test_emty_board(self): builder = SvgDiagramBuilder() builder.build(Board())