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)
Example #2
0
 def test_resistance_distance_same_node(self):
     with pytest.raises(nx.NetworkXError):
         nx.resistance_distance(self.G, 1, 1)
Example #3
0
 def test_resistance_distance_nodeB_not_in_graph(self):
     with pytest.raises(nx.NetworkXError):
         nx.resistance_distance(self.G, 1, 9)
Example #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)
Example #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")
Example #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)
Example #7
0
 def test_resistance_distance_no_weight(self):
     rd = nx.resistance_distance(self.G, 1, 3)
     assert round(rd, 5) == 1
Example #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)