Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
def test_smallest_unordered_children(int_heap):
    int_heap.values = [1, 4, 2]
    verify(int_heap, 0)

    assert heap.smallest(int_heap, (lambda x: x % 2 == 0)) == 2
Exemplo n.º 6
0
def test_smallest_empty(int_heap):
    with pytest.raises(NoMatchError):
        heap.smallest(int_heap, (lambda _: True))
Exemplo n.º 7
0
def test_smallest_unordered_children(int_heap):
    int_heap.values = [1, 4, 2]
    verify(int_heap, 0)

    assert heap.smallest(int_heap, (lambda x: x % 2 == 0)) == 2
Exemplo n.º 8
0
def test_smallest_empty(int_heap):
    with pytest.raises(NoMatchError):
        heap.smallest(int_heap, (lambda _: True))