def test_is_complete(self): h = None self.assertTrue(heap.is_complete(h)) for i in range(11): if i in [0, 1, 3, 7]: self.assertTrue(heap.is_complete(h)) else: self.assertFalse(heap.is_complete(h)) h = heap.push(h, i) self.assertFalse(heap.is_complete(h))
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))