code: def test_detector(
      signal,
      window_amp,
      window_local,
      n_est_points,
      return_instance_score,
  ):
      t, X, X_pert = signal["t"], signal["X"], signal["X_pert"]
  
      threshold = 6
      od = SpectralResidual(
          threshold=threshold,
          window_amp=window_amp,
          window_local=window_local,
          n_est_points=n_est_points,
      )
  
      assert od.threshold == threshold
      assert od.meta == {
          "name": "SpectralResidual",
          "detector_type": "outlier",
          "data_type": "time-series",
          "online": True,
          "version": __version__,
      }
      preds_in = od.predict(
          X, t, return_instance_score=return_instance_score
      )
      assert preds_in["data"]["is_outlier"].sum() <= 2.0
      if return_instance_score:
          assert (
              preds_in["data"]["is_outlier"].sum()
              == (preds_in["data"]["instance_score"] > od.threshold)
              .astype(int)
              .sum()
          )
      else:
          assert preds_in["data"]["instance_score"] is None
      preds_out = od.predict(
          X_pert, t, return_instance_score=return_instance_score
      )
      assert (
          preds_out["data"]["is_outlier"].sum() >= 10
      )  # check if we detect at least the number of perturbed points
      if return_instance_score:
          assert (
              preds_out["data"]["is_outlier"].sum()
              == (preds_out["data"]["instance_score"] > od.threshold)
              .astype(int)
              .sum()
          )
      else:
          assert preds_out["data"]["instance_score"] is None
      assert preds_out["meta"] == od.meta
  
imports: import pytest
  import numpy
  from alibi_detect.od import SpectralResidual
  from alibi_detect.version import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: test_detector(signal, window_amp, window_local, n_est_points, return_instance_score) without return types