code: def test_top_k(
      k: int,
      preds: Tensor,
      target: Tensor,
      average: str,
      expected_spec: Tensor,
  ):
      """A simple test to check that top_k works as expected."""
      class_metric = MulticlassSpecificity(
          top_k=k, average=average, num_classes=3
      )
      class_metric.update(preds, target)
  
      assert torch.equal(class_metric.compute(), expected_spec)
      assert torch.equal(
          multiclass_specificity(
              preds, target, top_k=k, average=average, num_classes=3
          ),
          expected_spec,
      )
  
imports: from functools import partial
  import numpy
  import pytest
  import torch
  from scipy.special import expit
  from sklearn.metrics import confusion_matrix
  from torch import Tensor, tensor
  from torchmetrics.classification.specificity import BinarySpecificity, MulticlassSpecificity, MultilabelSpecificity, Specificity
  from torchmetrics.functional.classification.specificity import binary_specificity, multiclass_specificity, multilabel_specificity
  from torchmetrics.metric import Metric
  from unittests import NUM_CLASSES, THRESHOLD
  from unittests.classification.inputs import _binary_cases, _multiclass_cases, _multilabel_cases
  from unittests.helpers import seed_all
  from unittests.helpers.testers import MetricTester, inject_ignore_index
label_desc: Use image node_id 6 for calling a global function with example usage: test_top_k(k, preds, target, average, expected_spec) without return types