Exemplo n.º 1
0
def test_smallest_random(values):
    int_heap = IntHeap()
    for v in values:
        heap.push(int_heap, v)

    target = random.choice(int_heap.values)
    valid = [i for (i, v) in enumerate(int_heap.values) if v == target]
    assert heap.smallest(int_heap, (lambda x: x == target)) in valid
Exemplo n.º 2
0
def test_smallest_random(values):
    int_heap = IntHeap()
    for v in values:
        heap.push(int_heap, v)

    target = random.choice(int_heap.values)
    valid = [i for (i, v) in enumerate(int_heap.values) if v == target]
    assert heap.smallest(int_heap, (lambda x: x == target)) in valid
Exemplo n.º 3
0
def test_smallest_basic(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    assert heap.smallest(int_heap, (lambda _: True)) == 0

    with pytest.raises(NoMatchError):
        heap.smallest(int_heap, (lambda _: False))
Exemplo n.º 4
0
def test_smallest_basic(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    assert heap.smallest(int_heap, (lambda _: True)) == 0

    with pytest.raises(NoMatchError):
        heap.smallest(int_heap, (lambda _: False))
Exemplo n.º 5
0
def test_remove(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    # random remove item from the heap
    n = len(values)
    for i in six.moves.range(n - 1, -1, -1):
        heap.remove(int_heap, random.randint(0, i))
        verify(int_heap, 0)
Exemplo n.º 6
0
def test_pop(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    for i in sorted(values):
        assert i == heap.pop(int_heap)
        verify(int_heap, 0)

    assert int_heap.size() == 0
Exemplo n.º 7
0
def test_remove(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    # random remove item from the heap
    n = len(values)
    for i in six.moves.range(n - 1, -1, -1):
        heap.remove(int_heap, random.randint(0, i))
        verify(int_heap, 0)
Exemplo n.º 8
0
def test_pop(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    for i in sorted(values):
        assert i == heap.pop(int_heap)
        verify(int_heap, 0)

    assert int_heap.size() == 0
Exemplo n.º 9
0
def test_heap_fuzz(int_heap):
    for _ in six.moves.range(random.randint(1, 100000)):
        ops = random.randint(0, 1)
        if ops == 0:  # push
            heap.push(int_heap, random.randint(0, sys.maxsize))
        elif ops == 1:  # pop
            if int_heap.size():
                heap.pop(int_heap)

        if int_heap.size():
            assert smallest(int_heap.values) == int_heap.values[0]

        verify(int_heap, 0)
Exemplo n.º 10
0
def test_heap_fuzz(int_heap):
    for _ in six.moves.range(random.randint(1, 100000)):
        ops = random.randint(0, 1)
        if ops == 0:  # push
            heap.push(int_heap, random.randint(0, sys.maxint))
        elif ops == 1:  # pop
            if int_heap.size():
                heap.pop(int_heap)

        if int_heap.size():
            assert smallest(int_heap.values) == int_heap.values[0]

        verify(int_heap, 0)
Exemplo n.º 11
0
def test_push(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    assert int_heap.size() == len(values)
Exemplo n.º 12
0
def test_push(int_heap, values):
    for value in values:
        heap.push(int_heap, value)
        verify(int_heap, 0)

    assert int_heap.size() == len(values)