code: def test_example_case_in_tree_digraph():
      rng = np.random.RandomState(0)
      x1 = rng.rand(100)
      cat = rng.randint(1, 3, size=x1.size)
      X = np.vstack([x1, cat]).T
      y = x1 + 2 * cat
      feature_name = ["x1", "cat"]
      ds = lgb.Dataset(
          X, y, feature_name=feature_name, categorical_feature=["cat"]
      )
  
      num_round = 3
      bst = lgb.train({"num_leaves": 7}, ds, num_boost_round=num_round)
      mod = bst.dump_model()
      example_case = X[[0]]
      makes_categorical_splits = False
      seen_indices = set()
      for i in range(num_round):
          graph = lgb.create_tree_digraph(
              bst, example_case=example_case, tree_index=i
          )
          gbody = graph.body
          node = mod["tree_info"][i]["tree_structure"]
          while "decision_type" in node:  # iterate through the splits
              split_index = node["split_index"]
  
              node_in_graph = [
                  n
                  for n in gbody
                  if f"split{split_index}" in n and "->" not in n
              ]
              assert len(node_in_graph) == 1
              seen_indices.add(gbody.index(node_in_graph[0]))
  
              edge_to_node = [
                  e for e in gbody if f"-> split{split_index}" in e
              ]
              if node["decision_type"] == "<=":
                  direction = lgb.plotting._determine_direction_for_numeric_split(
                      example_case[0][node["split_feature"]],
                      node["threshold"],
                      node["missing_type"],
                      node["default_left"],
                  )
              else:
                  makes_categorical_splits = True
                  direction = lgb.plotting._determine_direction_for_categorical_split(
                      example_case[0][node["split_feature"]],
                      node["threshold"],
                  )
              node = (
                  node["left_child"]
                  if direction == "left"
                  else node["right_child"]
              )
              assert "color=blue" in node_in_graph[0]
              if edge_to_node:
                  assert len(edge_to_node) == 1
                  assert "color=blue" in edge_to_node[0]
                  seen_indices.add(gbody.index(edge_to_node[0]))
          # we're in a leaf now
          leaf_index = node["leaf_index"]
          leaf_in_graph = [
              n
              for n in gbody
              if f"leaf{leaf_index}" in n and "->" not in n
          ]
          edge_to_leaf = [
              e for e in gbody if f"-> leaf{leaf_index}" in e
          ]
          assert len(leaf_in_graph) == 1
          assert "color=blue" in leaf_in_graph[0]
          assert len(edge_to_leaf) == 1
          assert "color=blue" in edge_to_leaf[0]
          seen_indices.update(
              [
                  gbody.index(leaf_in_graph[0]),
                  gbody.index(edge_to_leaf[0]),
              ]
          )
  
          # check that the rest of the elements have black color
          remaining_elements = [
              e
              for i, e in enumerate(graph.body)
              if i not in seen_indices and "graph" not in e
          ]
          assert all("color=black" in e for e in remaining_elements)
  
          # check that we got to the expected leaf
          expected_leaf = bst.predict(
              example_case,
              start_iteration=i,
              num_iteration=1,
              pred_leaf=True,
          )[0]
          assert leaf_index == expected_leaf
      assert makes_categorical_splits
  
imports: import numpy
  import pandas
  import pytest
  from sklearn.model_selection import train_test_split
  import lightgbm
  from lightgbm.compat import GRAPHVIZ_INSTALLED, MATPLOTLIB_INSTALLED, PANDAS_INSTALLED, pd_DataFrame
  from .utils import load_breast_cancer, make_synthetic_regression
label_desc: Use image node_id 12 for calling a global function with example usage: test_example_case_in_tree_digraph() without return types