Replace the ordinal ladder and make the keyword count a parameter - #20
Conversation
The four-branch if/elif chain in getKeywords() appended "th" to every number past 3, so raising the count would have produced "21th". A small ordinal() method now returns the correct suffix for any number, and the count is a constructor parameter (numKeywords, default 10) instead of a local literal. The ten prompts the program prints today are unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
createPairs() reads keywords two at a time, so an odd numKeywords would reach the IndexError tracked in #9 several calls later. The constructor now raises ValueError for odd or non-positive counts instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Self-review rubricScored against the diff at Universal
Repo-specific
Judgement call flagged for the owner: the constructor guard's message and its Path-anchored notes (no inline comments were posted — see the harness note in the PR body's Gardener line):
This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener). drafted by Claude on behalf of Daniel Stephenson |
Summary
if/elif/elif/elseordinal ladder ingetKeywords()has been replaced by a smallordinal()method that returns the correct suffix for any number (1st,2nd,3rd,4th,11th–13th,21st,22nd,23rd,111th,121st, …). The oldelsebranch appended"th"unconditionally, so any count past 20 would have produced21th.IdeaCollisionGeneratornow takes anumKeywordsconstructor parameter, defaulting to10, andgetKeywords()readsself.numKeywords. The CLI entry point is untouched and still collects ten.createPairs()reads keywords two at a time, the constructor raisesValueErrorfor an odd or non-positive count. This was added after the inline review below pointed out that an oddnumKeywordswould otherwise reach theIndexErrortracked in createPairs() raises IndexError when the keyword count is odd #9 several calls later; rejecting the configuration up front does not decide what a trailing odd keyword should mean, so createPairs() raises IndexError when the keyword count is odd #9 is left as filed.tests/test_ideaCollisionGenerator.py: a table of ordinal suffixes, the prompts for the 21st–23rd keywords produced throughgetKeywords()itself, a four-keyword generator collecting four keywords, the default of ten, and the twoValueErrorcases.The ten prompts printed today are byte-identical to before —
testPromptsUseOrdinalLadder(unchanged) still assertsEnter 1st keyword:throughEnter 10th keyword:, and the end-to-end run below shows the same text. No prompt string, output line format, or filename has been altered, soREADME.mdandideas/example.txtremain accurate as written.Closes #10
Scope notes
.vscode/launch.json"python"→"debugpy") was selected as the one-line companion to this change, but the edit was refused again by the harness this session ran under, which treats.vscode/launch.jsonas a protected path. It is left open, exactly as after Rewrite README and narrow .gitignore #16 and Write the ideas file with "w" and an explicit utf-8 encoding #19.createPairs()on an odd keyword count) was deferred: what a trailing odd keyword should mean is a behavioural decision and is unchanged by this PR. The constructor guard keeps an odd count from reaching thatIndexErrorthrough the new parameter, butcreatePairs()itself is unchanged and still raises when called directly on an odd list, astestOddKeywordCountRaisesIndexErrorrecords.COPYRIGHT.mdcontradictsLICENSE) was deferred: which licence governs is the owner's decision.Test plan
All commands were run from the repository root on Python 3.8.10 during this session.
python3 -m py_compile src/collide.py src/ideaCollisionGenerator.py→compile OKpython3 -m unittest discover -s tests -v→Ran 24 tests in 0.008s/OK(18 before this branch, 24 after)This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).
🤖 Generated with Claude Code
drafted by Claude on behalf of Daniel Stephenson