Skip to content

Commit 22af0d5

Browse files
Tighten strategy tests candidate setup
1 parent aa43c0c commit 22af0d5

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

tests/test_strategies_core.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def _clear_digit(cand: list[list[set[int]]], digit: int) -> None:
2222
cell.discard(digit)
2323

2424

25+
def _set_candidates(cand: list[list[set[int]]], r: int, c: int, values: set[int]) -> None:
26+
cand[r][c].clear()
27+
cand[r][c].update(values)
28+
29+
2530
def test_locked_candidates_pointing_row() -> None:
2631
grid = _empty_grid()
2732
cand = candidates(grid)
@@ -97,16 +102,18 @@ def test_naked_pair_eliminates_other_candidates() -> None:
97102
_clear_digit(cand, 1)
98103
_clear_digit(cand, 2)
99104
_clear_digit(cand, 3)
100-
cand[0][0].update({1, 2})
101-
cand[0][1].update({1, 2})
102-
cand[0][2].update({1, 2, 3})
105+
_set_candidates(cand, 0, 0, {1, 2})
106+
_set_candidates(cand, 0, 1, {1, 2})
107+
_set_candidates(cand, 0, 2, {1, 2, 3})
103108

104109
move = apply_naked_pair(grid, cand)
105110

106111
assert move is not None
107112
assert move["strategy"] == "naked_pair"
108113
assert move["r"] == 0 and move["c"] == 2
109-
assert 1 not in cand[0][2] and 2 not in cand[0][2]
114+
assert move["pair"] == [1, 2]
115+
assert move["remove"] in (1, 2)
116+
assert move["remove"] not in cand[0][2]
110117

111118

112119
def test_hidden_pair_prunes_extras() -> None:
@@ -116,8 +123,8 @@ def test_hidden_pair_prunes_extras() -> None:
116123
_clear_digit(cand, digit_a)
117124
_clear_digit(cand, digit_b)
118125
_clear_digit(cand, extra)
119-
cand[1][0].update({digit_a, digit_b, extra})
120-
cand[1][1].update({digit_a, digit_b, extra})
126+
_set_candidates(cand, 1, 0, {digit_a, digit_b, extra})
127+
_set_candidates(cand, 1, 1, {digit_a, digit_b, extra})
121128

122129
move = apply_hidden_pair(grid, cand)
123130

@@ -135,10 +142,10 @@ def test_naked_triple_clears_unit() -> None:
135142
digits = (1, 2, 3, 4)
136143
for d in digits:
137144
_clear_digit(cand, d)
138-
cand[2][0].update({1, 2})
139-
cand[2][1].update({1, 3})
140-
cand[2][2].update({2, 3})
141-
cand[2][3].update({1, 4})
145+
_set_candidates(cand, 2, 0, {1, 2})
146+
_set_candidates(cand, 2, 1, {1, 3})
147+
_set_candidates(cand, 2, 2, {2, 3})
148+
_set_candidates(cand, 2, 3, {1, 4})
142149

143150
move = apply_naked_triple(grid, cand)
144151

@@ -155,9 +162,9 @@ def test_hidden_triple_culls_extras() -> None:
155162
extra = 7
156163
for d in (*triple, extra):
157164
_clear_digit(cand, d)
158-
cand[3][0].update({4, 5, extra})
159-
cand[3][1].update({4, 6})
160-
cand[3][2].update({5, 6})
165+
_set_candidates(cand, 3, 0, {4, 5, extra})
166+
_set_candidates(cand, 3, 1, {4, 6})
167+
_set_candidates(cand, 3, 2, {5, 6})
161168

162169
move = apply_hidden_triple(grid, cand)
163170

0 commit comments

Comments
 (0)