def test_exist_relation(self): graph_data = GraphData() graph_data.add_node({"method", "entity"}, { "qualified_name": "ArrayList.remove", "version": "1.0" }) graph_data.add_node({"method", "entity"}, { "qualified_name": "LinkedList.add", "version": "1.0" }) graph_data.add_node({"class", "entity"}, { "qualified_name": "ArrayList", "version": "1.0" }) graph_data.add_relation(3, "hasMethod", 1) graph_data.add_relation(1, "belongTo", 3) self.assertEqual(graph_data.exist_any_relation(3, 1), True) self.assertEqual(graph_data.exist_any_relation(2, 1), False) new_relations = {(3, 'hasMethod', 1), (1, 'belongTo', 3)} self.assertEqual(graph_data.get_all_relations(1, 3), new_relations)
def test_remove_node(self): graph_data = GraphData() graph_data.create_index_on_property("qualified_name", "alias") graph_data.add_node({"method"}, {"qualified_name": "ArrayList.add"}) graph_data.add_node({"override method"}, {"qualified_name": "ArrayList.pop"}) graph_data.add_node({"method"}, {"qualified_name": "ArrayList.remove"}) graph_data.add_node({"method"}, { "qualified_name": "ArrayList.clear", "alias": ["clear"] }) graph_data.add_node({"method"}, { "qualified_name": "List.clear", "alias": ["clear", "List.clear", "List clear"] }) graph_data.add_relation(1, "related to", 2) graph_data.add_relation(1, "related to", 3) graph_data.add_relation(1, "related to", 4) graph_data.add_relation(2, "related to", 3) graph_data.add_relation(3, "related to", 4) result = graph_data.remove_node(node_id=1) self.assertIsNotNone(result) self.assertIsNone(graph_data.get_node_info_dict(node_id=1))
def test_get_graph(self): graph_data = GraphData() graph_data.add_node({"method"}, {"qualified_name": "ArrayList.add"}) graph_data.add_node({"override method"}, {"qualified_name": "ArrayList.pop"}) graph_data.add_node({"method"}, {"qualified_name": "ArrayList.remove"}) graph_data.add_node({"method"}, {"qualified_name": "ArrayList.clear"}) print(graph_data.get_node_ids()) print(graph_data.get_relation_pairs_with_type()) graph_data.add_relation(1, "related to", 2) graph_data.add_relation(1, "related to", 3) graph_data.add_relation(1, "related to", 4) graph_data.add_relation(2, "related to", 3) graph_data.add_relation(3, "related to", 4) print(graph_data.get_relations(1, "related to")) print("get relation by type") print(graph_data.get_relations(relation_type="related to"))