def testValidPath(self): for i in range(0,10): node = Node() node.set_data(str(i)) self.graph.nodes.append(node) for i in range(0,8): edge = Edge() edge.set_info(self.graph.nodes[i],self.graph.nodes[i+1],i) self.graph.edges.append(edge) valid_path = self.graph.is_valid_path(self.graph.nodes[:-1]) self.assertTrue(valid_path)
def testInvalidPath(self): self.graph.nodes = [] self.graph.edges = [] for i in range(1,10): node = Node() self.graph.nodes.append(node) for i in range(1,8): edge = Edge() edge.set_info(self.graph.nodes[i],self.graph.nodes[i+1],i) self.graph.edges.append(edge) self.graph.edges.remove(self.graph.edges[5]) valid_path = self.graph.is_valid_path(self.graph.nodes) self.assertFalse(valid_path)
class EdgeTest(unittest.TestCase): global edge def setUp(self): self.edge = Edge() self.edge.set_info("Source","Target",1337) def testSourceAssignment(self): source = self.edge.get_source() self.assertEquals(source,"Source") def testTargetAssignment(self): target = self.edge.get_target() self.assertEquals(target,"Target") def testWeightAssignment(self): weight = self.edge.get_weight() self.assertEquals(weight,1337)
def add_edge(self, route): edge = Edge.fromEdge(route) origin = edge.origin # We only deal with metros which has our service if(origin not in self.metros): return destination = edge.destination if(destination not in self.metros): return distance = edge.distance edge_back = Edge(destination,origin,distance) self.routes.append(edge) self.routes.append(edge_back) self.metros[origin].add_edge(edge) self.metros[destination].add_edge(edge_back)
def setUp(self): self.edge = Edge() self.edge.set_info("Source","Target",1337)