code: def test_shortest_path():
      dist_matrix = generate_graph(20)
      # We compare path length and not costs (-> set distances to 0 or 1)
      dist_matrix[dist_matrix != 0] = 1
  
      for directed in (True, False):
          if not directed:
              dist_matrix = np.minimum(dist_matrix, dist_matrix.T)
  
          graph_py = floyd_warshall_slow(dist_matrix.copy(), directed)
          for i in range(dist_matrix.shape[0]):
              # Non-reachable nodes have distance 0 in graph_py
              dist_dict = defaultdict(int)
              dist_dict.update(
                  single_source_shortest_path_length(dist_matrix, i)
              )
  
              for j in range(graph_py[i].shape[0]):
                  assert_array_almost_equal(
                      dist_dict[j], graph_py[i, j]
                  )
  
imports: from collections import defaultdict
  import numpy
  from numpy.testing import assert_array_almost_equal
  from sklearn.utils.graph import single_source_shortest_path_length
label_desc: Use image node_id 3 for calling a global function with example usage: test_shortest_path() without return types