Beispiel #1
0
def test_equality():
    s = Sudoku.load_file(os.path.join(_test_dir, 'hard_sol.sud'))
    s2 = Sudoku.load_file(os.path.join(_test_dir, 'medium_sol.sud'))
    s3 = Sudoku.load_file(os.path.join(_test_dir, 'hard_sol.sud'))
    assert s != s2
    assert s == s3
    assert s != 5
Beispiel #2
0
def test_to_oneliner_method():
    s = Sudoku.load_file(os.path.join(_test_dir, 'hard.sud'))
    s.solve(verbose=True)
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'hard_sol.sud'))
    assert s == correct_solution
    oneliner = s.to_oneliner()
    oneliner_parsed = Sudoku(oneliner)
    assert oneliner_parsed == correct_solution
Beispiel #3
0
def test_solve_very_hard_sudoku_with_brute_force():
    s = Sudoku.load_file(os.path.join(_test_dir, 'very_hard.sud'))
    s.solve(verbose=True, allow_brute_force=True)
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'very_hard_sol.sud'))
    assert s == correct_solution
    assert 'BRUTE FORCE' in "".join(s.solution_steps)
Beispiel #4
0
def test_solve_very_hard_sudoku_raises_error_if_brute_force_disallowed():
    s = Sudoku.load_file(os.path.join(_test_dir, 'very_hard.sud'))
    with pytest.raises(SudokuTooDifficultError):
        s.solve(verbose=True, allow_brute_force=False)
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'very_hard_sol.sud'))
    assert s != correct_solution
Beispiel #5
0
def test_solve_hard_sudoku():
    s = Sudoku.load_file(os.path.join(_test_dir, 'hard.sud'))
    s.solve(verbose=True)
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'hard_sol.sud'))
    assert s == correct_solution
Beispiel #6
0
def test_solve_medium_sudoku():
    s = Sudoku.load_file(os.path.join(_test_dir, 'medium.sud'))
    s.solve()
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'medium_sol.sud'))
    assert s == correct_solution
Beispiel #7
0
def test_solve_simple_sudoku_read_from_flat_file():
    s = Sudoku.load_file(os.path.join(_test_dir, 'simple_flat.sud'))
    s.solve()
    correct_solution = Sudoku.load_file(os.path.join(_test_dir, 'simple_sol.sud'))
    assert s == correct_solution
Beispiel #8
0
def test_str_repr():
    s = Sudoku.load_file(os.path.join(_test_dir, 'hard_sol.sud'))
    assert str(s) == repr(s)
Beispiel #9
0
def test_raises_error_when_unsolvable_2():
    with pytest.raises(SudokuHasNoSolutionError):
        s = Sudoku.load_file(os.path.join(_test_dir, 'hard.sud'))
        s._matrix[2][7] = 6
        s.solve()