Skip to content

Commit

Permalink
Merge pull request #16 from unmade/fix-locked-candidates
Browse files Browse the repository at this point in the history
Fix locked candidates
  • Loading branch information
unmade committed Dec 27, 2019
2 parents d3eafe7 + dc0caad commit db0e0b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Overview
:alt: Coverage Status
:target: https://codecov.io/gh/unmade/dokusan

.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
:alt: Checked with mypy
:target: http://mypy-lang.org/

.. image:: https://img.shields.io/pypi/v/dokusan.svg
:alt: PyPI Package latest release
:target: https://pypi.org/project/dokusan
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dokusan"
version = "0.1.0-alpha.4"
version = "0.1.0-alpha.5"
description = "Sudoku generator and solver with a step-by-step guidance"
keywords = ["sudoku", "sudoku-solver", "sudoku-generator", "solver", "generator"]
readme = "README.rst"
Expand Down
2 changes: 1 addition & 1 deletion src/dokusan/techniques.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _get_changes(self, combination: Combination) -> List[Cell]:

class LockedCandidate(Technique):
def _find(self) -> Iterator[Combination]:
for group in self.sudoku.boxes():
for group in self.sudoku.groups():
candidate_map: Dict[int, List[Cell]] = {}
for cell in group:
if cell.candidates:
Expand Down
31 changes: 30 additions & 1 deletion tests/test_techniques.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_naked_triplet_not_found():
techniques.NakedTriplet(sudoku).first()


def test_locked_candidate():
def test_locked_candidate_in_a_box():
sudoku = make_sudoku_with_marks(
[
[2, 0, 0, 5, 9, 3, 1, 0, 0],
Expand Down Expand Up @@ -354,6 +354,35 @@ def test_locked_candidate():
]


def test_locked_candidate_in_a_row():
sudoku = make_sudoku_with_marks(
[
[9, 0, 0, 5, 3, 1, 2, 8, 0],
[0, 2, 5, 7, 0, 4, 9, 3, 0],
[0, 3, 0, 0, 0, 2, 0, 4, 0],
[4, 8, 1, 2, 5, 7, 6, 9, 3],
[3, 5, 9, 0, 0, 8, 0, 0, 2],
[7, 6, 2, 3, 1, 9, 8, 5, 4],
[0, 1, 0, 0, 0, 0, 0, 6, 8],
[6, 0, 8, 1, 0, 5, 3, 0, 0],
[0, 0, 3, 8, 7, 6, 0, 0, 0],
],
box_size=BoxSize(3, 3),
)

locked_candidate = techniques.LockedCandidate(sudoku).first()

assert locked_candidate.combination.cells == [
Cell(position=Position(6, 3, 7), candidates={4, 9}),
Cell(position=Position(6, 4, 7), candidates={2, 4, 9}),
]
assert locked_candidate.combination.values == [9]

assert locked_candidate.changes == [
Cell(position=Position(7, 4, 7), candidates={2, 4})
]


def test_locked_candidate_not_found():
sudoku = make_sudoku_with_marks(
[
Expand Down

0 comments on commit db0e0b7

Please sign in to comment.