Пример #1
0
 def test_add_add_one(self):
     h = MinMaxHeap()
     self.assertIsNone(h.add(2))
     self.assertEqual(h.size, 1)
     self.assertFalse(h.is_empty())
     self.assertEqual(h.find_max(), 2)
     self.assertEqual(h.find_min(), 2)
Пример #2
0
    def test_add_multiple_elements(self):
        a = [randint(-100, 100) for _ in range(100)]
        h = MinMaxHeap()

        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))
        self.assertEqual(h.find_min(), min(a))
Пример #3
0
 def test_find_min_when_heap_has_random_size(self):
     a = [randint(-100, 100) for _ in range(3, 100)]
     h = MinMaxHeap(a)
     self.assertEqual(h.find_min(), min(a))
Пример #4
0
 def test_find_min_when_heap_has_size_2(self):
     h = MinMaxHeap([13, 7])
     self.assertEqual(h.find_min(), 7)
Пример #5
0
 def test_find_min_when_heap_has_size_1(self):
     h = MinMaxHeap([5])
     self.assertEqual(h.find_min(), 5)
Пример #6
0
 def test_find_min_when_empty_heap(self):
     h = MinMaxHeap()
     self.assertIsNone(h.find_min())