-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0561acc
commit 451f0ef
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# xxx not yet available | ||
# from exact_cover_impl import get_all_solutions | ||
|
||
import problems | ||
|
||
|
||
def normalize(solution): | ||
""" | ||
transform the output of get_all_solutions | ||
or the all_solutions key in a problem dict | ||
into a frozenset of frozensets, so that we can | ||
compare solutions for equality. | ||
""" | ||
return frozenset(frozenset(row) for row in solution) | ||
|
||
def 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"])) | ||
result = frozenset() | ||
expected = normalize(problem["all_solutions"]) | ||
assert result == expected | ||
return test | ||
|
||
|
||
# define in the current module a test function | ||
# for each problem in problems | ||
# not all symbols in the problems module are considered: | ||
# - need to contain '_problem' | ||
# - and not be a private symbol (start with '_') | ||
|
||
for problem_name in dir(problems): | ||
if ('_problem' not in problem_name | ||
or problem_name.startswith('_')): | ||
continue | ||
test_name = 'test_' + problem_name | ||
problem_function = getattr(problems, problem_name) | ||
globals()[test_name] = test_from_problem(problem_function()) |