def test_add_multiple_elements(self): a = [randint(-100, 100) for _ in range(100)] h = MaxHeap() for i, elem in enumerate(a): self.assertIsNone(h.add(elem)) self.assertEqual(h.size, i + 1) self.assertFalse(h.is_empty()) self.assertEqual(h.find_max(), max(a))
def test_add_add_one(self): h = MaxHeap() self.assertIsNone(h.add(2)) self.assertEqual(h.size, 1) self.assertFalse(h.is_empty()) self.assertEqual(h.find_max(), 2)
def test_find_max_when_heap_has_random_size(self): a = [randint(-100, 100) for _ in range(3, 100)] h = MaxHeap(a) self.assertEqual(h.find_max(), max(a))
def test_find_max_when_heap_has_size_2(self): h = MaxHeap([13, 7]) self.assertEqual(h.find_max(), 13)
def test_find_max_when_heap_has_size_1(self): h = MaxHeap([5]) self.assertEqual(h.find_max(), 5)
def test_find_max_when_empty_heap(self): h = MaxHeap() self.assertIsNone(h.find_max())