code: def test_fitted_knn_predict():
      """
      Test that a detector fitted on data and with threshold inferred correctly, will score
      and label outliers, as well as return the p-values using the predict method. Also Check
      that the score method gives the same results.
      """
  
      knn_detector = make_knn_detector(k=10)
      x_ref = np.random.randn(100, 2)
      knn_detector.infer_threshold(x_ref, 0.1)
      x = np.array([[0, 10], [0, 0.1]])
  
      y = knn_detector.predict(x)
      y = y["data"]
      scores = knn_detector.score(x)
      assert np.all(y["instance_score"] == scores)
      assert y["instance_score"][0] > 5
      assert y["instance_score"][1] < 1
      assert y["threshold_inferred"]
      assert y["threshold"] is not None
      assert isinstance(y["threshold"], float)
      assert y["p_value"].all()
      assert (y["is_outlier"] == [True, False]).all()
  
file_path: alibi-detect/alibi_detect/od/tests/test__knn/test__knn.py
imports: import pytest
  import numpy
  import torch
  from alibi_detect.od._knn import KNN
  from alibi_detect.od.pytorch.ensemble import AverageAggregator, TopKAggregator, MaxAggregator, MinAggregator, ShiftAndScaleNormalizer, PValNormalizer
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
  from sklearn.datasets import make_moons
label_desc: Use image node_id 6 for calling a global function with example usage: test_fitted_knn_predict() without return types