code: def test_sample_frac():
      ratings = lktu.ml_test.ratings
      users = np.random.choice(ratings.user.unique(), 5, replace=False)
  
      samp = xf.SampleFrac(0.2)
      for u in users:
          udf = ratings[ratings.user == u]
          tst = samp(udf)
          trn = udf.loc[udf.index.difference(tst.index), :]
          assert len(tst) + len(trn) == len(udf)
          assert len(tst) >= math.floor(len(udf) * 0.2)
          assert len(tst) <= math.ceil(len(udf) * 0.2)
  
      samp = xf.SampleFrac(0.5)
      for u in users:
          udf = ratings[ratings.user == u]
          tst = samp(udf)
          trn = udf.loc[udf.index.difference(tst.index), :]
          assert len(tst) + len(trn) == len(udf)
          assert len(tst) >= math.floor(len(udf) * 0.5)
          assert len(tst) <= math.ceil(len(udf) * 0.5)
  
imports: import itertools
  import functools
  import pytest
  import math
  import numpy
  import lenskit.util.test
  import lenskit.crossfold
label_desc: Use image node_id 7 for calling a global function with example usage: test_sample_frac() without return types