def test_basic(self): board = make_board(*Pbn.read(19407)) assert board.has_blots assert board.rows_descriptions[1] == (BlottedBlock,) propagation.solve(board) assert board.is_solved_full
def test_colored(self): columns, rows, colors = Pbn.read(898) assert [(c.name, c.rgb, c.symbol) for c in colors.iter_colors()] == [ ('white', 'FFFFFF', '.'), ('black', '000000', 'X'), ('red', 'FF0000', '*'), ('green', '00B000', '%'), ]
def test_depth_search(self): board = make_board(*Pbn.read(3469)) propagation.solve(board) assert board.solution_rate == 0 assert len(board.solutions) == 0 Solver(board, max_solutions=2, timeout=600).solve() assert board.is_solved_full assert len(board.solutions) == 1 assert board.is_finished
def get_board(cls, _id, create_mode, **renderer_params): """Generates a board using given ID and mode""" if create_mode == 'local': board_def = read_example(_id) elif create_mode == 'pbn': board_def = Pbn.read(_id) elif create_mode == 'nonograms.org': board_def = NonogramsOrg.read(_id) else: raise tornado.web.HTTPError(400, 'Bad mode: %s', create_mode) return make_board(*board_def, **renderer_params)
def test_depth_search_colored(self, stream): renderer = BaseAsciiRenderer(stream=stream) board = make_board(*Pbn.read(5260), renderer=renderer) propagation.solve(board) assert board.solution_rate == 0.9375 assert len(board.solutions) == 0 Solver(board, max_solutions=2, timeout=600).solve() assert board.solution_rate == 0.9375 assert len(board.solutions) == 2 assert board.is_finished board.draw_solutions() example_solution = [ '# # # # # # 1 1 ', '# # # # # # 1 1 ', '# # # # # # 1 1 1 1 1 1 ', '# # # # # # 1 1 1 1 1 1 1 1 1 1 ', '# # # # # # 6 1 2 1 2 1 2 1 1 2 1 2 1 2 1 6 ', '# # # # # # 1 1 1 1 1 2 0 1 2 1 1 2 1 0 2 1 1 1 1 1', ' 1 X . . . . . . . . . . . . . . . . . . .', ' 1 6 1 . X . . . . . % % % % % % . . . . . X .', ' 1 1 1 1 . . X . . . . . % . . % . . . X . . . .', ' 1 2 1 . . . . X . . . . % % . . . . . X . . .', ' 1 1 1 1 . . . X . @ . . . . . . . . @ . . X . .', ' 2 2 . . . . @ @ . . . . . . . . @ @ . . . .', ' 0 . . . . . . . . . . . . . . . . . . . .', ' 1 1 . % . . . . . . . . . . . . . . . . % .', ' 2 2 . % % . . . . . . . . . . . . . . % % .', '1 1 1 1 1 1 . % . % . . . . . * % . . . . . % . % .', '1 1 1 1 1 1 . % . % . . . . . X * . . . . . % . % .', ' 2 2 . % % . . . . . . . . . . . . . . % % .', ' 1 1 . % . . . . . . . . . . . . . . . . % .', ' 0 . . . . . . . . . . . . . . . . . . . .', ' 2 2 . . . . @ @ . . . . . . . . @ @ . . . .', ' 1 1 1 1 . X . . . @ . . . . . . . . @ . . X . .', ' 1 2 1 . . X . . . . . . % % . . . . . X . . .', ' 1 1 1 1 . . . . X . . . % . . % . . . . . . X .', ' 1 6 1 . . . X . . . % % % % % % . . X . . . .', ' 1 . . . . . . . . . . . . . . . . . . . X', ] actual_drawing = stream.getvalue().rstrip().split('\n') sol1, sol2 = actual_drawing[:26], actual_drawing[26:] # header assert sol1[:6] == sol2[:6] == example_solution[:6] # central assert sol1[11:21] == sol2[11:21] == example_solution[11:21]
def test_color(self): board = make_board(*Pbn.read(19647)) assert board.has_blots assert board.rows_descriptions[15] == ( (1, 2), (BlottedBlock, 8), (BlottedBlock, 8), (2, 2), (2, 2), (2, 8), ) propagation.solve(board) assert board.is_solved_full
def test_colored(self): board = make_board(*Pbn.read(10282)) propagation.solve(board) assert len(board.solutions) == 0 Solver(board, max_solutions=2, timeout=600).solve() assert is_close(board.solution_rate, 0.91625) assert len(board.solutions) == 2 assert len(board.solved_rows[0]) == 3 assert len(board.solved_rows[1]) == 2 assert len(board.solved_columns[0]) == 5 assert len(board.solved_columns[1]) == 9
def test_black_and_white(self): board = make_board(*Pbn.read(2903)) propagation.solve(board) assert len(board.solutions) == 0 Solver(board, max_solutions=2, timeout=600).solve() assert board.is_solved_full assert len(board.solutions) == 1 assert len(board.solved_rows[0]) == 6 assert len(board.solved_rows[1]) == 6 assert len(board.solved_columns[0]) == 4 assert len(board.solved_columns[1]) == 0 assert board.is_finished
def main(): """Main function for setuptools console_scripts""" args = cli_args() if args.version: print(__version__) return if args.show_examples_folder: print(example_file()) return is_windows = platform.system() == 'Windows' is_pypy2 = PY2 and platform.python_implementation() == 'PyPy' is_curses = args.curses if is_curses and is_windows: exit('Curses do not supported on Windows') _setup_logs(log_level(args.verbose)) if args.pbn: board_def = Pbn.read(args.pbn) elif args.local_pbn: board_def = PbnLocal.read(args.local_pbn) elif args.nonograms_org: board_def = NonogramsOrg.read(args.nonograms_org) else: board_def = read_example(args.board) # the Windows does not support Unicode, so does the curses on PyPy2 if (is_curses and is_pypy2) or is_windows: box_symbol = '#' else: box_symbol = '\u2B1B' draw_solution(board_def, box_symbol=box_symbol, draw_final=args.draw_final, draw_probes=args.draw_probes, curses_animation=is_curses, max_solutions=args.max_solutions, timeout=args.timeout, max_depth=args.max_depth)
def test_black(self): board = make_board(*Pbn.read(20029)) assert board.rows_descriptions[2] == (BlottedBlock, 1) propagation.solve(board) assert board.is_solved_full
def test_solve_contradictions(self): board = make_board(*Pbn.read(2021)) Solver(board).solve() assert board.is_solved_full assert board.is_finished
def test_backtracking(self): board = make_board(*Pbn.read(4581)) propagation.solve(board, methods=self.method_name()) assert is_close(board.solution_rate, 0.75416666667) assert len(board.solutions) == 0
def test_absent(self): with pytest.raises(PbnNotFoundError, match='5'): Pbn.read(5)
def test_simple(self): columns, rows = Pbn.read(1) assert columns == [(2, 1), (2, 1, 3), (7, ), (1, 3), (2, 1)] assert rows == [(2, ), (2, 1), (1, 1), (3, ), (1, 1), (1, 1), (2, ), (1, 1), (1, 2), (2, )]