Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init():
slt = SortedKeyList(key=negate)
slt._check()
slt = SortedKeyList(key=negate)
slt._reset(10000)
assert slt._load == 10000
slt._check()
slt = SortedKeyList(range(10000), key=negate)
assert all(tup[0] == tup[1] for tup in zip(slt, reversed(range(10000))))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
slt._check()
def test_init():
slt = SortedKeyList(key=modulo)
assert slt.key == modulo
slt._check()
slt = SortedKeyList(key=modulo)
slt._reset(10000)
assert slt._load == 10000
slt._check()
slt = SortedKeyList(range(10000), key=modulo)
assert all(tup[0] == tup[1] for tup in zip(slt, sorted(range(10000), key=modulo)))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
assert isinstance(slt, SortedList)
assert isinstance(slt, SortedKeyList)
slt._check()
def test_delitem():
random.seed(0)
slt = SortedKeyList(range(100), key=negate)
slt._reset(17)
while len(slt) > 0:
del slt[random.randrange(len(slt))]
slt._check()
def test_index_valueerror4():
slt = SortedKeyList([0] * 10, key=negate)
slt._reset(4)
with pytest.raises(ValueError):
slt.index(1)
# Setups.
def do_nothing(obj, size):
pass
def fill_values(obj, size):
obj.update(sorted(lists[size]))
# Implementation imports.
from .context import sortedcontainers
from sortedcontainers import SortedList
kinds['SortedList'] = SortedList
from sortedcontainers import SortedKeyList
kinds['SortedKeyList'] = SortedKeyList
try:
from blist import sortedlist
kinds['B-Tree'] = sortedlist
except ImportError:
warnings.warn('No module named blist', ImportWarning)
try:
from .sortedcollection import SortedCollection
kinds['List'] = SortedCollection
except ImportError:
warnings.warn('No module named sortedcollection', ImportWarning)
# Implementation configuration.
for name in tests:
def test_index_valueerror1():
slt = SortedKeyList([0] * 10, key=modulo)
slt._reset(4)
with pytest.raises(ValueError):
slt.index(0, 10)
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=modulo)
slt._reset(17)
slt.add(5)
slt._build_index()
slt._check()
slt.clear()
lst = list(random.random() for rpt in range(100))
slt.update(lst)
lst.sort(key=modulo)
assert all(slt[idx] == lst[idx] for idx in range(100))
assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
def test_bisect_key():
slt = SortedKeyList(key=modulo)
assert slt.bisect_key(0) == 0
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
slt.update(range(100))
slt._check()
assert slt.bisect_key(0) == 20
assert slt.bisect_key(5) == 120
assert slt.bisect_key(10) == 200
def test_remove_valueerror5():
slt = SortedKeyList([1, 1, 1, 2, 2, 2], key=modulo)
with pytest.raises(ValueError):
slt.remove(12)
self._indices = defaultdict(lambda: SortedKeyList(key=_sort_func))