Python sortedcontainers.SortedListWithKey() Examples
The following are 30
code examples of sortedcontainers.SortedListWithKey().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sortedcontainers
, or try the search function
.
Example #1
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 6 votes |
def test_init(): slt = SortedListWithKey(key=modulo) slt._check() slt = SortedListWithKey(load=10000, key=modulo) assert slt._load == 10000 assert slt._twice == 20000 assert slt._half == 5000 slt._check() slt = SortedListWithKey(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, SortedListWithKey) slt._check()
Example #2
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_islice(): return slt = SortedListWithKey(load=7, key=negate) assert [] == list(slt.islice()) values = sorted(range(53), key=negate) slt.update(values) for start in range(53): for stop in range(53): assert list(slt.islice(start, stop)) == values[start:stop] for start in range(53): for stop in range(53): assert list(slt.islice(start, stop, reverse=True)) == values[start:stop][::-1] for start in range(53): assert list(slt.islice(start=start)) == values[start:] assert list(slt.islice(start=start, reverse=True)) == values[start:][::-1] for stop in range(53): assert list(slt.islice(stop=stop)) == values[:stop] assert list(slt.islice(stop=stop, reverse=True)) == values[:stop][::-1]
Example #3
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_getitem(): random.seed(0) slt = SortedListWithKey(load=17, key=negate) slt.append(5) assert slt[0] == 5 slt.clear() lst = list() for rpt in range(100): val = random.random() slt.add(val) lst.append(val) lst.sort(reverse=True) assert all(slt[idx] == lst[idx] for idx in range(100)) assert all(slt[idx - 99] == lst[idx - 99] for idx in range(100))
Example #4
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_setitem_slice(): slt = SortedListWithKey(range(100), load=17, key=negate) slt[:10] = iter(range(99, 89, -1)) assert slt == list(range(99, -1, -1)) slt[:10:2] = iter([99, 97, 95, 93, 91]) assert slt == list(range(99, -1, -1)) slt[-50:] = range(49, -51, -1) assert slt == list(range(99, -51, -1)) slt[-100:] = range(49, -1, -1) assert slt == list(range(99, -1, -1)) slt[:] = range(99, -1, -1) assert slt == list(range(99, -1, -1)) slt[90:] = [] assert slt == list(range(99, 9, -1)) slt[:10] = [] assert slt == list(range(89, 9, -1))
Example #5
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_index(): slt = SortedListWithKey(range(100), load=17, key=negate) for pos, val in enumerate(range(99, -1, -1)): assert val == slt.index(pos) assert slt.index(99, 0, 1000) == 0 slt = SortedListWithKey((0 for rpt in range(100)), load=17, key=negate) for start in range(100): for stop in range(start, 100): assert slt.index(0, start, stop + 1) == start for start in range(100): assert slt.index(0, -(100 - start)) == start assert slt.index(0, -1000) == 0
Example #6
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_init(): slt = SortedListWithKey(key=negate) slt._check() slt = SortedListWithKey(load=10000, key=negate) assert slt._load == 10000 assert slt._twice == 20000 assert slt._half == 5000 slt._check() slt = SortedListWithKey(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()
Example #7
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 6 votes |
def test_discard(): slt = SortedListWithKey(key=modulo) assert slt.discard(0) == None assert len(slt) == 0 slt._check() slt = SortedListWithKey([1, 2, 2, 2, 3, 3, 5], load=4, key=modulo) slt.discard(6) slt._check() slt.discard(4) slt._check() slt.discard(2) slt._check() slt.discard(11) slt.discard(12) slt.discard(13) slt.discard(15) assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
Example #8
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_add(): random.seed(0) slt = SortedListWithKey(key=negate) for val in range(1000): slt.add(val) slt._check() slt = SortedListWithKey(key=negate) for val in range(1000, 0, -1): slt.add(val) slt._check() slt = SortedListWithKey(key=negate) for val in range(1000): slt.add(random.random()) slt._check()
Example #9
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_update(): slt = SortedListWithKey(key=negate) 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((val for val in chain(range(100), range(1000), range(10000))), key=negate) assert all(tup[0] == tup[1] for tup in zip(slt, values))
Example #10
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 6 votes |
def test_discard(): slt = SortedListWithKey(key=negate) assert slt.discard(0) == None assert len(slt) == 0 slt._check() slt = SortedListWithKey([1, 2, 2, 2, 3, 3, 5], load=4, key=negate) 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, reversed([1, 2, 2, 3, 3, 5])))
Example #11
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 6 votes |
def test_contains(): slt = SortedListWithKey(key=modulo, load=7) assert 0 not in slt slt.update(range(100)) for val in range(100): assert val in slt assert 100 not in slt slt._check() slt = SortedListWithKey(range(100), key=modulo, load=4) assert all(val not in slt for val in range(100, 200))
Example #12
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror3(): slt = SortedListWithKey([0] * 10, load=4, key=negate) slt.index(0, 7, 3)
Example #13
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 5 votes |
def test_remove(): slt = SortedListWithKey(key=modulo) assert slt.discard(0) == None assert len(slt) == 0 slt._check() slt = SortedListWithKey([1, 2, 2, 2, 3, 3, 5], load=4, key=modulo) slt.remove(2) slt._check() assert all(tup[0] == tup[1] for tup in zip(slt, [1, 2, 2, 3, 3, 5]))
Example #14
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror5(): slt = SortedListWithKey(key=negate) slt.index(1)
Example #15
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror6(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.index(6, 5)
Example #16
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_mul(): this = SortedListWithKey(range(10), load=4, key=negate) that = this * 5 this._check() that._check() assert this == list(reversed((range(10)))) assert that == list(sorted(list(range(10)) * 5, reverse=True)) assert this != that
Example #17
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_imul(): this = SortedListWithKey(range(10), load=4, key=negate) this *= 5 this._check() assert this == sorted(list(range(10)) * 5, reverse=True)
Example #18
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 5 votes |
def test_update(): slt = SortedListWithKey(key=modulo) slt.update(range(1000)) assert all(tup[0] == tup[1] for tup in zip(slt, sorted(range(1000), key=modulo))) assert len(slt) == 1000 slt._check() slt.update(range(10000)) assert len(slt) == 11000 slt._check()
Example #19
Source File: test_coverage_sortedlistwithkey_modulo.py From pyFileFixity with MIT License | 5 votes |
def test_remove_valueerror1(): slt = SortedListWithKey(key=modulo) slt.remove(0)
Example #20
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_gt(): this = SortedListWithKey(range(10), load=4, key=negate) that = SortedListWithKey(range(10, 20), load=5, key=negate) assert that > this assert not (this > that) that = SortedListWithKey(range(1, 20), load=6, key=negate) assert that > this that = SortedListWithKey(range(1, 10), load=4, key=negate) assert not (that > this)
Example #21
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror2(): slt = SortedListWithKey([0] * 10, load=4, key=negate) slt.index(0, 0, -10)
Example #22
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_index_valueerror1(): slt = SortedListWithKey([0] * 10, load=4, key=negate) slt.index(0, 10)
Example #23
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_pop_indexerror2(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.pop(10)
Example #24
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_pop(): slt = SortedListWithKey(range(10), load=4, key=negate) slt._check() assert slt.pop() == 0 slt._check() assert slt.pop(0) == 9 slt._check() assert slt.pop(-2) == 2 slt._check() assert slt.pop(4) == 4 slt._check()
Example #25
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror4(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.insert(5, 7)
Example #26
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror3(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.insert(5, 3)
Example #27
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror2(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.insert(0, 0)
Example #28
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_insert_valueerror1(): slt = SortedListWithKey(range(10), load=4, key=negate) slt.insert(10, 5)
Example #29
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_extend_valueerror2(): slt = SortedListWithKey(range(20), load=4, key=negate) slt.extend([5, 4, 3, 2, 1])
Example #30
Source File: test_coverage_sortedlistwithkey_negate.py From pyFileFixity with MIT License | 5 votes |
def test_extend_valueerror1(): slt = SortedListWithKey(key=negate) slt.extend([1, 2, 3, 5, 4, 6])