def test_4_generalisation_sort_order(self): # START AGAIN - more tests, ensure children nodes with children themselves, are prioritised # and furthermore, children with the most descendants are prioritised even more. # B,B1 --|> A # C --|> B g = Graph() c = GraphNode('C', 0, 0, 200, 200) b = GraphNode('B', 0, 0, 200, 200) b1 = GraphNode('B1', 0, 0, 200, 200) a = GraphNode('A', 0, 0, 200, 200) c2 = GraphNode('C2', 0, 0, 200, 200) d = GraphNode('D', 0, 0, 200, 200) # add out of order g.AddNode(b1) g.AddNode(b) g.AddNode(a) g.AddNode(c) g.AddNode(c2) g.AddNode(d) g.AddEdge(c2, b1)['uml_edge_type'] = 'generalisation' g.AddEdge(d, c)['uml_edge_type'] = 'generalisation' g.AddEdge(c, b)['uml_edge_type'] = 'generalisation' g.AddEdge(b1, a)['uml_edge_type'] = 'generalisation' g.AddEdge(b, a)['uml_edge_type'] = 'generalisation' nodelist_normal = [node.id for node in g.nodes] nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'B1', 'C', 'D', 'C2'] #print "nodelist_normal", nodelist_normal #print "nodelist_sorted_expected", nodelist_sorted_expected #print "nodelist_sorted", nodelist_sorted assert nodelist_sorted_expected == nodelist_sorted
def test_3_generalisation_sort_order(self): # START AGAIN - more tests, ensure children nodes with children themselves, are prioritised # C2,C --|> B # B,B2 --|> A g = Graph() c = GraphNode('C', 0, 0, 200, 200) c2 = GraphNode('C2', 0, 0, 200, 200) b = GraphNode('B', 0, 0, 200, 200) b2 = GraphNode('B2', 0, 0, 200, 200) a = GraphNode('A', 0, 0, 200, 200) # add out of order g.AddNode(b2) g.AddNode(b) g.AddNode(c) g.AddNode(c2) g.AddNode(a) g.AddEdge(c, b)['uml_edge_type'] = 'generalisation' g.AddEdge(c2, b)['uml_edge_type'] = 'generalisation' g.AddEdge(b2, a)['uml_edge_type'] = 'generalisation' g.AddEdge(b, a)['uml_edge_type'] = 'generalisation' nodelist_normal = [node.id for node in g.nodes] nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'B2', 'C', 'C2'] nodelist_sorted_expected2 = ['A', 'B', 'B2', 'C2', 'C'] #print "nodelist_normal", nodelist_normal #print "nodelist_sorted_expected", nodelist_sorted_expected #print "nodelist_sorted", nodelist_sorted assert nodelist_sorted_expected == nodelist_sorted or \ nodelist_sorted_expected2 == nodelist_sorted
def test_2_generalisation_sort_order(self): # C --|> B --|> A g = Graph() c = GraphNode('C', 0, 0, 200, 200) b = GraphNode('B', 0, 0, 200, 200) # parent of C a = GraphNode('A', 0, 0, 200, 200) # parent of B # add out of order g.AddNode(b) g.AddNode(c) g.AddNode(a) g.AddEdge(c, b)['uml_edge_type'] = 'generalisation' g.AddEdge(b, a)['uml_edge_type'] = 'generalisation' nodelist_normal = [node.id for node in g.nodes] nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'C'] #print "nodelist_normal", nodelist_normal #print "nodelist_sorted_expected", nodelist_sorted_expected #print "nodelist_sorted", nodelist_sorted assert nodelist_sorted_expected == nodelist_sorted # D --|> C --|> B --|> A d = GraphNode('D', 0, 0, 200, 200) g.AddNode(d) g.AddEdge(d, c)['uml_edge_type'] = 'generalisation' nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'C', 'D'] assert nodelist_sorted_expected == nodelist_sorted # E node not connected to anything e = GraphNode('E', 0, 0, 200, 200) g.AddNode(e) nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'C', 'D', 'E'] assert nodelist_sorted_expected == nodelist_sorted # D --|> C --|> B --|> A # E # C2 --|> B c2 = GraphNode('C2', 0, 0, 200, 200) g.AddNode(c2) g.AddEdge(c2, b)['uml_edge_type'] = 'generalisation' nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'C', 'C2', 'D', 'E'] assert nodelist_sorted_expected == nodelist_sorted
def test_5_generalisation_sort_order(self): # START AGAIN - more tests, check stranger trees, though the algorithm # is proving pretty smart, prioritising children who have children to the left # B,B1,C,K --|> A # D --|> C g = Graph() a = GraphNode('A', 0, 0, 200, 200) b = GraphNode('B', 0, 0, 200, 200) b1 = GraphNode('B1', 0, 0, 200, 200) c = GraphNode('C', 0, 0, 200, 200) k = GraphNode('K', 0, 0, 200, 200) d = GraphNode('D', 0, 0, 200, 200) # add out of order g.AddNode(b1) g.AddNode(b) g.AddNode(a) g.AddNode(c) g.AddNode(k) g.AddNode(d) g.AddEdge(k, a)['uml_edge_type'] = 'generalisation' g.AddEdge(d, c)['uml_edge_type'] = 'generalisation' g.AddEdge(c, a)['uml_edge_type'] = 'generalisation' g.AddEdge(b1, a)['uml_edge_type'] = 'generalisation' g.AddEdge(b, a)['uml_edge_type'] = 'generalisation' nodelist_normal = [node.id for node in g.nodes] nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] #print "nodelist_normal", nodelist_normal #print "nodelist_sorted_expected", nodelist_sorted_expected #print "nodelist_sorted", nodelist_sorted assert nodelist_sorted[0] == 'A' assert nodelist_sorted[1] == 'C' assert nodelist_sorted[-1] == 'D' nodelist_sorted_annotated = [ (node.id, annotation) for node, annotation in g.nodes_sorted_by_generalisation ] assert nodelist_sorted_annotated[0] == ('A', 'root') assert nodelist_sorted_annotated[1] == ('C', 'fc') assert nodelist_sorted_annotated[-1] == ('D', 'fc') assert ('K', 'tab') in nodelist_sorted_annotated assert ('B', 'tab') in nodelist_sorted_annotated assert ('B1', 'tab') in nodelist_sorted_annotated
def test_6_generalisation_sort_order(self): # START AGAIN - more tests, check stranger trees # B,D,F --|> A # G --|> C --|> B # E --|> D g = Graph() a = GraphNode('A', 0, 0, 200, 200) b = GraphNode('B', 0, 0, 200, 200) c = GraphNode('C', 0, 0, 200, 200) d = GraphNode('D', 0, 0, 200, 200) e = GraphNode('E', 0, 0, 200, 200) f = GraphNode('F', 0, 0, 200, 200) h = GraphNode('H', 0, 0, 200, 200) # add out of order g.AddNode(f) g.AddNode(b) g.AddNode(a) g.AddNode(h) g.AddNode(c) g.AddNode(e) g.AddNode(d) g.AddEdge(b, a)['uml_edge_type'] = 'generalisation' g.AddEdge(d, a)['uml_edge_type'] = 'generalisation' g.AddEdge(f, a)['uml_edge_type'] = 'generalisation' g.AddEdge(h, c)['uml_edge_type'] = 'generalisation' g.AddEdge(c, b)['uml_edge_type'] = 'generalisation' g.AddEdge(e, d)['uml_edge_type'] = 'generalisation' nodelist_normal = [node.id for node in g.nodes] nodelist_sorted = [ node.id for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected = ['A', 'B', 'D', 'F', 'C', 'H', 'E'] assert nodelist_sorted_expected == nodelist_sorted nodelist_sorted_annotated = [ (node.id, annotation) for node, annotation in g.nodes_sorted_by_generalisation ] nodelist_sorted_expected_annotated = [('A', 'root'), ('B', 'fc'), ('D', 'tab'), ('F', 'tab'), ('C', 'fc'), ('H', 'fc'), ('E', 'root')] assert nodelist_sorted_expected_annotated == nodelist_sorted_annotated