code: def test_kvp_add_several(kvp_len, data):
      "Test filling up a KVP."
      ks = np.full(kvp_len, -1, dtype=np.int32)
      vs = np.zeros(kvp_len)
  
      n = 0
  
      values = np.random.randn(kvp_len) * 100
  
      for k, v in enumerate(values):
          n = kvp_minheap_insert(0, n, kvp_len, k, v, ks, vs)
  
      assert n == kvp_len
      # all key slots are used
      assert all(ks >= 0)
      # all keys are there
      assert all(np.sort(ks) == list(range(kvp_len)))
      # value is the smallest
      assert vs[0] == np.min(vs)
  
      # it rejects a smaller value; -10000 is below our min value
      special_k = 500
      n2 = kvp_minheap_insert(
          0, n, kvp_len, special_k, -10000.0, ks, vs
      )
  
      assert n2 == n
      assert all(ks != special_k)
      assert all(vs > -5000.0)
  
      # it inserts a larger value somewhere
      old_mk = ks[0]
      old_mv = vs[0]
      assume(np.median(vs) < 50)
      nv = data.draw(st.floats(np.median(vs), 100))
      n2 = kvp_minheap_insert(0, n, kvp_len, special_k, nv, ks, vs)
  
      assert n2 == n
      # the old value minimum key has been removed
      assert all(ks != old_mk)
      # the old minimum value has been removed
      assert all(vs > old_mv)
      assert np.count_nonzero(ks == special_k) == 1
  
file_path: lkpy/tests/test_util_accum.py
imports: import numpy
  from lenskit.util.accum import kvp_minheap_insert, kvp_minheap_sort
  from hypothesis import given, assume, settings
  import hypothesis.strategies
  import hypothesis.extra.numpy
label_desc: Use image node_id 4 for calling a global function with example usage: test_kvp_add_several(kvp_len, data) without return types