code: def test_optimal_threshold_adversarial_case():
      # The worst case for the optimal_threshold function is when the values are concentrated
      # at one edge: [0, 0, ..., 1000]. (histogram)
      # We want to make sure that the optimal threshold in this case is the max.
      hist = []
      hist_edges = []
      min_val = -2
      max_val = 2
      for _ in range(0, 998):
          hist.append(0)
      for i in range(0, 999):
          hist_edges.append((max_val - min_val) / 999 * i + min_val)
      hist.append(1000)
      hist_edges.append(max_val)
      hist_data = (hist, hist_edges, min_val, max_val, max_val)
      for dtype in ["uint8", "int8", "auto"]:
          res = mx.contrib.quant._LayerHistogramCollector.get_optimal_threshold(
              hist_data, dtype, num_quantized_bins=5
          )
          # The threshold should be 2.
          print(res)
          assert abs(res[2] - 2) < 1e-5
  
imports: import os
  import mxnet
  import numpy
  from mxnet import npx
  from mxnet.util import use_np
  from mxnet.gluon.model_zoo import vision
  from mxnet.test_utils import assert_almost_equal, assert_exception, rand_ndarray, rand_shape_nd, same, DummyIter
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.io import NDArrayIter
  import unittest
  import operator
label_desc: Use image node_id 27 for calling a global function with example usage: test_optimal_threshold_adversarial_case() without return types