def test_bold_lines(self, stream): """ M letter """ columns = [5, 1, 1, 1, 5] rows = ['1 1', '2 2', '1 1 1', '1 1', '1 1'] renderer = AsciiRendererWithBold(stream=stream) renderer.BOLD_LINE_EVERY = 2 board = BlackBoard(columns, rows, renderer=renderer) propagation.solve(board) board.draw() assert stream.getvalue().rstrip() == '\n'.join([ '+---+---+---+++---+---++---+---++---+', '| # | # | # ||| 5 | 1 || 1 | 1 || 5 |', '|===+===+===+++===+===++===+===++===|', '| | 1 | 1 ||| # | || | || # |', '|---+---+---+++---+---++---+---++---|', '| | 2 | 2 ||| # | # || | # || # |', '|===+===+===+++===+===++===+===++===|', '| 1 | 1 | 1 ||| # | || # | || # |', '|---+---+---+++---+---++---+---++---|', '| | 1 | 1 ||| # | || | || # |', '|===+===+===+++===+===++===+===++===|', '| | 1 | 1 ||| # | || | || # |', '+---+---+---+++---+---++---+---++---+', ])
def test_several_solutions(self, stream): columns = [3, None, 1, 1] rows = [ 1, '1 1', '1 1', ] board = BlackBoard(columns, rows, renderer=AsciiRenderer, stream=stream) propagation.solve(board) board.draw() assert stream.getvalue().rstrip() == '\n'.join([ '+---+---++---+---+---+---+', '| # | # || 3 | 0 | 1 | 1 |', '|===+===++===+===+===+===|', '| | 1 || # | | | |', '|---+---++---+---+---+---|', '| 1 | 1 || # | | ? | ? |', '|---+---++---+---+---+---|', '| 1 | 1 || # | | ? | ? |', '+---+---++---+---+---+---+', ]) assert board.solution_rate * 3 == 2.0
def test_two_digits_bad_drawing(self, stream): width = 10 cols = [1] * width + [0, 1] rows = [[width, 1]] b = BlackBoard(cols, rows, renderer=BaseAsciiRenderer, stream=stream) b.draw() assert stream.getvalue().rstrip() == '\n'.join([ '# # 1 1 1 1 1 1 1 1 1 1 0 1', '101 _ _ _ _ _ _ _ _ _ _ _ _', ])
def test_hello(self): columns, rows = read_example('hello.txt') stream = StringIO() board = BlackBoard(columns, rows, renderer=BaseAsciiRenderer, stream=stream) propagation.solve(board) board.draw() assert stream.getvalue().rstrip() == '\n'.join([ '# # # # # # # # # 1 1 ', '# # # # # # # # # 1 1 1 1 5', '# # # # # # # # # 7 1 1 1 7 0 3 1 1 2 0 6 0 6 0 3 1 5 1 3 0 1', ' 1 1 1 X . . . X . . . . . . . . . . . . . . . . X', ' 1 1 1 1 1 X . . . X . . . . . . X . X . . . . . . . X', ' 1 1 2 1 1 3 1 X . . . X . . X X . . X . X . . X X X . . X', '5 1 1 1 1 1 1 1 1 X X X X X . X . . X . X . X . X . X . X . X', '1 1 4 1 1 1 1 1 1 X . . . X . X X X X . X . X . X . X . X . X', ' 1 1 1 1 1 1 1 1 X . . . X . X . . . . X . X . X . X . X . .', ' 1 1 2 1 1 3 1 X . . . X . . X X . . X . X . . X X X . . X', ]) assert board.is_solved_full