Print possible answers in heuristic order, not alphabetical
The "possible answer(s) remain" list (shown when <=20 candidates) was sorted alphabetically, out of step with the ranked suggestions printed right below it. Rank it with the same heuristic instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+21
-2
@@ -4,8 +4,8 @@ import pytest
|
|||||||
|
|
||||||
from wordle_solver import cli
|
from wordle_solver import cli
|
||||||
from wordle_solver.game import Clue, score_guess
|
from wordle_solver.game import Clue, score_guess
|
||||||
from wordle_solver.cli import handle_slash_command, parse_line, hard_mode_violation
|
from wordle_solver.cli import handle_slash_command, parse_line, hard_mode_violation, print_suggestions
|
||||||
from wordle_solver.solver import Solver
|
from wordle_solver.solver import Solver, rank_guesses
|
||||||
from wordle_solver.wager import Wager
|
from wordle_solver.wager import Wager
|
||||||
|
|
||||||
G = Clue.GREEN
|
G = Clue.GREEN
|
||||||
@@ -153,3 +153,22 @@ class TestAddWordCommand:
|
|||||||
handle_slash_command("/addword chase", solver, Wager(), {}, solver.answers, self._opts())
|
handle_slash_command("/addword chase", solver, Wager(), {}, solver.answers, self._opts())
|
||||||
|
|
||||||
assert "chase" in solver.candidates
|
assert "chase" in solver.candidates
|
||||||
|
|
||||||
|
|
||||||
|
class TestPrintSuggestionsOrder:
|
||||||
|
def test_possible_answers_printed_in_heuristic_order_not_alphabetical(self, capsys):
|
||||||
|
# Deliberately not alphabetical so a bug that re-sorts alphabetically
|
||||||
|
# would be caught: alphabetical order here is amigo, aroma, mango.
|
||||||
|
answers = ["mango", "amigo", "aroma"]
|
||||||
|
solver = Solver(answers=answers, extra_guesses=[])
|
||||||
|
|
||||||
|
print_suggestions(solver, top_n=10, position_weight=1.0, presence_weight=1.0)
|
||||||
|
|
||||||
|
expected_order = [
|
||||||
|
word for word, _, _ in
|
||||||
|
rank_guesses(answers, answers, top_n=len(answers), position_weight=1.0, presence_weight=1.0)
|
||||||
|
]
|
||||||
|
assert expected_order != sorted(answers) # sanity check the fixture is non-alphabetical
|
||||||
|
|
||||||
|
printed_line = capsys.readouterr().out.splitlines()[2]
|
||||||
|
assert printed_line.strip() == ", ".join(expected_order)
|
||||||
|
|||||||
@@ -130,8 +130,10 @@ def handle_slash_command(line: str, solver: Solver, wager: Wager, state: dict, a
|
|||||||
def print_suggestions(solver: Solver, top_n: int, position_weight: float, presence_weight: float):
|
def print_suggestions(solver: Solver, top_n: int, position_weight: float, presence_weight: float):
|
||||||
n_remaining = len(solver.candidates)
|
n_remaining = len(solver.candidates)
|
||||||
print(f"\n{n_remaining} possible answer(s) remain.")
|
print(f"\n{n_remaining} possible answer(s) remain.")
|
||||||
if n_remaining <= 20:
|
if 0 < n_remaining <= 20:
|
||||||
print(" " + ", ".join(sorted(solver.candidates)))
|
ranked_candidates = rank_guesses(solver.candidates, solver.candidates, top_n=n_remaining,
|
||||||
|
position_weight=position_weight, presence_weight=presence_weight)
|
||||||
|
print(" " + ", ".join(word for word, _, _ in ranked_candidates))
|
||||||
|
|
||||||
pool = solver.hard_mode_pool()
|
pool = solver.hard_mode_pool()
|
||||||
suggestions = rank_guesses(pool, solver.candidates, top_n=top_n,
|
suggestions = rank_guesses(pool, solver.candidates, top_n=top_n,
|
||||||
|
|||||||
Reference in New Issue
Block a user