def test_adjacency2digraph_with_given_mapping(self):
     dg = self.sample_dgraph
     adj_matrix = utils.dgraph2adjacency(dg)
     node_mapping = {0: 1, 1: 2, 2: 3, 3: 4}
     computed_graph = utils._adjacency2digraph_with_given_mapping(
         adj_matrix=adj_matrix, node_mapping=node_mapping)
     self.assertEqual(dg.nodes(), computed_graph.nodes())
     self.assertEqual(dg.edges(), computed_graph.edges())
     # Checking every edge weight.
     for edge in dg.edges():
         self.assertEqual(dg.get_edge_data(edge[0], edge[1]),
                          computed_graph.get_edge_data(edge[0], edge[1]))
 def test_adjacency2digraph_without_similar_graph(self):
     dg = self.sample_dgraph
     adj_matrix = utils.dgraph2adjacency(dg)
     # We need to map the node labels to start from 0 due to the default.
     dg = nx.relabel_nodes(dg, mapping={i + 1: i for i in range(4)})
     computed_graph = utils.adjacency2digraph(adj_matrix=adj_matrix)
     self.assertEqual(dg.nodes(), computed_graph.nodes())
     self.assertEqual(dg.edges(), computed_graph.edges())
     # Checking every edge weight.
     for edge in dg.edges():
         self.assertEqual(dg.get_edge_data(edge[0], edge[1]),
                          computed_graph.get_edge_data(edge[0], edge[1]))
 def test_adjacency2digraph(self):
     dg = self.sample_dgraph
     adj_matrix = utils.dgraph2adjacency(dg)
     # We make another directed graph with the same adjacency matrix. Thus
     #   the graphs should match.
     computed_graph = utils.adjacency2digraph(adj_matrix=adj_matrix,
                                              similar_this_dgraph=dg)
     self.assertEqual(dg.nodes(), computed_graph.nodes())
     self.assertEqual(dg.edges(), computed_graph.edges())
     # Checking every edge weight.
     for edge in dg.edges():
         self.assertEqual(dg.get_edge_data(edge[0], edge[1]),
                          computed_graph.get_edge_data(edge[0], edge[1]))
 def test_dgraph2adjacency(self):
     dg = self.sample_dgraph
     expected = np.array([[0, 1, -1, 0], [0, 0, 5, 0], [-4, 0, 0, 0],
                          [2, 0, 0, 0]])
     computed = utils.dgraph2adjacency(dg)
     np_testing.assert_array_equal(expected, computed)