Skip to content

Commit

Permalink
Fixed format
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed Oct 20, 2024
1 parent 532f44a commit 882a228
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
10 changes: 7 additions & 3 deletions src/pyswip/examples/sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@


class Matrix:

def __init__(self, matrix: List[List[int]]) -> None:
if not matrix:
raise ValueError("matrix must be given")
Expand All @@ -56,7 +55,9 @@ def from_text(cls, text: str) -> "Matrix":
for i, line in enumerate(lines):
cols = line.split()
if len(cols) != dimension:
raise ValueError(f"All rows must have {dimension} columns, line {i+1} has {len(cols)}")
raise ValueError(
f"All rows must have {dimension} columns, line {i+1} has {len(cols)}"
)
rows.append([0 if x == "." else int(x) for x in cols])
return cls(rows)

Expand All @@ -66,7 +67,9 @@ def _validate(cls, dimension: int, matrix: List[List[int]]):
raise ValueError(f"Matrix must have {dimension} rows, it has {len(matrix)}")
for i, row in enumerate(matrix):
if len(row) != dimension:
raise ValueError(f"All rows must have {dimension} columns, row {i+1} has {len(row)}")
raise ValueError(
f"All rows must have {dimension} columns, row {i+1} has {len(row)}"
)

def __len__(self) -> int:
return self._dimension
Expand Down Expand Up @@ -108,6 +111,7 @@ def solve(matrix: Matrix) -> Union[Matrix, Literal[False]]:

def prolog_source() -> str:
from pathlib import Path

path = Path(__file__).parent / _SOURCE_PATH
with open(path) as f:
return f.read()
Expand Down
1 change: 0 additions & 1 deletion tests/examples/test_sudoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class MatrixTestCase(unittest.TestCase):

FIXTURE = """
. 6 . 1 . 4 . 5 .
. . 8 3 . 5 6 . .
Expand Down
14 changes: 8 additions & 6 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ def example_path(path):
def execfile(filepath, globals=None, locals=None):
if globals is None:
globals = {}
globals.update({
"__file__": filepath,
"__name__": "__main__",
})
with open(filepath, 'rb') as file:
exec(compile(file.read(), filepath, 'exec'), globals, locals)
globals.update(
{
"__file__": filepath,
"__name__": "__main__",
}
)
with open(filepath, "rb") as file:
exec(compile(file.read(), filepath, "exec"), globals, locals)

0 comments on commit 882a228

Please sign in to comment.