Ejemplo n.º 1
0
 def test_remove_edge(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.remove_edge(1, 2)
     assert_graph_eq(rule.lhs, self.pattern)
     assert(('d', 'a') in rule.p.edges())
     assert(('s', 'x') in rule.rhs.edges())
     return
Ejemplo n.º 2
0
 def test_add_edge(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.add_edge(4, 2)
     assert_graph_eq(rule.lhs, self.pattern)
     assert_graph_eq(rule.p, self.p)
     assert(('s', 'y') in rule.rhs.edges())
     return
Ejemplo n.º 3
0
 def test_add_edge_attrs(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.add_edge_attrs(4, 1, {'amazing': True})
     assert_graph_eq(rule.p, self.p)
     t = {'amazing': {True}}
     normalize_attrs(t)
     assert(rule.rhs.edge['s']['x'] == t)
     return
Ejemplo n.º 4
0
 def test_merge_nodes(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     new_name = rule.merge_nodes(1, 4)
     assert_graph_eq(rule.lhs, self.pattern)
     assert_graph_eq(rule.p, self.p)
     assert(new_name in rule.rhs.nodes())
     assert((new_name, new_name) in rule.rhs.edges())
     assert((new_name, 'y') in rule.rhs.edges())
     return
Ejemplo n.º 5
0
 def test_pullback_complement(self):
     C, homAC, homCD = pullback_complement(self.A, self.B, self.D,
                                           self.homAB, self.homBD)
     assert_equals(type(C), nx.DiGraph)
     test_graph = get_relabeled_graph(self.C, {
         2: "circle",
         3: "dark_circle",
         "dark_square": "dark_square"
     })
     assert_graph_eq(test_graph, C)
     assert (id(self.D) != id(C))
Ejemplo n.º 6
0
 def test_add_node(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.add_node('g', {'a': 1})
     assert_graph_eq(rule.p, self.p)
     assert_graph_eq(rule.lhs, self.pattern)
     assert('g' in rule.rhs)
     t = {'a': set([1])}
     normalize_attrs(t)
     assert(rule.rhs.node['g'] == t)
     return
Ejemplo n.º 7
0
 def test_clone_node(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.clone_node(2)
     assert_graph_eq(rule.lhs, self.pattern)
     assert('b1' in rule.p.nodes())
     assert('y1' in rule.rhs.nodes())
     assert(('a', 'b1') in rule.p.edges())
     assert(('b1', 'c') in rule.p.edges())
     assert(('x', 'y1') in rule.rhs.edges())
     assert(('t', 'y1') in rule.rhs.edges())
     return
Ejemplo n.º 8
0
 def test_remove_node(self):
     rule = Rule(self.p, self.pattern, self.rhs,
                 self.p_lhs, self.p_rhs)
     rule.remove_node(2)
     assert_graph_eq(rule.lhs, self.pattern)
     assert('b' not in rule.p.nodes())
     assert(('a', 'b') not in rule.p.edges())
     assert(('b', 'c') not in rule.p.edges())
     assert('y' not in rule.rhs.nodes())
     assert(('x', 'y') not in rule.rhs.edges())
     assert(('t', 'y') not in rule.rhs.edges())
     assert(('y', 'z') not in rule.rhs.edges())
     return
Ejemplo n.º 9
0
 def test_pullpack_complement_inplace(self):
     D_copy = copy.deepcopy(self.D)
     C, homAC, homCD = pullback_complement(self.A,
                                           self.B,
                                           D_copy,
                                           self.homAB,
                                           self.homBD,
                                           inplace=True)
     assert_equals(type(C), nx.DiGraph)
     test_graph = get_relabeled_graph(self.C, {
         2: "circle",
         3: "dark_circle",
         "dark_square": "dark_square"
     })
     assert_graph_eq(test_graph, C)
     assert (id(D_copy) == id(C))