code: def test_degree_p4_weighted(self):
      G = nx.path_graph(4)
      G[1][2]["weight"] = 4
      answer = {0: 2, 1: 1.8, 2: 1.8, 3: 2}
      nd = nx.average_neighbor_degree(G, weight="weight")
      assert nd == answer
  
      D = G.to_directed()
      nd = nx.average_neighbor_degree(D, weight="weight")
      assert nd == answer
  
      D = nx.DiGraph(G.edges(data=True))
      print(D.edges(data=True))
      nd = nx.average_neighbor_degree(D, weight="weight")
      assert nd == {0: 1, 1: 1, 2: 0, 3: 0}
      nd = nx.average_neighbor_degree(D, "out", "out", weight="weight")
      assert nd == {0: 1, 1: 1, 2: 0, 3: 0}
      nd = nx.average_neighbor_degree(D, "in", "in", weight="weight")
      assert nd == {0: 0, 1: 0, 2: 1, 3: 1}
      nd = nx.average_neighbor_degree(D, "in", "out", weight="weight")
      assert nd == {0: 0, 1: 1, 2: 1, 3: 1}
      nd = nx.average_neighbor_degree(D, "out", "in", weight="weight")
      assert nd == {0: 1, 1: 1, 2: 1, 3: 0}
      nd = nx.average_neighbor_degree(
          D, source="in+out", weight="weight"
      )
      assert nd == {0: 1.0, 1: 1.0, 2: 0.8, 3: 1.0}
      nd = nx.average_neighbor_degree(
          D, target="in+out", weight="weight"
      )
      assert nd == {0: 2.0, 1: 2.0, 2: 1.0, 3: 0.0}
  
      D = G.to_directed()
      nd = nx.average_neighbor_degree(D, weight="weight")
      assert nd == answer
      nd = nx.average_neighbor_degree(
          D, source="out", target="out", weight="weight"
      )
      assert nd == answer
  
      D = G.to_directed()
      nd = nx.average_neighbor_degree(
          D, source="in", target="in", weight="weight"
      )
      assert nd == answer
  
file_path: networkx/networkx/algorithms/assortativity/tests/test_neighbor_degree.py
imports: import pytest
  import networkx
label_desc: Use image node_id 2 for calling the TestAverageNeighbor obj's underlying member method code with example usage: obj.test_degree_p4_weighted() without return types