### view env/lib/python3.9/site-packages/networkx/algorithms/assortativity/tests/test_neighbor_degree.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line source
```
import networkx as nx
from networkx.testing import almost_equal

class TestAverageNeighbor:
def test_degree_p4(self):
G = nx.path_graph(4)
answer = {0: 2, 1: 1.5, 2: 1.5, 3: 2}
nd = nx.average_neighbor_degree(G)

D = G.to_directed()
nd = nx.average_neighbor_degree(D)

D = G.to_directed()
nd = nx.average_neighbor_degree(D)

D = G.to_directed()
nd = nx.average_neighbor_degree(D, source="in", target="in")

def test_degree_p4_weighted(self):
G = nx.path_graph(4)
G["weight"] = 4
answer = {0: 2, 1: 1.8, 2: 1.8, 3: 2}
nd = nx.average_neighbor_degree(G, weight="weight")

D = G.to_directed()
nd = nx.average_neighbor_degree(D, weight="weight")

D = G.to_directed()
nd = nx.average_neighbor_degree(D, weight="weight")
nd = nx.average_neighbor_degree(D, source="out", target="out", weight="weight")

D = G.to_directed()
nd = nx.average_neighbor_degree(D, source="in", target="in", weight="weight")

def test_degree_k4(self):
G = nx.complete_graph(4)
answer = {0: 3, 1: 3, 2: 3, 3: 3}
nd = nx.average_neighbor_degree(G)

D = G.to_directed()
nd = nx.average_neighbor_degree(D)

D = G.to_directed()
nd = nx.average_neighbor_degree(D)

D = G.to_directed()
nd = nx.average_neighbor_degree(D, source="in", target="in")

def test_degree_k4_nodes(self):
G = nx.complete_graph(4)
answer = {1: 3.0, 2: 3.0}
nd = nx.average_neighbor_degree(G, nodes=[1, 2])