Skip to content

Commit

Permalink
Formatting/cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwg4 committed Mar 17, 2024
1 parent ed090b5 commit 26bab78
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
3 changes: 2 additions & 1 deletion exact_cover/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def truncate(row):
return truncate(row[:-1])
else:
return row

return set([tuple(truncate(row)) for row in a])


Expand All @@ -58,4 +59,4 @@ def get_all_solutions(matrix, max_count=None):
result = raw_get_all_solutions(transformed, count)
if result.size == 0:
raise NoSolution("No solutions found by the C code.")
return _solutions_array_to_set(result)
return _solutions_array_to_set(result)
2 changes: 1 addition & 1 deletion tests/problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ def bruteforce_problem3():
{5, 9, 10},
{6, 7, 8},
{9, 10, 11},
]
],
)
8 changes: 5 additions & 3 deletions tests/test_all_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ def normalize(solution):
"""
return frozenset(frozenset(row) for row in solution)


def make_test_from_problem(problem):
"""
generate a test function for a problem dict
"""

def test():
# xxx not yet available
result = normalize(get_all_solutions(problem["data"]))
expected = normalize(problem["all_solutions"])
assert result == expected

return test


Expand All @@ -31,9 +34,8 @@ def test():
# - and not be a private symbol (start with '_')

for problem_name in dir(problems):
if ('_problem' not in problem_name
or problem_name.startswith('_')):
if "_problem" not in problem_name or problem_name.startswith("_"):
continue
test_name = 'test_' + problem_name
test_name = "test_" + problem_name
problem_function = getattr(problems, problem_name)
globals()[test_name] = make_test_from_problem(problem_function())
1 change: 0 additions & 1 deletion tests/test_count_solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from hypothesis.strategies import sampled_from

from exact_cover import get_solution_count
from exact_cover.error import NoSolution
from exact_cover.io import DTYPE_FOR_ARRAY
from .helpers.polyomino_data import polyomino_problem
from .test_exact_cover_problems import large_problems_without_solution
Expand Down
7 changes: 0 additions & 7 deletions tests/test_get_all_solutions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import numpy as np
import pytest

from hypothesis import given
from hypothesis.strategies import sampled_from

from exact_cover import get_all_solutions
from exact_cover.error import NoSolution
from exact_cover.io import DTYPE_FOR_ARRAY
from .helpers.polyomino_data import polyomino_problem
from .test_exact_cover_problems import large_problems_without_solution


def test_exact_cover():
Expand Down

0 comments on commit 26bab78

Please sign in to comment.