def init_data_provider(self): return [ ( DiGraph(), [(0, 1), (0, 2)], {0, 1, 2}, [(0, True), (1, True), (2, True), (3, False)], [((0, 1), True), ((0, 2), True), ((1, 2), False)], None, { 1: {0}, 2: {0}, 0: DiGraph._sentinel }, ), ( DiGraph({0: {1, 2}}), [], {0, 1, 2}, [(0, True), (1, True), (2, True), (3, False)], [((0, 1), True), ((0, 2), True), ((1, 2), False)], None, { 1: {0}, 2: {0}, 0: DiGraph._sentinel }, ), (DiGraph({ 0: {1, 2}, 1: {0} }), [], {0, 1, 2}, [(0, True), (1, True), (2, True), (3, False)], [ ((0, 1), True), ((0, 2), True), ((1, 2), False), ((1, 0), True), ], InconsistentState, { 0: {1}, 1: {0}, 2: {0} }), ]
def test_init_acycle( self, graph: DiGraph, vertices, edges, has_edges, has_vertices, exception, inverse_graph, ): if exception: with self.assertRaises(exception): graph = AcyclicDiGraph(graph) for f, t in vertices: graph.insert(f, t) self.assertEquals(edges, graph.vertexes()) for edge, has_edge in has_edges: self.assertEquals(has_edge, graph.has_vertex(edge)) for vertice, has_vertice in has_vertices: self.assertEquals(has_vertice, graph.has_edge(*vertice)) inv_graph = graph.reverse() for edge in inv_graph.vertexes(): self.assertEqual( inverse_graph[edge], inv_graph.vertexes_to(edge), )
def test_init( self, graph: DiGraph, vertices, edges, has_edges, has_vertices, exception, inverse_graph, ): for f, t in vertices: graph.insert(f, t) self.assertEquals(edges, graph.vertexes()) for edge, has_edge in has_edges: self.assertEquals(has_edge, graph.has_vertex(edge)) for vertice, has_vertice in has_vertices: self.assertEquals(has_vertice, graph.has_edge(*vertice)) inv_graph = graph.reverse() for edge in inv_graph.vertexes(): self.assertEqual( inverse_graph[edge], inv_graph.vertexes_to(edge), )
def union_data_provider(self): return [ ( DiGraph({ 1: {2, 3}, 2: {4} }), DiGraph({ 3: {4}, 4: {5} }), { 1: {2, 3}, 2: {4}, 3: {4}, 4: {5}, 5: DiGraph._sentinel, }, None, ), ( DiGraph({ 1: {2, 3}, 2: {4} }), DiGraph({ 3: {4}, 4: {5}, 2: {1} }), { 1: {2, 3}, 2: {4, 1}, 3: {4}, 4: {5}, 5: DiGraph._sentinel, }, InconsistentState, ), ]
def test_union_acycle(self, a: DiGraph, b: DiGraph, vertices, exception): a = AcyclicDiGraph(a) b = AcyclicDiGraph(b) if exception: with self.assertRaises(exception): a.union(b) else: a.union(b) self.assertEquals(set(vertices.keys()), a.vertexes()) for edge, vertices in vertices.items(): self.assertEquals(a.vertexes_to(edge), vertices)
def setUp(self): super().setUp() self.graph_model = mem.InMemoryGraphModel( AcyclicDiGraph(DiGraph()) )
def test_union(self, a: DiGraph, b: DiGraph, vertices, exception): a.union(b) self.assertEquals(set(vertices.keys()), a.vertexes()) for edge, vertices in vertices.items(): self.assertEquals(a.vertexes_to(edge), vertices)