本文整理汇总了Python中sortedcontainers.SortedKeyList类的典型用法代码示例。如果您正苦于以下问题:Python SortedKeyList类的具体用法?Python SortedKeyList怎么用?Python SortedKeyList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SortedKeyList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_key
def test_key():
slt = SortedKeyList(range(10000), key=lambda val: val % 10)
slt._check()
values = sorted(range(10000), key=lambda val: (val % 10, val))
assert slt == values
assert all(val in slt for val in range(10000))
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedkeylist_modulo.py
示例2: test_delitem_slice
def test_delitem_slice():
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
del slt[10:40:1]
del slt[10:40:-1]
del slt[10:40:2]
del slt[10:40:-2]
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedkeylist_modulo.py
示例3: test_delitem
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()
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedkeylist_negate.py
示例4: test_copy_copy
def test_copy_copy():
import copy
slt = SortedKeyList(range(100), key=modulo)
slt._reset(7)
two = copy.copy(slt)
slt.add(100)
assert len(slt) == 101
assert len(two) == 100
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sortedkeylist_modulo.py
示例5: test_key2
def test_key2():
class Incomparable:
pass
a = Incomparable()
b = Incomparable()
slt = SortedKeyList(key=lambda val: 1)
slt.add(a)
slt.add(b)
assert slt == [a, b]
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:9,代码来源:test_coverage_sortedkeylist_modulo.py
示例6: test_pickle
def test_pickle():
import pickle
alpha = SortedKeyList(range(10000), key=negate)
alpha._reset(500)
beta = pickle.loads(pickle.dumps(alpha))
assert alpha == beta
assert alpha._key == beta._key
assert alpha._load == 500
assert beta._load == 1000
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:9,代码来源:test_coverage_sortedkeylist_negate.py
示例7: test_gte
def test_gte():
this = SortedKeyList(range(10), key=negate)
this._reset(4)
that = SortedKeyList(range(10), key=negate)
that._reset(5)
assert this >= that
assert that >= this
del this[-1]
assert that >= this
assert not (this >= that)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:10,代码来源:test_coverage_sortedkeylist_negate.py
示例8: test_op_add
def test_op_add():
this = SortedKeyList(range(10), key=modulo)
this._reset(4)
assert (this + this + this) == (this * 3)
that = SortedKeyList(range(10), key=modulo)
that._reset(4)
that += that
that += that
assert that == (this * 4)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:10,代码来源:test_coverage_sortedkeylist_modulo.py
示例9: test_contains
def test_contains():
slt = SortedKeyList(key=negate)
assert 0 not in slt
slt.update(range(10000))
for val in range(10000):
assert val in slt
assert 10000 not in slt
assert -1 not in slt
slt._check()
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:13,代码来源:test_coverage_sortedkeylist_negate.py
示例10: test_delete
def test_delete():
slt = SortedKeyList(range(20), key=modulo)
slt._reset(4)
slt._check()
for val in range(20):
slt.remove(val)
slt._check()
assert len(slt) == 0
assert slt._maxes == []
assert slt._lists == []
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:10,代码来源:test_coverage_sortedkeylist_modulo.py
示例11: test_delitem
def test_delitem():
random.seed(0)
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
while len(slt) > 0:
del slt[random.randrange(len(slt))]
slt._check()
slt = SortedKeyList(range(100), key=modulo)
slt._reset(17)
del slt[:]
assert len(slt) == 0
slt._check()
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:14,代码来源:test_coverage_sortedkeylist_modulo.py
示例12: test_update
def test_update():
slt = SortedKeyList(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()
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:11,代码来源:test_coverage_sortedkeylist_modulo.py
示例13: test_count
def test_count():
slt = SortedKeyList(key=negate)
slt._reset(7)
assert slt.count(0) == 0
for iii in range(100):
for jjj in range(iii):
slt.add(iii)
slt._check()
for iii in range(100):
assert slt.count(iii) == iii
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:13,代码来源:test_coverage_sortedkeylist_negate.py
示例14: test_gt
def test_gt():
this = SortedKeyList(range(10), key=negate)
this._reset(4)
that = SortedKeyList(range(10, 20), key=negate)
that._reset(5)
assert that > this
assert not (this > that)
that = SortedKeyList(range(1, 20), key=negate)
that._reset(6)
assert that > this
that = SortedKeyList(range(1, 10), key=negate)
that._reset(4)
assert not (that > this)
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:13,代码来源:test_coverage_sortedkeylist_negate.py
示例15: test_contains
def test_contains():
slt = SortedKeyList(key=modulo)
slt._reset(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 = SortedKeyList(range(100), key=modulo)
slt._reset(4)
assert all(val not in slt for val in range(100, 200))
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:18,代码来源:test_coverage_sortedkeylist_modulo.py
示例16: test_eq
def test_eq():
this = SortedKeyList(range(10), key=negate)
this._reset(4)
that = SortedKeyList(range(20), key=negate)
that._reset(4)
assert not (this == that)
that.clear()
that.update(range(10))
assert this == that
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:9,代码来源:test_coverage_sortedkeylist_negate.py
示例17: test_copy
def test_copy():
slt = SortedKeyList(range(100), key=negate)
slt._reset(7)
two = slt.copy()
slt.add(100)
assert len(slt) == 101
assert len(two) == 100
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sortedkeylist_negate.py
示例18: test_getitem_slice
def test_getitem_slice():
random.seed(0)
slt = SortedKeyList(key=modulo)
slt._reset(17)
lst = list()
for rpt in range(100):
val = random.random()
slt.add(val)
lst.append(val)
lst.sort(key=modulo)
assert all(slt[start:] == lst[start:]
for start in [-75, -25, 0, 25, 75])
assert all(slt[:stop] == lst[:stop]
for stop in [-75, -25, 0, 25, 75])
assert all(slt[::step] == lst[::step]
for step in [-5, -1, 1, 5])
assert all(slt[start:stop] == lst[start:stop]
for start in [-75, -25, 0, 25, 75]
for stop in [-75, -25, 0, 25, 75])
assert all(slt[:stop:step] == lst[:stop:step]
for stop in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
assert all(slt[start::step] == lst[start::step]
for start in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
assert all(slt[start:stop:step] == lst[start:stop:step]
for start in [-75, -25, 0, 25, 75]
for stop in [-75, -25, 0, 25, 75]
for step in [-5, -1, 1, 5])
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:39,代码来源:test_coverage_sortedkeylist_modulo.py
示例19: test_irange_key
def test_irange_key():
values = sorted(range(100), key=modulo)
for load in range(5, 16):
slt = SortedKeyList(range(100), key=modulo)
slt._reset(load)
for start in range(10):
for end in range(start, 10):
temp = list(slt.irange_key(start, end))
assert temp == values[(start * 10):((end + 1) * 10)]
temp = list(slt.irange_key(start, end, reverse=True))
assert temp == values[(start * 10):((end + 1) * 10)][::-1]
for start in range(10):
for end in range(start, 10):
temp = list(slt.irange_key(start, end, inclusive=(True, False)))
assert temp == values[(start * 10):(end * 10)]
for start in range(10):
for end in range(start, 10):
temp = list(slt.irange_key(start, end, (False, True)))
assert temp == values[((start + 1) * 10):((end + 1) * 10)]
for start in range(10):
for end in range(start, 10):
temp = list(slt.irange_key(start, end, inclusive=(False, False)))
assert temp == values[((start + 1) * 10):(end * 10)]
for start in range(10):
temp = list(slt.irange_key(min_key=start))
assert temp == values[(start * 10):]
for end in range(10):
temp = list(slt.irange_key(max_key=end))
assert temp == values[:(end + 1) * 10]
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:37,代码来源:test_coverage_sortedkeylist_modulo.py
示例20: test_getitem
def test_getitem():
random.seed(0)
slt = SortedKeyList(key=negate)
slt._reset(17)
slt.add(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))
开发者ID:grantjenks,项目名称:sorted_containers,代码行数:20,代码来源:test_coverage_sortedkeylist_negate.py
注:本文中的sortedcontainers.SortedKeyList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论