code: def test_cluster_distances_with_distance_threshold(
      global_random_seed,
  ):
      rng = np.random.RandomState(global_random_seed)
      n_samples = 100
      X = rng.randint(-10, 10, size=(n_samples, 3))
      # check the distances within the clusters and with other clusters
      distance_threshold = 4
      clustering = AgglomerativeClustering(
          n_clusters=None,
          distance_threshold=distance_threshold,
          linkage="single",
      ).fit(X)
      labels = clustering.labels_
      D = pairwise_distances(X, metric="minkowski", p=2)
      # to avoid taking the 0 diagonal in min()
      np.fill_diagonal(D, np.inf)
      for label in np.unique(labels):
          in_cluster_mask = labels == label
          max_in_cluster_distance = (
              D[in_cluster_mask][:, in_cluster_mask].min(axis=0).max()
          )
          min_out_cluster_distance = (
              D[in_cluster_mask][:, ~in_cluster_mask].min(axis=0).min()
          )
          # single data point clusters only have that inf diagonal here
          if in_cluster_mask.sum() > 1:
              assert max_in_cluster_distance < distance_threshold
          assert min_out_cluster_distance >= distance_threshold
  
imports: import itertools
  import shutil
  from functools import partial
  from tempfile import mkdtemp
  import numpy
  import pytest
  from scipy.cluster import hierarchy
  from scipy.sparse.csgraph import connected_components
  from sklearn.cluster import AgglomerativeClustering, FeatureAgglomeration, ward_tree
  from sklearn.cluster._agglomerative import _TREE_BUILDERS, _fix_connectivity, _hc_cut, linkage_tree
  from sklearn.cluster._hierarchical_fast import average_merge, max_merge, mst_linkage_core
  from sklearn.datasets import make_circles, make_moons
  from sklearn.feature_extraction.image import grid_to_graph
  from sklearn.metrics import DistanceMetric
  from sklearn.metrics.cluster import adjusted_rand_score, normalized_mutual_info_score
  from sklearn.metrics.pairwise import PAIRED_DISTANCES, cosine_distances, manhattan_distances, pairwise_distances
  from sklearn.metrics.tests.test_dist_metrics import METRICS_DEFAULT_PARAMS
  from sklearn.neighbors import kneighbors_graph
  from sklearn.utils._fast_dict import IntFloatDict
  from sklearn.utils._testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal, create_memmap_backed_data, ignore_warnings
  from sklearn.utils.fixes import LIL_CONTAINERS
label_desc: Use image node_id 28 for calling a global function with example usage: test_cluster_distances_with_distance_threshold(global_random_seed) without return types