code: def test_directed_walk_generation_single_root_node(self, tree_graph):
      def _check_directed_walk(walk, n_size):
          if len(n_size) > 1 and n_size[0] > 0 and n_size[1] > 0:
              for child_pos in range(n_size[0]):
                  child = walk[child_pos + 1]
                  grandchildren_start = (
                      1 + n_size[0] + child_pos * n_size[1]
                  )
                  grandchildren_end = grandchildren_start + n_size[1]
                  grandchildren = walk[
                      grandchildren_start:grandchildren_end
                  ]
                  if child == "root":  # node with three children
                      for grandchild in grandchildren:
                          assert grandchild in [0, 1, 2]
                  elif child == "0":  # node without children
                      for grandchild in grandchildren:
                          assert grandchild == "root"
                  elif child == 1:  # node with single child
                      for grandchild in grandchildren:
                          assert grandchild in ["c1.1", "root"]
                  elif child == 2:  # node with two children
                      for grandchild in grandchildren:
                          assert grandchild in ["c2.1", "c2.2", "root"]
                  else:
                      assert 1 == 0
  
      bfw = SampledBreadthFirstWalk(tree_graph)
  
      nodes = tree_graph.node_ids_to_ilocs(["root"])
      n = 1
      n_size = [0]
  
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      assert (
          len(subgraphs[0]) == 1
      )  # all elements should be the same node
      assert (
          subgraphs[0][0] == tree_graph.node_ids_to_ilocs(["root"])[0]
      )
  
      n_size = [1]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      assert len(subgraphs[0]) == expected_bfw_size(
          n_size
      )  # "root" plus child
      assert (
          subgraphs[0][0] == tree_graph.node_ids_to_ilocs(["root"])[0]
      )
  
      n_size = [2, 2]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      # "root" plus 2 * child + 2 * 2 * grandchild or None
      assert len(subgraphs[0]) == expected_bfw_size(n_size)
      assert (
          subgraphs[0][0] == tree_graph.node_ids_to_ilocs(["root"])[0]
      )
      assert subgraphs[0][1] != -1
      assert subgraphs[0][2] != -1
      _check_directed_walk(
          tree_graph.node_ilocs_to_ids(subgraphs[0]), n_size
      )
  
      n_size = [3, 2]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      # "root" plus 3 * child + 3 * 2 * grandchild or None
      assert len(subgraphs[0]) == expected_bfw_size(n_size)
      assert (
          subgraphs[0][0] == tree_graph.node_ids_to_ilocs(["root"])[0]
      )
      _check_directed_walk(
          tree_graph.node_ilocs_to_ids(subgraphs[0]), n_size
      )
  
      n = 3
      n_size = [0]
  
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      for subgraph in subgraphs:
          assert len(subgraph) == 1  # root node only
          assert (
              subgraph[0] == tree_graph.node_ids_to_ilocs(["root"])[0]
          )
  
      n_size = [1]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      for subgraph in subgraphs:
          # "root" plus child
          assert len(subgraph) == expected_bfw_size(n_size)
          assert (
              subgraph[0] == tree_graph.node_ids_to_ilocs(["root"])[0]
          )
  
      n = 99
      n_size = [2, 2]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      for subgraph in subgraphs:
          # "root" plus 2 * child + 2 * 2 * grandchild or None
          assert len(subgraph) == expected_bfw_size(n_size)
          assert (
              subgraph[0] == tree_graph.node_ids_to_ilocs(["root"])[0]
          )
          _check_directed_walk(
              tree_graph.node_ilocs_to_ids(subgraph), n_size
          )
  
      n = 17
      n_size = [3, 2]
      subgraphs = bfw.run(nodes=nodes, n=n, n_size=n_size)
      assert len(subgraphs) == n
      for subgraph in subgraphs:
          # "root" plus 3 * child + 3 * 2 * grandchild or None
          assert len(subgraph) == expected_bfw_size(n_size)
          assert (
              subgraph[0] == tree_graph.node_ids_to_ilocs(["root"])[0]
          )
  
file_path: stellargraph/tests/data/test_breadth_first_walker.py
imports: import pandas
  import pytest
  import numpy
  from stellargraph.data.explorer import SampledBreadthFirstWalk
  from stellargraph.core.graph import StellarGraph, StellarDiGraph
  from ..test_utils.graphs import create_test_graph, tree_graph, example_graph_random, weighted_tree
label_desc: Use image node_id 3 for calling the TestBreadthFirstWalk obj's underlying member method code with example usage: obj.test_directed_walk_generation_single_root_node(tree_graph) without return types