Conversation
…mmit tests while raising PR.
backtracking/rat_in_maze.py
Outdated
| source_column: int, | ||
| destination_row: int, | ||
| destination_column: int, | ||
| ) -> list[list[int]] | None: |
There was a problem hiding this comment.
Returning two different datatypes pushes work on the caller. Please consider raising an exception if there is no solution.
There was a problem hiding this comment.
See my remark in the general discussion of this Pull Request.
There was a problem hiding this comment.
| ) -> list[list[int]] | None: | |
| ) -> list[list[int]]: |
|
@cclauss Is there something I'm missing? |
|
Ok so @Muhammadummerr old pull request was reopened here.
@cclaus If an exception is raised, the caller still has to wrap each function call in a try-except clause and catch the correct exception. In Nim, I would use an Option type (the equivalent of Result type in Rust, I guess?). |
|
It is very true that Nim and Rust have cooler ways of dealing with exception states that Python does but raising Exceptions are quite Pythonic and are preferred to multiple different datatypes. |
|
Okay,Based on my understanding of your request, the program should return both the solution maze and a flag. |
|
No. The function should return a solution if there is one and raise an ValueError if there is no solution. |
|
I have made these changes. |
|
Okay, my mistake. I need to make some more changes. Thanks. |
|
Do we really care about changing the initial and destination cells in the maze? I do not really see the benefit of it and it just makes the implementation harder to read and understand. |
backtracking/rat_in_maze.py
Outdated
| [0, 0, 0, 0, 1] | ||
| True | ||
| >>> solve_maze(maze,0,0,len(maze)-1,len(maze)-1) | ||
| [[0, 1, 1, 1, 1], [0, 0, 0, 0, 1], [1, 1, 1, 0, 1],\ |
There was a problem hiding this comment.
Why is the output on the same line now? It makes reading the solution harder.
There was a problem hiding this comment.
https://docs.python.org/3/library/doctest.html#doctest.NORMALIZE_WHITESPACE will allow you to have doctests that ignore the whitespace so the matrix can look like a matrix.
for more information, see https://pre-commit.ci
|
All Test case are passed on my device but failing in build check. |
|
Looking better! |
|
________________ [doctest] backtracking.rat_in_maze.solve_maze _________________ /home/runner/work/Python/Python/backtracking/rat_in_maze.py:37: DocTestFailure |
This same test case passed on my local device because I used (optionflags=doctest.NORMALIZE_WHITESPACE), so why is it failing here? |
I guess; it would be more helpful for understanding to run the program with different source and destination points to find the path. |
|
Does this program require any further changes, or is it okay as it is? |
| import doctest | ||
|
|
||
| doctest.testmod() | ||
| doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE) |
There was a problem hiding this comment.
Does this work?!?
Yes, it's working on my local machine, but it's not working on the build test. That's why I added '# doctest: +NORMALIZE_WHITESPACE' to each test.
Describe your change:
Fixes #9066
I have made updates to the rat_in_maze.py file to enhance code clarity.
These updates include:
Checklist: