def test_resistance_distance(self):
     rd = nx.resistance_distance(self.G, 1, 3, 'weight', True)
     test_data = 1 / (1 / (2 + 4) + 1 / (1 + 3))
     assert round(rd, 5) == round(test_data, 5)
Exemple #2
0
 def test_resistance_distance_same_node(self):
     with pytest.raises(nx.NetworkXError):
         nx.resistance_distance(self.G, 1, 1)
Exemple #3
0
 def test_resistance_distance_nodeB_not_in_graph(self):
     with pytest.raises(nx.NetworkXError):
         nx.resistance_distance(self.G, 1, 9)
Exemple #4
0
 def test_resistance_distance_not_connected(self):
     with pytest.raises(nx.NetworkXError):
         self.G.add_node(5)
         nx.resistance_distance(self.G, 1, 5)
Exemple #5
0
 def test_resistance_distance_div0(self):
     with pytest.raises(ZeroDivisionError):
         self.G[1][2]["weight"] = 0
         nx.resistance_distance(self.G, 1, 3, "weight")
Exemple #6
0
 def test_resistance_distance_neg_weight(self):
     self.G[2][3]["weight"] = -4
     rd = nx.resistance_distance(self.G, 1, 3, "weight", True)
     test_data = 1 / (1 / (2 + -4) + 1 / (1 + 3))
     assert round(rd, 5) == round(test_data, 5)
Exemple #7
0
 def test_resistance_distance_no_weight(self):
     rd = nx.resistance_distance(self.G, 1, 3)
     assert round(rd, 5) == 1
Exemple #8
0
 def test_resistance_distance_noinv(self):
     rd = nx.resistance_distance(self.G, 1, 3, "weight", False)
     test_data = 1 / (1 / (1 / 2 + 1 / 4) + 1 / (1 / 1 + 1 / 3))
     assert round(rd, 5) == round(test_data, 5)