code: def test_prepare_anomaly_ranges():
      """Tests for prepare_anomaly_ranges function"""
  
      y_true = [
          0,
          0,
          0,
          1,
          1,
          1,
          1,
          1,
          0,
          0,
          0,
          1,
          1,
          1,
          1,
          1,
          1,
          1,
          1,
          0,
      ]
      y_pred = [
          0,
          0,
          1,
          1,
          1,
          1,
          0,
          0,
          0,
          0,
          0,
          1,
          1,
          0,
          0,
          1,
          1,
          1,
          0,
          0,
      ]
  
      real_anomaly_ranges = prepare_anomaly_ranges(np.array(y_true))
      expected_real_anomaly_ranges = np.array([[3, 7], [11, 18]])
      predicted_anomaly_ranges = prepare_anomaly_ranges(
          np.array(y_pred)
      )
      expected_predicted_anomaly_ranges = np.array(
          [[2, 5], [11, 12], [15, 17]]
      )
  
      assert np.array_equal(
          real_anomaly_ranges, expected_real_anomaly_ranges
      )
      assert np.array_equal(
          predicted_anomaly_ranges, expected_predicted_anomaly_ranges
      )
  
      real_anomaly_ranges = prepare_anomaly_ranges(
          np.array(y_true), range_based=False
      )
      expected_real_anomaly_ranges = [
          [3, 3],
          [4, 4],
          [5, 5],
          [6, 6],
          [7, 7],
          [11, 11],
          [12, 12],
          [13, 13],
          [14, 14],
          [15, 15],
          [16, 16],
          [17, 17],
          [18, 18],
      ]
      predicted_anomaly_ranges = prepare_anomaly_ranges(
          np.array(y_pred), range_based=False
      )
      expected_predicted_anomaly_ranges = [
          [2, 2],
          [3, 3],
          [4, 4],
          [5, 5],
          [11, 11],
          [12, 12],
          [15, 15],
          [16, 16],
          [17, 17],
      ]
  
      assert all(
          anomaly_range in real_anomaly_ranges
          for anomaly_range in expected_real_anomaly_ranges
      )
      assert all(
          anomaly_range in predicted_anomaly_ranges
          for anomaly_range in expected_predicted_anomaly_ranges
      )
  
file_path: greykite/greykite/tests/detection/common/test_ad_evaluation_utils.py
imports: import numpy
  from greykite.detection.common.ad_evaluation_utils import compute_range_based_score
  from greykite.detection.common.ad_evaluation_utils import get_cardinality_factor
  from greykite.detection.common.ad_evaluation_utils import get_overlap_size_and_position_reward
  from greykite.detection.common.ad_evaluation_utils import get_positional_reward
  from greykite.detection.common.ad_evaluation_utils import prepare_anomaly_ranges
label_desc: Use image node_id 1 for calling a global function with example usage: test_prepare_anomaly_ranges() without return types