def test_empty(self): """ Verify that an empty directed graph results in no compressor nodes """ G = nx.DiGraph() compressed_graph, c_nodes = nx.dedensify(G, threshold=2) assert c_nodes == set()
def test_dedensify_edge_count(self): """ Verifies that dedensify produced the correct number of comrpessor nodes in a directed graph """ G = self.build_original_graph() original_edge_count = len(G.edges()) c_G, c_nodes = nx.dedensify(G, threshold=2) compressed_edge_count = len(c_G.edges()) assert compressed_edge_count <= original_edge_count compressed_G = self.build_compressed_graph() assert compressed_edge_count == len(compressed_G.edges())
def test_dedensify_edge_count(self): """ Verifies that dedensify produced the correct number of edges in an undirected graph """ G = self.build_original_graph() c_G, c_nodes = nx.dedensify(G, threshold=2, copy=True) compressed_edge_count = len(c_G.edges()) verified_original_edge_count = len(G.edges()) assert compressed_edge_count <= verified_original_edge_count verified_compressed_G = self.build_compressed_graph() verified_compressed_edge_count = len(verified_compressed_G.edges()) assert compressed_edge_count == verified_compressed_edge_count
def test_dedensify_edges(self): """ Verifies that dedensify produced the correct edges to/from compressor nodes in a directed graph """ G = self.build_original_graph() compressed_G = self.build_compressed_graph() compressed_graph, c_nodes = nx.dedensify(G, threshold=2) for s, t in compressed_graph.edges(): o_s = "".join(sorted(s)) o_t = "".join(sorted(t)) compressed_graph_exists = compressed_graph.has_edge(s, t) verified_compressed_exists = compressed_G.has_edge(o_s, o_t) assert compressed_graph_exists == verified_compressed_exists assert len(c_nodes) == len(self.c_nodes)
def test_dedensify_edges(self): """ Verifies that dedensify produced correct compressor nodes and the correct edges to/from the compressor nodes in an undirected graph """ G = self.build_original_graph() c_G, c_nodes = nx.dedensify(G, threshold=2) v_compressed_G = self.build_compressed_graph() for s, t in c_G.edges(): o_s = "".join(sorted(s)) o_t = "".join(sorted(t)) has_compressed_edge = c_G.has_edge(s, t) verified_has_compressed_edge = v_compressed_G.has_edge(o_s, o_t) assert has_compressed_edge == verified_has_compressed_edge assert len(c_nodes) == len(self.c_nodes)