Add /addword command to add missing Wordle answers
Some real Wordle answers aren't in the bundled answers.txt list. This adds a REPL command to append a word to answers.txt and remove it from guesses.txt if present there, since the two lists are meant to be disjoint. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+73
-2
@@ -1,7 +1,12 @@
|
||||
import argparse
|
||||
|
||||
import pytest
|
||||
|
||||
from wordle_solver.game import Clue
|
||||
from wordle_solver.cli import parse_line, hard_mode_violation
|
||||
from wordle_solver import cli
|
||||
from wordle_solver.game import Clue, score_guess
|
||||
from wordle_solver.cli import handle_slash_command, parse_line, hard_mode_violation
|
||||
from wordle_solver.solver import Solver
|
||||
from wordle_solver.wager import Wager
|
||||
|
||||
G = Clue.GREEN
|
||||
Y = Clue.YELLOW
|
||||
@@ -82,3 +87,69 @@ class TestHardModeViolation:
|
||||
def test_empty_constraints_always_none(self):
|
||||
from collections import Counter
|
||||
assert hard_mode_violation("crane", {}, Counter()) is None
|
||||
|
||||
|
||||
class TestAddWordCommand:
|
||||
def _solver(self):
|
||||
return Solver(answers=["crane", "trace"], extra_guesses=["about", "zesty"])
|
||||
|
||||
def _opts(self):
|
||||
return argparse.Namespace(top=10, position_weight=1.0, presence_weight=1.0)
|
||||
|
||||
def test_rejects_wrong_arg_count(self, capsys):
|
||||
solver = self._solver()
|
||||
handle_slash_command("/addword", solver, Wager(), {}, solver.answers, self._opts())
|
||||
assert "Usage" in capsys.readouterr().out
|
||||
assert solver.answers == ["crane", "trace"]
|
||||
|
||||
def test_rejects_non_alpha_or_wrong_length(self, capsys):
|
||||
solver = self._solver()
|
||||
handle_slash_command("/addword abc12", solver, Wager(), {}, solver.answers, self._opts())
|
||||
assert "5 letters" in capsys.readouterr().out
|
||||
assert solver.answers == ["crane", "trace"]
|
||||
|
||||
def test_already_in_answers_short_circuits(self, capsys, monkeypatch):
|
||||
solver = self._solver()
|
||||
called = False
|
||||
|
||||
def fake_add(word):
|
||||
nonlocal called
|
||||
called = True
|
||||
return {"added": False, "removed_from_guesses": False}
|
||||
|
||||
monkeypatch.setattr(cli, "add_answer_word", fake_add)
|
||||
handle_slash_command("/addword crane", solver, Wager(), {}, solver.answers, self._opts())
|
||||
|
||||
assert "already" in capsys.readouterr().out
|
||||
assert not called
|
||||
assert solver.answers == ["crane", "trace"]
|
||||
|
||||
def test_adds_word_and_removes_from_guesses(self, capsys, monkeypatch):
|
||||
solver = self._solver()
|
||||
monkeypatch.setattr(
|
||||
cli, "add_answer_word",
|
||||
lambda word: {"added": True, "removed_from_guesses": True},
|
||||
)
|
||||
|
||||
handle_slash_command("/addword zesty", solver, Wager(), {}, solver.answers, self._opts())
|
||||
|
||||
out = capsys.readouterr().out
|
||||
assert "Added ZESTY" in out
|
||||
assert "removed it from guesses.txt" in out
|
||||
assert solver.answers == ["crane", "trace", "zesty"]
|
||||
assert "zesty" not in solver.extra_guesses
|
||||
|
||||
def test_new_candidate_consistent_with_history_is_added(self, capsys, monkeypatch):
|
||||
solver = self._solver()
|
||||
# Derive the pattern "trace" would actually produce against "chase",
|
||||
# so the new word is consistent with history by construction.
|
||||
pattern = score_guess("trace", "chase")
|
||||
solver.apply("trace", pattern)
|
||||
monkeypatch.setattr(
|
||||
cli, "add_answer_word",
|
||||
lambda word: {"added": True, "removed_from_guesses": False},
|
||||
)
|
||||
|
||||
handle_slash_command("/addword chase", solver, Wager(), {}, solver.answers, self._opts())
|
||||
|
||||
assert "chase" in solver.candidates
|
||||
|
||||
Reference in New Issue
Block a user