From c85e1b0bcb257ed3e9ecc7aaa3baf686b0c245fc Mon Sep 17 00:00:00 2001 From: Ilja Heitlager Date: Tue, 21 Nov 2023 21:24:57 +0100 Subject: [PATCH] Fix (#39) * adding second csp solver * coverage fix --- simple_sudoku.py | 15 ++++++++++----- test_simple_sudoku.py | 5 +++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/simple_sudoku.py b/simple_sudoku.py index d53c4f3..833ae9b 100644 --- a/simple_sudoku.py +++ b/simple_sudoku.py @@ -97,11 +97,16 @@ def solve_sudoku(grid): [0, 0, 0, 0, 0, 0, 4, 0, 0] ] -if __name__ == '__main__': - print("Fill before rate: {0:d}".format(count_nonzero(sudoku_grid))) - solve_sudoku(sudoku_grid) - fr = count_nonzero(sudoku_grid) +def main(grid): + print("Fill before rate: {0:d}".format(count_nonzero(grid))) + res = solve_sudoku(grid) + fr = count_nonzero(grid) frp = fr / 81 * 100.0 print("Fill after rate: {0:d} ({1:0.0f}%)".format(fr, frp)) print("Iterations: {0:d}".format(iterations)) - display_grid(sudoku_grid) + display_grid(grid) + return res + + +if __name__ == '__main__': + main(sudoku_grid) \ No newline at end of file diff --git a/test_simple_sudoku.py b/test_simple_sudoku.py index 8954821..b6b70d2 100644 --- a/test_simple_sudoku.py +++ b/test_simple_sudoku.py @@ -30,3 +30,8 @@ def test_solve(): assert ss.is_complete(g) assert ss.count_nonzero(g) == 81 assert ss.find_empty_cell(g) == (None, None) + + +def test_main(): + g = copy.deepcopy(ss.sudoku_grid) + assert ss.main(g)