Skip to content

Commit

Permalink
Merge pull request #65 from parmentelat/debug-simple-trimino
Browse files Browse the repository at this point in the history
added a failing test with 2 triminos on a 3x3 board
  • Loading branch information
jwg4 authored Oct 20, 2023
2 parents d719ab0 + 17109f9 commit 08b4c3e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Binary file added tests/files/small_trimino_problem.npy
Binary file not shown.
77 changes: 77 additions & 0 deletions tests/test_trimino_based.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pytest
import numpy as np

from exact_cover import get_exact_cover
from exact_cover.error import NoSolution
from exact_cover.io import DTYPE_FOR_ARRAY
# from exact_cover.helpers import is_solution

DTYPE = dict(dtype=DTYPE_FOR_ARRAY)

# from exact_cover.io import load_problem

# from tests.config import GLOBAL_CONFIG


# one specific problem that I had trouble with
# originally based on solving the trivial problem
# of arranging 2 identical triminos on a 3x3 board

# +--+
# | |
# +--+--+
# | | |
# +--+--+

# +--+--+--+
# |xx| |xx|
# +--+--+--+
# | | | |
# +--+--+--+
# |xx| | |
# +--+--+--+

# the exact cover matrix built manually
def input1():
to_cover = [
[1, 0, 0, 1, 1, 0, 1, 0],
[1, 0, 0, 0, 1, 1, 0, 1],
[1, 0, 0, 0, 1, 1, 1, 0],
[1, 0, 1, 0, 1, 1, 0, 0],
[1, 0, 0, 0, 1, 0, 1, 1],
[1, 0, 1, 1, 1, 0, 0, 0], # <- 5
[1, 0, 0, 0, 0, 1, 1, 1],
[0, 1, 0, 1, 1, 0, 1, 0],
[0, 1, 0, 0, 1, 1, 0, 1],
[0, 1, 0, 0, 1, 1, 1, 0],
[0, 1, 1, 0, 1, 1, 0, 0],
[0, 1, 0, 0, 1, 0, 1, 1],
[0, 1, 1, 1, 1, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 1, 1], # <- 13
]
return np.array(to_cover, **DTYPE)

def input2():
return np.load("tests/files/small_trimino_problem.npy")

def test_inputs_are_equal():
m1 = input1()
m2 = input2()

# really equal, including their dtype
assert (np.all(np.equal(m1, m2))
and (m1.dtype is m2.dtype)
and (m1.shape == m2.shape))

def run_on_input(array, expected):
try:
solution = get_exact_cover(array)
assert np.all(solution == expected)
except NoSolution as exc:
pytest.fail(f"no solution found for {array}")

def test_input1():
run_on_input(input1(), [5, 13])

def test_input2():
run_on_input(input2(), [5, 13])

0 comments on commit 08b4c3e

Please sign in to comment.