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)
def test_push(self): count = self.SIZE head = count - 1 h = None for i in range(count): h = heap.push(h, i) self.assertTrue(heap.is_consistent(h)) self.assertEqual(node.count(h), count) self.assertEqual(node.value(h), head)
def test_complete_branch_aware_adding(self): h = None h = heap.push(h, 1) self.assertTrue(heap.is_complete(h)) self.assertTrue(heap.is_consistent(h)) h = heap.push(h, 2) self.assertFalse(heap.is_complete(h)) self.assertTrue(heap.is_complete(node.left(h))) self.assertIsNone(node.right(h)) self.assertTrue(heap.is_consistent(h)) h = heap.push(h, 3) self.assertTrue(heap.is_complete(h)) self.assertTrue(heap.is_consistent(h)) h = heap.push(h, 5) self.assertFalse(heap.is_complete(h)) self.assertFalse(heap.is_complete(node.left(h))) self.assertTrue(heap.is_complete(node.right(h))) self.assertTrue(heap.is_consistent(h))