Skip to content

[hangman] Sync tests & Update solution to match canonical rules#3109

Open
thibault2705 wants to merge 6 commits intoexercism:mainfrom
thibault2705:sync_hangman_tests
Open

[hangman] Sync tests & Update solution to match canonical rules#3109
thibault2705 wants to merge 6 commits intoexercism:mainfrom
thibault2705:sync_hangman_tests

Conversation

@thibault2705
Copy link
Copy Markdown
Contributor

pull request

What has been done:

  • Rename and simplify method play(Observable<String> words, Observable<String> letters) to guess(String word, Observable<String> letters)
  • Add, rename output params maskedWord, state, and remainingFailures to match canonical expectations
  • Introduced MAX_FAILURES = 10 based on canonical rules
  • Added error handling for guesses after win and lose states
  • Aligned test cases with canonical scenarios

This PR partially solves issues #2959.


Reviewer Resources:

Track Policies

@github-actions
Copy link
Copy Markdown
Contributor

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

Comment thread exercises/practice/hangman/src/main/java/Hangman.java Outdated
Comment thread exercises/practice/hangman/src/main/java/Output.java Outdated
Comment thread exercises/practice/hangman/src/main/java/Output.java Outdated
@thibault2705 thibault2705 changed the title [hangman] Sync tests & Update solution to match tests.toml [hangman] Sync tests & Update solution to match canonical rules Apr 28, 2026
@thibault2705 thibault2705 requested a review from kahgoh April 28, 2026 19:02
Copy link
Copy Markdown
Member

@kahgoh kahgoh left a comment

Choose a reason for hiding this comment

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

Hey @thibault2705, sorry this review is taking a while. I have noticed over on the forums, there is a proposal to replace this Hangman exercise with Save the Cow, which is going through review at the moment. I would like to suggest holding off on this one for a bit so that we can move to Save the Cow. I think the canonical data is largely the same, so I think you'd be able to most of this to the new exercise and rename things.

public final List<Part> parts;
public final Status status;
public final Status state;
public final int remainingFailures;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at the tests, I notice not all of these fields are checked. Do we need all of them? If not, consider removing the ones no longer needed.

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We generally prefer using AssertJ over JUnit assertions (see issue #1803).

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.

2 participants