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 = SortedList()
assert slt.key is None
slt._check()
slt = SortedList()
slt._reset(10000)
assert slt._load == 10000
slt._check()
slt = SortedList(range(10000))
assert all(tup[0] == tup[1] for tup in zip(slt, range(10000)))
slt.clear()
assert slt._len == 0
assert slt._maxes == []
assert slt._lists == []
slt._check()
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_popitem():
mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
temp = SortedDict(mapping)
assert temp.popitem() == ('z', 25)
def test_reversed_key():
temp = SortedDict(modulo, ((val, val) for val in range(100)))
temp._reset(7)
values = sorted(range(100), key=modulo)
assert all(lhs == rhs for lhs, rhs in zip(reversed(temp), reversed(values)))
def test_discard():
slt = SortedList()
assert slt.discard(0) == None
assert len(slt) == 0
slt._check()
slt = SortedList([1, 2, 2, 2, 3, 3, 5])
slt._reset(4)
slt.discard(6)
slt._check()
slt.discard(4)
slt._check()
slt.discard(2)
slt._check()
assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
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)