code: def test_ranking(self):
      # Test `_validate`
      X_val = rand(16, 2)
      X_idx = stack([randperm(len(X_val))[:3] for _ in range(1)])
      X = SliceContainer(
          X_val, X_idx, event_shape=Size([3 * X_val.shape[-1]])
      )
      feature_names = ["x1", "x2"]
      outcome_names = ["ranking indices"]
  
      with self.assertRaisesRegex(
          ValueError, "The `values` field of `X`"
      ):
          RankingDataset(
              X=X,
              Y=tensor([[-1, 0, 1]]),
              feature_names=feature_names[:1],
              outcome_names=outcome_names,
          )
  
      with self.assertRaisesRegex(ValueError, "out-of-bounds"):
          RankingDataset(
              X=X,
              Y=tensor([[-1, 0, 1]]),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      RankingDataset(
          X=X,
          Y=tensor([[2, 0, 1]]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
  
      with self.assertRaisesRegex(ValueError, "out-of-bounds"):
          RankingDataset(
              X=X,
              Y=tensor([[0, 1, 3]]),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      RankingDataset(
          X=X,
          Y=tensor([[0, 1, 2]]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
  
      with self.assertRaisesRegex(ValueError, "missing zero-th rank."):
          RankingDataset(
              X=X,
              Y=tensor([[1, 2, 2]]),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      RankingDataset(
          X=X,
          Y=tensor([[0, 1, 1]]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
  
      with self.assertRaisesRegex(
          ValueError, "ranks not skipped after ties."
      ):
          RankingDataset(
              X=X,
              Y=tensor([[0, 0, 1]]),
              feature_names=feature_names,
              outcome_names=outcome_names,
          )
      RankingDataset(
          X=X,
          Y=tensor([[0, 0, 2]]),
          feature_names=feature_names,
          outcome_names=outcome_names,
      )
  
file_path: botorch/test/utils/test_datasets.py
imports: from typing import List, Optional
  import torch
  from botorch.exceptions.errors import InputDataError, UnsupportedError
  from botorch.utils.containers import DenseContainer, SliceContainer
  from botorch.utils.datasets import ContextualDataset, FixedNoiseDataset, MultiTaskDataset, RankingDataset, SupervisedDataset
  from botorch.utils.testing import BotorchTestCase
  from torch import rand, randperm, Size, stack, Tensor, tensor
label_desc: Use image node_id 3 for calling the TestDatasets obj's underlying member method code with example usage: obj.test_ranking() without return types