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