Ejemplo n.º 1
0
def test_setitem_extended_slice():
    dl = DiskList(range(0, 1000, 10))
    lst = list(range(0, 1000, 10))
    lst[10:90:10] = range(105, 905, 100)
    dl[10:90:10] = range(105, 905, 100)
    assert dl == lst
    dl.destroy()
Ejemplo n.º 2
0
def test_delitem_slice():
    dl = DiskList(range(100))
    del dl[10:40:1]
    del dl[10:40:-1]
    del dl[10:40:2]
    del dl[10:40:-2]
    dl.destroy()
Ejemplo n.º 3
0
def test_op_add():
    this = DiskList(range(10))
    assert (this + this + this) == (this * 3)
    that = DiskList(range(10))
    that += that
    that += that
    assert that == (this * 4)
    this.destroy()
    that.destroy()
Ejemplo n.º 4
0
def test_setitem():
    random.seed(0)
    dl = DiskList(range(0, 100, 10))
    print dl
    values = list(enumerate(range(5, 105, 10)))
    print values
    random.shuffle(values)
    for pos, val in values:
        dl[pos] = val
    dl[-2] = 85
    dl.destroy()
Ejemplo n.º 5
0
def test_getitem_slice_big():
    dl = DiskList(range(4))
    lst = list(range(4))

    itr = ((start, stop, step) for start in [-6, -4, -2, 0, 2, 4, 6]
           for stop in [-6, -4, -2, 0, 2, 4, 6]
           for step in [-3, -2, -1, 1, 2, 3])

    for start, stop, step in itr:
        assert dl[start:stop:step] == lst[start:stop:step]
    dl.destroy()
Ejemplo n.º 6
0
def test_count():
    dl = DiskList()
    assert dl.count(0) == 0
    for iii in range(100):
        for jjj in range(iii):
            dl.append(iii)
    for iii in range(100):
        assert dl.count(iii) == iii
    assert dl.count(100) == 0
    dl.destroy()
Ejemplo n.º 7
0
def test_getitem_slice():
    random.seed(0)
    dl = DiskList()

    lst = list()

    for rpt in range(100):
        val = random.random()
        dl.append(val)
        lst.append(val)

    lst.sort()
    dl.sort()

    assert all(dl[start:] == lst[start:] for start in [-75, -25, 0, 25, 75])

    assert all(dl[:stop] == lst[:stop] for stop in [-75, -25, 0, 25, 75])

    assert all(dl[::step] == lst[::step] for step in [-5, -1, 1, 5])

    assert all(dl[start:stop] == lst[start:stop]
               for start in [-75, -25, 0, 25, 75]
               for stop in [-75, -25, 0, 25, 75])

    assert all(dl[:stop:step] == lst[:stop:step]
               for stop in [-75, -25, 0, 25, 75] for step in [-5, -1, 1, 5])

    assert all(dl[start::step] == lst[start::step]
               for start in [-75, -25, 0, 25, 75] for step in [-5, -1, 1, 5])

    assert all(dl[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])
    dl.destroy()
Ejemplo n.º 8
0
def test_pop():
    dl = DiskList(range(10))
    assert dl.pop() == 9
    assert dl.pop(0) == 0
    assert dl.pop(-2) == 7
    assert dl.pop(4) == 5
    dl.destroy()
Ejemplo n.º 9
0
def test_remove():
    dl = DiskList([0])

    assert dl.remove(0) == None
    assert len(dl) == 0

    dl = DiskList([1, 2, 2, 2, 3, 3, 5])

    dl.remove(2)

    assert all(tup[0] == tup[1] for tup in zip(dl, [1, 2, 2, 3, 3, 5]))
    dl.destroy()
Ejemplo n.º 10
0
def test_le():
    this = DiskList(range(10, 15))
    assert this <= [10, 11, 12, 13, 14]
    assert this <= [10, 11, 12, 13, 14, 15]
    assert this <= [10, 11, 13, 13, 14]
    assert this <= [11]
    this.destroy()
Ejemplo n.º 11
0
def test_ge():
    this = DiskList(range(10, 15))
    assert this >= [10, 11, 12, 13, 14]
    assert this >= [10, 11, 12, 13]
    assert this >= [10, 11, 11, 13, 14]
    assert this >= [9]
    this.destroy()
