Exemplo n.º 1
0
    def test_sort(self):
        sample_list = [random.randint(1, 100000) for i in range(self.SIZE)]
        h = None
        for i in sample_list:
            h = heap.push(h, i)

        sorted_list = sorted(sample_list, reverse=True)
        for i in sorted_list:
            h, val = heap.pop(h)
            self.assertEqual(val, i)
        self.assertIsNone(h)
Exemplo n.º 2
0
    def test_pop(self):
        h = None
        for i in range(self.SIZE):
            h = heap.push(h, i)
            self.assertTrue(heap.is_consistent(h))

        for i in reversed(range(self.SIZE)):
            h, val = heap.pop(h)
            self.assertEqual(val, i)
            self.assertTrue(heap.is_consistent(h))

        self.assertIsNone(h)