Skip to content

state-of-tic-tac-toe: add missing test cases for invalid board states - #3153

Open
MathJAY10 wants to merge 2 commits into
exercism:mainfrom
MathJAY10:add-state-of-tic-tac-toe-tests
Open

state-of-tic-tac-toe: add missing test cases for invalid board states#3153
MathJAY10 wants to merge 2 commits into
exercism:mainfrom
MathJAY10:add-state-of-tic-tac-toe-tests

Conversation

@MathJAY10

Copy link
Copy Markdown

Summary of Changes(For Issue #3150 )

This PR implements missing canonical test cases for state-of-tic-tac-toe from problem-specifications:

  • Added missing test cases in StateOfTicTacToeTest.java:
    • 5a84757a-fc86-4328-aec9-a5759e6ed35d: Invalid board - O kept playing after X wins
    • cf25543d-583a-4656-b9ab-f82dc00a4a02: Invalid board - X kept playing after O wins
  • Updated Reference Solution:
    • Updated .meta/src/reference/java/StateOfTicTacToe.java to validate move counts after a victory condition is met.

Testing

Ran ./gradlew test locally — all 29 tests completed successfully with 0 failures.

Closes #3150

@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!

@jagdish-15 jagdish-15 left a comment

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.

Please update the test cases to match the latest canonical-data.json rather than using assumed values, and remove the comments that were added since they aren't needed in the final solution. Also, don't forget to update test.toml using configlet (see #2959 for more information).

public void testInvalidBoardOKeptPlayingAfterXWins() {

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> stateOfTicTacToe.determineState(new String[]{"XXX", "OO ", "O "}))

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.

Please update the test values to match those in the canonical-data.json

public void testInvalidBoardXKeptPlayingAfterOWins() {

assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> stateOfTicTacToe.determineState(new String[]{"OOO", "XX ", "XX "}))

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.

Comment on lines +54 to +55
// --- NAYE CHECKS START ---
// Agar X jeeta hai, toh xCount zaroor (oCount + 1) hona chahiye. Agar barabar hai, matlab O ne extra move chala!

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.

Suggested change
// --- NAYE CHECKS START ---
// Agar X jeeta hai, toh xCount zaroor (oCount + 1) hona chahiye. Agar barabar hai, matlab O ne extra move chala!

);
}

// Agar O jeeta hai, toh xCount zaroor oCount ke barabar hona chahiye. Agar xCount zyaada hai, matlab X ne extra move chala!

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.

Suggested change
// Agar O jeeta hai, toh xCount zaroor oCount ke barabar hona chahiye. Agar xCount zyaada hai, matlab X ne extra move chala!

"Impossible board: game should have ended after the game was won"
);
}
// --- NAYE CHECKS END ---

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.

Suggested change
// --- NAYE CHECKS END ---

@MathJAY10

Copy link
Copy Markdown
Author

Hi @jagdish-15 , I have updated StateOfTicTacToeTest.java to align with canonical-data.json and cleaned up the comments in StateOfTicTacToe.java. All tests are passing locally. Could you please take another look?

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.

[configlet] state-of-tic-tac-toe: missing test cases

2 participants