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))
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
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
def test_smallest_empty(int_heap): with pytest.raises(NoMatchError): heap.smallest(int_heap, (lambda _: True))