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_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_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_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_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)
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
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)
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
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)
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)
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)
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)