Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import unittest
  4. from Planet import Direction, Planet
  5.  
  6.  
  7. class FirstPlanetTest(PlanetTestCase):
  8.  
  9. def setUp(self):
  10. """
  11. Planet:
  12.  
  13. +--+
  14. | |
  15. +-0,3------+
  16. | |
  17. 0,2-----2,2 (target)
  18. | /
  19. +-0,1 /
  20. | | /
  21. +-0,0-1,0
  22. |
  23. (start)
  24.  
  25. """
  26.  
  27. self.planet = Planet()
  28.  
  29.  
  30. def test_target_not_reachable_with_loop(self):
  31. self.planet.add_path(((0, 0), Direction.NORTH), ((0, 1), Direction.SOUTH), 1)
  32. self.planet.add_path(((0, 0), Direction.WEST), ((0, 1), Direction.WEST), 2)
  33. self.planet.add_path(((0, 0), Direction.EAST), ((1, 0), Direction.WEST), 1)
  34. self.planet.add_path(((0, 1), Direction.NORTH), ((0, 2), Direction.SOUTH), 1)
  35. self.planet.add_path(((0, 2), Direction.NORTH), ((0, 3), Direction.SOUTH), 1)
  36. self.planet.add_path(((0, 2), Direction.EAST), ((2, 2), Direction.WEST), 2)
  37. self.planet.add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 2)
  38. self.planet.add_path(((0, 3), Direction.EAST), ((2, 2), Direction.NORTH), 3)
  39. self.planet.add_path(((1, 0), Direction.NORTH), ((2, 2), Direction.SOUTH), 3)
  40. self.assertIsNone(self.planet.shortest_path((0, 0), (1, 2)))
  41.  
  42.  
  43. def test_empty_planet(self):
  44. self.assertIsNone(self.planet.shortest_path((0, 0), (1, 2)))
  45.  
  46.  
  47. def test_shortest_path(self):
  48. self.planet.add_path(((0, 0), Direction.NORTH), ((0, 1), Direction.SOUTH), 1)
  49. self.planet.add_path(((0, 0), Direction.WEST), ((0, 1), Direction.WEST), 2)
  50. self.planet.add_path(((0, 0), Direction.EAST), ((1, 0), Direction.WEST), 1)
  51. self.planet.add_path(((0, 1), Direction.NORTH), ((0, 2), Direction.SOUTH), 1)
  52. self.planet.add_path(((0, 2), Direction.NORTH), ((0, 3), Direction.SOUTH), 1)
  53. self.planet.add_path(((0, 2), Direction.EAST), ((2, 2), Direction.WEST), 2)
  54. self.planet.add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 2)
  55. self.planet.add_path(((0, 3), Direction.EAST), ((2, 2), Direction.NORTH), 3)
  56. self.planet.add_path(((1, 0), Direction.NORTH), ((2, 2), Direction.SOUTH), 3)
  57. self.assertEqual(self.planet.shortest_path((0, 0), (2, 2)), [((0, 0), Direction.EAST), ((1, 0), Direction.NORTH)])
  58.  
  59.  
  60. if __name__ == "__main__":
  61. unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement