Skip to content

Add input validation and tests for get_result function#39

Merged
sgauth01 merged 4 commits intomainfrom
test_get_result
Jan 17, 2026
Merged

Add input validation and tests for get_result function#39
sgauth01 merged 4 commits intomainfrom
test_get_result

Conversation

@yhouyang02
Copy link
Collaborator

Enhanced get_result with type and value checks for inputs, raising appropriate exceptions for invalid cases. Added a new test suite to verify correct behavior and error handling, including edge cases and repeated letters.

Enhanced get_result with type and value checks for inputs, raising appropriate exceptions for invalid cases. Added a new test suite to verify correct behavior and error handling, including edge cases and repeated letters.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements the get_result function for a word-guessing game with comprehensive input validation and error handling. The PR adds type checking, length validation, and corpus validation for both target and guess parameters, along with the core algorithm to compare words and return feedback codes.

Changes:

  • Implemented complete get_result function with input validation and word comparison logic
  • Fixed import path from relative to absolute import
  • Added comprehensive test suite covering valid inputs, error cases, and edge cases with repeated letters

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/wordguess/get_result.py Implemented input validation (type, length, corpus membership) and word comparison algorithm with proper handling of repeated letters
tests/unit/test_get_result.py Added new test file with fixtures and test cases for error handling and various word comparison scenarios
Comments suppressed due to low confidence (1)

src/wordguess/get_result.py:39

  • The expected result in the docstring example is incorrect. For get_result('stare', 'tears'), the correct result should be '11221', not '11211'. The test file correctly expects '11221' at line 33. Tracing the algorithm: exact matches are at positions 2 (a=a) and 3 (r=r), giving '??22?'. Then 't', 'e', and 's' from the guess all exist in different positions in the target, resulting in '11221'.
    '11211'

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

get_result("apple", "longword", corpus=mock_corpus)

with pytest.raises(ValueError, match="not a valid word"):
get_result("apple", "zzzzz", corpus=mock_corpus)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for ValueError when a word is not in the corpus only tests the case where the guess is invalid. There's no test for the case where the target is invalid (e.g., get_result('zzzzz', 'apple', corpus=mock_corpus)). Although less likely in practice, this case should be tested since the function validates both parameters.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 15, 2026 09:32
Copy link

Copilot AI commented Jan 15, 2026

@yhouyang02 I've opened a new pull request, #40, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

src/wordguess/get_result.py:39

  • The expected output is incorrect. With target='stare' and guess='tears', the correct result should be '11221' not '11211'. Position 2 and 3 have exact matches (a,r), positions 0,1,4 all have letters in wrong positions (t,e,s).
    >>> get_result("stare", "tears")
    '11211'

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sgauth01 sgauth01 merged commit 2dced66 into main Jan 17, 2026
8 of 9 checks passed
@sgauth01 sgauth01 deleted the test_get_result branch January 17, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement function and tests for get_result

4 participants