Implemented doctests for geometry-related classes (#12368)

* Implemented doctests for geometry-related classes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removed unused noqa directive

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactored sudoku_solver.py

* refactored sudoku_solver.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* context manager for file handling changed too in from_file function

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
This commit is contained in:
Matej
2024-12-30 16:04:28 +01:00
committed by GitHub
parent a2be5adf67
commit f24ddba5b2
2 changed files with 32 additions and 2 deletions

View File

@ -23,7 +23,7 @@ unitlist = (
+ [cross(rs, cs) for rs in ("ABC", "DEF", "GHI") for cs in ("123", "456", "789")]
)
units = {s: [u for u in unitlist if s in u] for s in squares}
peers = {s: set(sum(units[s], [])) - {s} for s in squares} # noqa: RUF017
peers = {s: {x for u in units[s] for x in u} - {s} for s in squares}
def test():
@ -172,7 +172,8 @@ def solved(values):
def from_file(filename, sep="\n"):
"Parse a file into a list of strings, separated by sep."
return open(filename).read().strip().split(sep)
with open(filename) as file:
return file.read().strip().split(sep)
def random_puzzle(assignments=17):