2020-07-14 09:26:50 +08:00
|
|
|
import unittest
|
2017-03-28 17:07:25 +08:00
|
|
|
|
|
|
|
|
2020-07-14 09:26:50 +08:00
|
|
|
class TestGridPath(unittest.TestCase):
|
2017-03-28 17:07:25 +08:00
|
|
|
|
|
|
|
def test_grid_path(self):
|
|
|
|
grid = Grid()
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(grid.find_path(None), None)
|
|
|
|
self.assertEqual(grid.find_path([[]]), None)
|
2017-03-28 17:07:25 +08:00
|
|
|
max_rows = 8
|
|
|
|
max_cols = 4
|
|
|
|
matrix = [[1] * max_cols for _ in range(max_rows)]
|
|
|
|
matrix[1][1] = 0
|
|
|
|
matrix[2][2] = 0
|
|
|
|
matrix[3][0] = 0
|
|
|
|
matrix[4][2] = 0
|
|
|
|
matrix[5][3] = 0
|
|
|
|
matrix[6][1] = 0
|
|
|
|
matrix[6][3] = 0
|
|
|
|
matrix[7][1] = 0
|
|
|
|
result = grid.find_path(matrix)
|
|
|
|
expected = [(0, 0), (1, 0), (2, 0),
|
|
|
|
(2, 1), (3, 1), (4, 1),
|
|
|
|
(5, 1), (5, 2), (6, 2),
|
|
|
|
(7, 2), (7, 3)]
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(result, expected)
|
2017-03-28 17:07:25 +08:00
|
|
|
matrix[7][2] = 0
|
|
|
|
result = grid.find_path(matrix)
|
2020-07-14 09:26:50 +08:00
|
|
|
self.assertEqual(result, None)
|
2017-03-28 17:07:25 +08:00
|
|
|
print('Success: test_grid_path')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
test = TestGridPath()
|
|
|
|
test.test_grid_path()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-14 09:26:50 +08:00
|
|
|
main()
|