Ejemplo n.º 12
0
def test_mul():
    this = DiskList(range(10))
    that = this * 5
    assert this == list(range(10))
    assert that == sorted(list(range(10)) * 5)
    assert this != that
    this.destroy()
Ejemplo n.º 13
0
def test_setitem_slice():
    dl = DiskList(range(100))
    dl[:10] = iter(range(10))
    assert dl == list(range(100))
    dl[:10:2] = iter(val * 2 for val in range(5))
    assert dl == list(range(100))
    dl[:50] = range(-50, 50)
    assert dl == list(range(-50, 100))
    dl[:100] = range(50)
    assert dl == list(range(100))
    dl[:] = range(100)
    assert dl == list(range(100))
    dl[90:] = []
    assert dl == list(range(90))
    dl[:10] = []
    assert dl == list(range(10, 90))
    dl.destroy()
Ejemplo n.º 14
0
def test_ne():
    this = DiskList(range(10))
    assert this != list(range(9))
    assert this != tuple(range(11))
    assert this != [0, 1, 2, 3, 3, 5, 6, 7, 8, 9]
    assert this != (val for val in range(10))
    assert this != set()
    this.destroy()
Ejemplo n.º 15
0
def test_delitem():
    random.seed(0)
    dl = DiskList(range(100))
    while len(dl) > 0:
        pos = random.randrange(len(dl))
        del dl[pos]
    dl.destroy()
    dl = DiskList(range(100))
    del dl[:]
    assert len(dl) == 0
    dl.destroy()
Ejemplo n.º 16
0
def test_copy():
    alpha = DiskList(range(100))
    beta = alpha.copy()
    alpha.append(100)
    assert len(alpha) == 101
    assert len(beta) == 100
    alpha.destroy()
    beta.destroy()
Ejemplo n.º 17
0
def test_copy_copy():
    import copy
    alpha = DiskList(range(100))
    beta = copy.copy(alpha)
    alpha.append(100)
    assert len(alpha) == 101
    print len(beta)
    assert len(beta) == 100
    alpha.destroy()
Ejemplo n.º 18
0
def test_contains():
    dl = DiskList()
    assert 0 not in dl

    dl.extend(range(10))

    for val in range(10):
        assert val in dl

    assert 10 not in dl
    dl.destroy()
Ejemplo n.º 19
0
def test_getitem():
    random.seed(0)
    dl = DiskList()
    lst = list()
    for _ in range(100):
        val = random.random()
        dl.add(val)
        lst.append(val)
    assert all(dl[idx] == lst[idx] for idx in range(100))
    assert all(dl[idx - 99] == lst[idx - 99] for idx in range(100))
    dl.destroy()
Ejemplo n.º 20
0
def test_remove_valueerror1():
    dl = DiskList()
    dl.remove(0)
    dl.destroy()
Ejemplo n.º 21
0
def test_remove_valueerror2():
    dl = DiskList(range(100))
    dl.remove(100)
    dl.destroy()
Ejemplo n.º 22
0
def test_index_valueerror4():
    dl = DiskList([0] * 10)
    dl.index(1)
    dl.destroy()
Ejemplo n.º 23
0
def test_index_nonexisting_value():
    dl = DiskList()
    dl.index(0)
    dl.destroy()
Ejemplo n.º 24
0
def test_repr():
    this = DiskList(range(10))
    assert repr(this) == 'DiskList([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])'
    this.destroy()
Ejemplo n.º 25
0
def test_pickle():
    import pickle
    alpha = DiskList(range(100))
    beta = pickle.loads(pickle.dumps(alpha))
    assert alpha == beta
    alpha.destroy()
Ejemplo n.º 26
0
def test_index_valueerror5():
    dl = DiskList()
    dl.index(1)
    dl.destroy()
Ejemplo n.º 27
0
def test_index_valueerror6():
    dl = DiskList(range(10))
    dl.index(3, 5)
    dl.destroy()
Ejemplo n.º 28
0
def test_index_valueerror7():
    dl = DiskList([0] * 10 + [2] * 10)
    dl.index(1, 0, 10)
    dl.destroy()
Ejemplo n.º 29
0
def test_eq():
    this = DiskList(range(10))
    assert this == list(range(10))
    assert not (this == list(range(9)))
    this.destroy()
Ejemplo n.º 30
0
def test_imul():
    this = DiskList(range(10))
    this *= 5
    assert this == sorted(list(range(10)) * 5)
    this.destroy()