code: def test_trainset_testset(toy_data_reader):
      """Test the construct_trainset and construct_testset methods."""
  
      current_dir = os.path.dirname(os.path.realpath(__file__))
      folds_files = [
          (current_dir + "/custom_train", current_dir + "/custom_test")
      ]
  
      data = Dataset.load_from_folds(
          folds_files=folds_files, reader=toy_data_reader
      )
  
      pkf = PredefinedKFold()
      trainset, testset = next(pkf.split(data))
  
      # test ur
      ur = trainset.ur
      assert ur[0] == [(0, 4)]
      assert ur[1] == [(0, 4), (1, 2)]
      assert ur[40] == []  # not in the trainset
  
      # test ir
      ir = trainset.ir
      assert ir[0] == [(0, 4), (1, 4), (2, 1)]
      assert ir[1] == [(1, 2), (2, 1), (3, 5)]
      assert ir[20000] == []  # not in the trainset
  
      # test n_users, n_items, n_ratings, rating_scale
      assert trainset.n_users == 4
      assert trainset.n_items == 2
      assert trainset.n_ratings == 6
      assert trainset.rating_scale == (1, 5)
  
      # test raw2inner
      for i in range(4):
          assert trainset.to_inner_uid("user" + str(i)) == i
      with pytest.raises(ValueError):
          trainset.to_inner_uid("unknown_user")
  
      for i in range(2):
          assert trainset.to_inner_iid("item" + str(i)) == i
      with pytest.raises(ValueError):
          trainset.to_inner_iid("unknown_item")
  
      # test inner2raw
      assert trainset._inner2raw_id_users is None
      assert trainset._inner2raw_id_items is None
      for i in range(4):
          assert trainset.to_raw_uid(i) == "user" + str(i)
      for i in range(2):
          assert trainset.to_raw_iid(i) == "item" + str(i)
      assert trainset._inner2raw_id_users is not None
      assert trainset._inner2raw_id_items is not None
  
      # Test the build_testset() method
      algo = BaselineOnly()
      algo.fit(trainset)
      testset = trainset.build_testset()
      algo.test(testset)  # ensure an algorithm can manage the data
      assert ("user0", "item0", 4) in testset
      assert ("user3", "item1", 5) in testset
      assert ("user3", "item1", 0) not in testset
  
      # Test the build_anti_testset() method
      algo = BaselineOnly()
      algo.fit(trainset)
      testset = trainset.build_anti_testset()
      algo.test(testset)  # ensure an algorithm can manage the data
      assert ("user0", "item0", trainset.global_mean) not in testset
      assert ("user3", "item1", trainset.global_mean) not in testset
      assert ("user0", "item1", trainset.global_mean) in testset
      assert ("user3", "item0", trainset.global_mean) in testset
  
file_path: Surprise/tests/test_dataset.py
imports: import os
  import random
  import pandas
  import pytest
  from surprise import BaselineOnly, Dataset, Reader
  from surprise.builtin_datasets import get_dataset_dir
  from surprise.model_selection import KFold, PredefinedKFold
label_desc: Use image node_id 3 for calling a global function with example usage: test_trainset_testset(toy_data_reader) without return types