Uh oh!
There was an error while loading. Please reload this page.
UPDATED rat_in_maze.py - #9148
Conversation
…mmit tests while raising PR.
| 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]]: |
Muhammadummerr
commented
Oct 2, 2023
@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?). |
cclauss
commented
Oct 3, 2023
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. |
Muhammadummerr
commented
Oct 3, 2023
Okay,Based on my understanding of your request, the program should return both the solution maze and a flag. |
cclauss
commented
Oct 3, 2023
No. The function should return a solution if there is one and raise an ValueError if there is no solution. |
Muhammadummerr
commented
Oct 3, 2023
I have made these changes. |
Muhammadummerr
commented
Oct 3, 2023
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. |
| [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
Muhammadummerr
commented
Oct 4, 2023
All Test case are passed on my device but failing in build check. |
cclauss
commented
Oct 4, 2023
Looking better! |
cclauss
commented
Oct 4, 2023
________________ [doctest] backtracking.rat_in_maze.solve_maze _________________ /home/runner/work/Python/Python/backtracking/rat_in_maze.py:37: DocTestFailure |
Muhammadummerr
commented
Oct 4, 2023
This same test case passed on my local device because I used (optionflags=doctest.NORMALIZE_WHITESPACE), so why is it failing here? |
Muhammadummerr
commented
Oct 4, 2023
I guess; it would be more helpful for understanding to run the program with different source and destination points to find the path. |
Muhammadummerr
commented
Oct 4, 2023
Does this program require any further changes, or is it okay as it is? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| 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: