Exemplo n.º 1
0
    def test_solve_bad_row(self, description, input_row, error):
        with pytest.raises(NonogramError) as ie:
            solve_line(description, input_row, method='simpson')

        str_ex = str(ie.value)
        assert str_ex.startswith('FastSolver: Failed to solve line')
        assert str_ex.endswith(': ' + error)
Exemplo n.º 2
0
    def test_solve_bad_row(self):
        with pytest.raises(NonogramError) as ie:
            solve_line('1 1', '__.', method='reverse_tracking')

        assert str(
            ie.value) == ('ReverseTrackingSolver: Failed to solve line '
                          '(None, None, False) with clues (1, 1): '
                          'Bad transition table: final state 4 not found')
Exemplo n.º 3
0
def solve_row(board, index, is_column, method):
    """
    Solve a line with the solving `method`.
    If the line gets partially solved,
    put the crossed lines into queue.

    Return the list of new jobs that should be solved next (one for each solved cell).
    """

    # start = time.time()

    if is_column:
        row_desc = board.columns_descriptions[index]
        row = tuple(board.get_column(index))
        # desc = 'column'
    else:
        row_desc = board.rows_descriptions[index]
        row = tuple(board.get_row(index))
        # desc = 'row'

    # pre_solution_rate = board.line_solution_rate(row)

    # if board.is_line_solved(row):
    #     # do not check solved lines in trusted mode
    #     if contradiction_mode:
    #         assert_match(row_desc, row)
    #     return 0, ()

    # LOG.debug('Solving %s %s: %s. Partial: %s', index,
    #           'column' if is_column else 'row', row_desc, row)

    updated = solve_line(row_desc, row, method=method, normalized=True)

    new_jobs = []

    # if board.line_solution_rate(updated) > pre_solution_rate:
    if row != updated:
        # LOG.debug('Queue: %s', jobs_queue)
        # LOG.debug(row)
        # LOG.debug(updated)
        for i, (pre, post) in enumerate(zip(row, updated)):
            if _is_pixel_updated(pre, post):
                new_jobs.append((not is_column, i))
        # LOG.debug('Queue: %s', jobs_queue)
        # LOG.debug('New info on %s %s: %s', desc, index, [job_index for _, job_index in new_jobs])

        if is_column:
            board.set_column(index, updated)
        else:
            board.set_row(index, updated)

    # LOG.debug('%ss solution: %.6f sec', desc, time.time() - start)
    return new_jobs
Exemplo n.º 4
0
 def test_solve(self, description, input_row, expected):
     assert solve_line(description, tuple(input_row),
                       method='simpson') == tuple(expected)
Exemplo n.º 5
0
    def test_solve_bad_method(self):
        with pytest.raises(KeyError) as ie:
            solve_line('1 1', '___', method='brute_force')

        assert str(ie.value.args[0]) == "Cannot find solver 'brute_force'"
Exemplo n.º 6
0
 def test_solve(self, description, input_row, expected):
     # both arguments passes work
     # assert solve_line((description, input_row)) == tuple(expected)
     assert solve_line(description, input_row,
                       method='reverse_tracking') == tuple(expected)
Exemplo n.º 7
0
 def test_solve(self, description, input_row, expected):
     # both arguments passes work
     # assert solve_row((description, input_row)) == expected
     assert solve_line(description, input_row,
                       method='partial_match') == tuple(expected)
Exemplo n.º 8
0
 def test_solve_bad_row(self, description, input_row):
     with pytest.raises(NonogramError):
         solve_line(description, input_row, method='bgu')
Exemplo n.º 9
0
 def test_solve(self, description, input_row, expected):
     assert solve_line(description, input_row,
                       method='bgu') == tuple(expected)