Skip to content

Add unit tests for the "Word Search" problem. - #22

Merged
kobukuro merged 2 commits into
mainfrom
test/add-word-search-tests
Sep 8, 2025
Merged

kobukuro merged 2 commits into
mainfrom
test/add-word-search-tests

Conversation

@kobukuro

@kobukuro kobukuro commented Sep 8, 2025

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings September 8, 2025 02:45

This comment was marked as outdated.

@kobukuro
kobukuro requested a review from Copilot September 8, 2025 02:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive unit tests for the "Word Search" problem (LeetCode 79) and refactors the implementation to use proper package structure and improved performance optimizations.

  • Adds JUnit 5 test cases covering the main examples from the problem
  • Refactors the solution to use a boolean array instead of a HashSet for visited tracking
  • Moves the implementation from root directory to proper Maven package structure

Reviewed Changes

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

File Description
src/test/java/com/leetcode/medium/WordSearch79Test.java New test file with 3 test cases covering basic functionality and edge cases
src/main/java/com/leetcode/medium/WordSearch79.java Refactored implementation with improved performance using boolean array for visited tracking
src/WordSearch79.java Removed original implementation from root directory

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


@Test
void testExist_Example1() {
char[][] board = {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}};

Copilot AI Sep 8, 2025

Copy link

Choose a reason for hiding this comment

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

The same board array is duplicated across all three test methods. Consider extracting this as a class-level constant or creating it in the setUp method to reduce code duplication.

Copilot uses AI. Check for mistakes.

@Test
void testExist_Example2() {
char[][] board = {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}};

Copilot AI Sep 8, 2025

Copy link

Choose a reason for hiding this comment

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

The same board array is duplicated across all three test methods. Consider extracting this as a class-level constant or creating it in the setUp method to reduce code duplication.

Copilot uses AI. Check for mistakes.

@Test
void testExist_Example3() {
char[][] board = {{'A', 'B', 'C', 'E'}, {'S', 'F', 'C', 'S'}, {'A', 'D', 'E', 'E'}};

Copilot AI Sep 8, 2025

Copy link

Choose a reason for hiding this comment

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

The same board array is duplicated across all three test methods. Consider extracting this as a class-level constant or creating it in the setUp method to reduce code duplication.

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +14
if (this.dfs(r + 1, c, board, word, index + 1, visited) || this.dfs(r - 1, c, board, word, index + 1, visited) || this.dfs(r, c + 1, board, word, index + 1, visited) || this.dfs(r, c - 1, board, word, index + 1, visited)) {
return true;

Copilot AI Sep 8, 2025

Copy link

Choose a reason for hiding this comment

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

This line is too long and hard to read. Consider breaking it into multiple lines or using an array/loop to iterate through the four directions for better readability.

Suggested change
if (this.dfs(r + 1, c, board, word, index + 1, visited) || this.dfs(r - 1, c, board, word, index + 1, visited) || this.dfs(r, c + 1, board, word, index + 1, visited) || this.dfs(r, c - 1, board, word, index + 1, visited)) {
return true;
int[] dr = {1, -1, 0, 0};
int[] dc = {0, 0, 1, -1};
for (int i = 0; i < 4; i++) {
if (this.dfs(r + dr[i], c + dc[i], board, word, index + 1, visited)) {
return true;
}

Copilot uses AI. Check for mistakes.
@kobukuro
kobukuro merged commit 84ac778 into main Sep 8, 2025
1 check passed
@kobukuro
kobukuro deleted the test/add-word-search-tests branch September 8, 2025 03:01
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