code: def test(self) -> None:
      # Define 4 training points from 4 classes.
      train_features = torch.tensor(
          [
              [0.0, -1.0],
              [0.0, 1.0],
              [1.0, 0.0],
              [1.0, 1.0],
          ]
      )
      train_targets = torch.tensor([0, 1, 2, 3])
      train_dataset = _FeaturesDataset(
          features=train_features, targets=train_targets
      )
  
      # Define 3 validation points.
      # Their expected predicted labels are their closest training points in order.
      val_features = torch.tensor(
          [
              [0.0, -0.4],  # predicted_labels = [0, 1, 2, 3]
              [0.6, 0.7],  # predicted_labels = [3, 1, 2, 0]
              [0.6, 0.3],  # predicted_labels = [2, 3, 1, 0]
          ]
      )
      val_targets = torch.tensor([0, 0, 1])
      val_dataset = _FeaturesDataset(
          features=val_features, targets=val_targets
      )
  
      train_dataloader = DataLoader(train_dataset, batch_size=2)
      val_dataloader = DataLoader(val_dataset, batch_size=2)
  
      # Run KNN classifier.
      model = nn.Identity()
      classifier = KNNClassifier(
          model, num_classes=4, knn_k=3, topk=(1, 2, 3, 4)
      )
      trainer = Trainer(max_epochs=1, accelerator="cpu", devices=1)
      trainer.fit(
          model=classifier,
          train_dataloaders=train_dataloader,
          val_dataloaders=val_dataloader,
      )
      assert trainer.callback_metrics[
          "val_top1"
      ].item() == pytest.approx(1 / 3)
      assert trainer.callback_metrics[
          "val_top2"
      ].item() == pytest.approx(1 / 3)
      assert trainer.callback_metrics[
          "val_top3"
      ].item() == pytest.approx(2 / 3)
      assert trainer.callback_metrics[
          "val_top4"
      ].item() == pytest.approx(3 / 3)
  
imports: from typing import Tuple
  import pytest
  import torch
  from pytest_mock import MockerFixture
  from pytorch_lightning import Trainer
  from torch import Tensor, nn
  from torch.utils.data import DataLoader, Dataset
  from lightly.utils.benchmarking import KNNClassifier
  from lightly.utils.benchmarking.knn_classifier import F
label_desc: Use image node_id 1 for calling the TestKNNClassifier obj's underlying member method code with example usage: obj.test() without return types