code: def test_negative_sampler(caplog):
      user = 1
      n_samples = 3
      user_positive_item_pool = {1, 2}
      item_pool = {1, 2, 3, 4, 5}
      sample_with_replacement = False
      sampler = NegativeSampler(
          user,
          n_samples,
          user_positive_item_pool,
          item_pool,
          sample_with_replacement,
      )
      assert sampler.n_samples == 3
      samples = sampler.sample()
      assert set(samples) == item_pool.difference(
          user_positive_item_pool
      )
  
      # test sampler adjusts n_samples down if population is too small and that it raises a warning
      n_samples = 4
      sampler = NegativeSampler(
          user,
          n_samples,
          user_positive_item_pool,
          item_pool,
          sample_with_replacement,
      )
      assert sampler.n_samples == 3
      assert (
          "The population of negative items to sample from is too small for user 1"
          in caplog.text
      )
  
      # test sampling with replacement returns requested number of samples despite small population
      sampler = NegativeSampler(
          user,
          n_samples,
          user_positive_item_pool,
          item_pool,
          sample_with_replacement=True,
      )
      assert sampler.n_samples == 4
      assert len(sampler.sample()) == n_samples
  
file_path: recommenders/tests/unit/recommenders/models/test_ncf_dataset.py
imports: import os
  import pytest
  import pandas
  from recommenders.utils.constants import DEFAULT_USER_COL, DEFAULT_ITEM_COL, DEFAULT_RATING_COL, DEFAULT_TIMESTAMP_COL
  from recommenders.models.ncf.dataset import DataFile, NegativeSampler, Dataset, EmptyFileException, MissingFieldsException, FileNotSortedException, MissingUserException
label_desc: Use image node_id 5 for calling a global function with example usage: test_negative_sampler(caplog) without return types