def test_islice(): sl = SortedList() sl._reset(7) assert [] == list(sl.islice()) values = list(range(53)) sl.update(values) for start in range(53): for stop in range(53): assert list(sl.islice(start, stop)) == values[start:stop] for start in range(53): for stop in range(53): assert list(sl.islice(start, stop, reverse=True)) == values[start:stop][::-1] for start in range(53): assert list(sl.islice(start=start)) == values[start:] assert list(sl.islice(start=start, reverse=True)) == values[start:][::-1] for stop in range(53): assert list(sl.islice(stop=stop)) == values[:stop] assert list(sl.islice(stop=stop, reverse=True)) == values[:stop][::-1]
def test_bisect_right(): slt = SortedList() assert slt.bisect_right(10) == 0 slt = SortedList(range(100)) slt._reset(17) slt.update(range(100)) slt._check() assert slt.bisect_right(10) == 22 assert slt.bisect_right(200) == 200
def test_bisect_left(): slt = SortedList() assert slt.bisect_left(0) == 0 slt = SortedList(range(100)) slt._reset(17) slt.update(range(100)) slt._check() assert slt.bisect_left(50) == 100 assert slt.bisect_left(200) == 200
def test_contains(): slt = SortedList() assert 0 not in slt slt.update(range(10000)) for val in range(10000): assert val in slt assert 10000 not in slt slt._check()
def test_irange(): sl = SortedList() sl._reset(7) assert [] == list(sl.irange()) values = list(range(53)) sl.update(values) for start in range(53): for end in range(start, 53): assert list(sl.irange(start, end)) == values[start:(end + 1)] assert list(sl.irange( start, end, reverse=True)) == values[start:(end + 1)][::-1] for start in range(53): for end in range(start, 53): assert list(range(start, end)) == list( sl.irange(start, end, (True, False))) for start in range(53): for end in range(start, 53): assert list(range(start + 1, end + 1)) == list( sl.irange(start, end, (False, True))) for start in range(53): for end in range(start, 53): assert list(range(start + 1, end)) == list( sl.irange(start, end, (False, False))) for start in range(53): assert list(range(start, 53)) == list(sl.irange(start)) for end in range(53): assert list(range(0, end)) == list(sl.irange(None, end, (True, False))) assert values == list(sl.irange(inclusive=(False, False))) assert [] == list(sl.irange(53)) assert values == list(sl.irange(None, 53, (True, False)))
def test_irange(): sl = SortedList() sl._reset(7) assert [] == list(sl.irange()) values = list(range(53)) sl.update(values) for start in range(53): for end in range(start, 53): assert list(sl.irange(start, end)) == values[start:(end + 1)] assert list(sl.irange(start, end, reverse=True)) == values[start:(end + 1)][::-1] for start in range(53): for end in range(start, 53): assert list(range(start, end)) == list(sl.irange(start, end, (True, False))) for start in range(53): for end in range(start, 53): assert list(range(start + 1, end + 1)) == list(sl.irange(start, end, (False, True))) for start in range(53): for end in range(start, 53): assert list(range(start + 1, end)) == list(sl.irange(start, end, (False, False))) for start in range(53): assert list(range(start, 53)) == list(sl.irange(start)) for end in range(53): assert list(range(0, end)) == list(sl.irange(None, end, (True, False))) assert values == list(sl.irange(inclusive=(False, False))) assert [] == list(sl.irange(53)) assert values == list(sl.irange(None, 53, (True, False)))
def test_update(): slt = SortedList() slt.update(range(1000)) assert len(slt) == 1000 slt._check() slt.update(range(100)) assert len(slt) == 1100 slt._check() slt.update(range(10000)) assert len(slt) == 11100 slt._check() values = sorted(chain(range(1000), range(100), range(10000))) assert all(tup[0] == tup[1] for tup in zip(slt, values))