Skip to content

Fix MazeRecursion crash on small mazes - #7720

Open
Meherab-hsn wants to merge 1 commit into
TheAlgorithms:masterfrom
Meherab-hsn:fix-mazerecursion-small-mazes
Open

Meherab-hsn wants to merge 1 commit into
TheAlgorithms:masterfrom
Meherab-hsn:fix-mazerecursion-small-mazes

Conversation

@Meherab-hsn

Copy link
Copy Markdown

Fixes #7671.

MazeRecursion read the target cell as map[6][5], so any maze smaller than that crashed with ArrayIndexOutOfBoundsException. I reproduced it with a simple 5x5 maze before fixing.

What changed:

  • The target is now derived from the map size: map[map.length - 2][map[0].length - 2]. For the existing 8x7 maze in the tests this is exactly the same cell as before, so behaviour on current mazes does not change.
  • Null or degenerate (smaller than 3x3) maps now return null instead of crashing.
  • Added tests: a 5x5 maze for both strategies, and an unsolvable maze that returns null for both strategies.

MazeRecursionTest passes locally (3/3), including the original 8x7 test, unchanged.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.25%. Comparing base (410f087) to head (9e1eb8b).

Files with missing lines Patch % Lines
.../com/thealgorithms/backtracking/MazeRecursion.java 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7720      +/-   ##
============================================
+ Coverage     82.22%   82.25%   +0.03%     
- Complexity     8402     8408       +6     
============================================
  Files           843      843              
  Lines         26143    26147       +4     
  Branches       5101     5103       +2     
============================================
+ Hits          21495    21507      +12     
+ Misses         3854     3847       -7     
+ Partials        794      793       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[BUG] MazeRecursion crashes on small mazes

2 participants