def test_astar_path(self):
     """Test that paths are constructed exclusive of start, inclusive of end
     """
     start = nodes.RectNode((0, 0))
     end = nodes.RectNode((5, 0))
     self.assertEquals(list(algorithms.astar(start, end)),
         [nodes.RectNode((i, 0)) for i in xrange(1, 6)])
 def test_astar_failure(self):
     try:
         f = open(mapname)
         start, end = load_map.file_to_tile(f)
         walkable = start.walkable
         self.assertEquals(algorithms.astar(start, end), None)
     finally:
         f.close()
 def test_astar_success(self):
     try:
         f = open(mapname)
         start, end = load_map.file_to_tile(f)
         walkable = start.walkable
         path = algorithms.astar(start, end)
         self.verify_path(walkable, path)
     finally:
         f.close()
 def getPathToSink(self,fromCell):
     """
     Added support for multiple sinks
     """
     distances={node: math.hypot(node.pos[0]-fromCell.pos[0],node.pos[1]-fromCell.pos[1]) for node in self.sink} 
     
     sorted_distances = sorted(distances.iteritems(), key=operator.itemgetter(1)) 
                     
     for i in xrange(len(self.sink)):
         toCell=sorted_distances[0][0]
         
         nodes=astar(fromCell, toCell)
         if nodes is not None:
             path=[node.pos for node in nodes]
             return path
     
     return None #no path to sink
 def test_astar_noop(self):
     node = nodes.RectNode((0, 0))
     self.assertEquals(len(list(algorithms.astar(node, node))), 0)
 def getPath(self,fromCell,toCell):
     return  [node.pos for node in astar(fromCell, toCell)]