当前位置: 首页>>代码示例>>Python>>正文


Python sortedcontainers.SortedKeyList类代码示例

本文整理汇总了Python中sortedcontainers.SortedKeyList的典型用法代码示例。如果您正苦于以下问题:Python SortedKeyList类的具体用法?Python SortedKeyList怎么用?Python SortedKeyList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SortedKeyList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的sortedcontainers.SortedKeyList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。