def test_remove_max_when_heap_has_random_size(self): size = randint(3, 100) a = [randint(-100, 100) for _ in range(size)] h = MaxHeap(a) m = max(a) self.assertEqual(h.remove_max(), m) self.assertFalse(h.is_empty()) self.assertEqual(h.size, size - 1)
def test_remove_max_when_heap_has_size_1(self): h = MaxHeap([13]) self.assertEqual(h.remove_max(), 13) self.assertTrue(h.is_empty()) self.assertEqual(h.size, 0)
def test_remove_max_when_heap_has_size_2(self): h = MaxHeap([11, 13]) self.assertEqual(h.remove_max(), 13) self.assertFalse(h.is_empty()) self.assertEqual(h.size, 1)
def test_remove_max_when_empty_heap(self): h = MaxHeap() self.assertIsNone(h.remove_max())