Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import unittest
- from Planet import Direction, Planet
- class FirstPlanetTest(PlanetTestCase):
- def setUp(self):
- """
- Planet:
- +--+
- | |
- +-0,3------+
- | |
- 0,2-----2,2 (target)
- | /
- +-0,1 /
- | | /
- +-0,0-1,0
- |
- (start)
- """
- self.planet = Planet()
- def test_target_not_reachable_with_loop(self):
- self.planet.add_path(((0, 0), Direction.NORTH), ((0, 1), Direction.SOUTH), 1)
- self.planet.add_path(((0, 0), Direction.WEST), ((0, 1), Direction.WEST), 2)
- self.planet.add_path(((0, 0), Direction.EAST), ((1, 0), Direction.WEST), 1)
- self.planet.add_path(((0, 1), Direction.NORTH), ((0, 2), Direction.SOUTH), 1)
- self.planet.add_path(((0, 2), Direction.NORTH), ((0, 3), Direction.SOUTH), 1)
- self.planet.add_path(((0, 2), Direction.EAST), ((2, 2), Direction.WEST), 2)
- self.planet.add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 2)
- self.planet.add_path(((0, 3), Direction.EAST), ((2, 2), Direction.NORTH), 3)
- self.planet.add_path(((1, 0), Direction.NORTH), ((2, 2), Direction.SOUTH), 3)
- self.assertIsNone(self.planet.shortest_path((0, 0), (1, 2)))
- def test_empty_planet(self):
- self.assertIsNone(self.planet.shortest_path((0, 0), (1, 2)))
- def test_shortest_path(self):
- self.planet.add_path(((0, 0), Direction.NORTH), ((0, 1), Direction.SOUTH), 1)
- self.planet.add_path(((0, 0), Direction.WEST), ((0, 1), Direction.WEST), 2)
- self.planet.add_path(((0, 0), Direction.EAST), ((1, 0), Direction.WEST), 1)
- self.planet.add_path(((0, 1), Direction.NORTH), ((0, 2), Direction.SOUTH), 1)
- self.planet.add_path(((0, 2), Direction.NORTH), ((0, 3), Direction.SOUTH), 1)
- self.planet.add_path(((0, 2), Direction.EAST), ((2, 2), Direction.WEST), 2)
- self.planet.add_path(((0, 3), Direction.NORTH), ((0, 3), Direction.WEST), 2)
- self.planet.add_path(((0, 3), Direction.EAST), ((2, 2), Direction.NORTH), 3)
- self.planet.add_path(((1, 0), Direction.NORTH), ((2, 2), Direction.SOUTH), 3)
- self.assertEqual(self.planet.shortest_path((0, 0), (2, 2)), [((0, 0), Direction.EAST), ((1, 0), Direction.NORTH)])
- if __name__ == "__main__":
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement