Beispiel #1
0
 def test_contains_false(self):
     h = MaxHeap([6, 8, 2, 60, 7, 9, 3, 67])
     self.assertFalse(h.contains(10))
Beispiel #2
0
 def test_delete_when_argument_is_None(self):
     self.assertRaises(ValueError, MaxHeap().delete, None)
Beispiel #3
0
 def test_contains_when_empty_heap(self):
     h = MaxHeap()
     self.assertFalse(h.contains(3))
Beispiel #4
0
 def test_contains_true(self):
     h = MaxHeap([6, 8, 2, 2, 60, 7, 9])
     self.assertTrue(h.contains(2))
Beispiel #5
0
 def test_find_max_when_heap_has_size_2(self):
     h = MaxHeap([13, 7])
     self.assertEqual(h.find_max(), 13)
Beispiel #6
0
 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)
Beispiel #7
0
 def test_clear_heap_of_random_size(self):
     h = MaxHeap([randint(-100, 100) for _ in range(100)])
     self.assertIsNone(h.clear())
     self.assertEqual(h.size, 0)
     self.assertTrue(h.is_empty())
Beispiel #8
0
 def test_find_max_when_empty_heap(self):
     h = MaxHeap()
     self.assertIsNone(h.find_max())
Beispiel #9
0
 def test_heap_creation_given_list(self):
     a = [12, 14, 28, 6, 7, 10, 18]
     h = MaxHeap(a)
     self.assertFalse(h.is_empty())
     self.assertEqual(h.size, len(a))
Beispiel #10
0
 def test_clear_empty_heap(self):
     h = MaxHeap()
     self.assertIsNone(h.clear())
     self.assertEqual(h.size, 0)
     self.assertTrue(h.is_empty())
Beispiel #11
0
 def test_heap_creation_default(self):
     h = MaxHeap()
     self.assertTrue(h.is_empty())
     self.assertEqual(h.size, 0)
Beispiel #12
0
 def test_merge_empty_heap_with_empty_heap(self):
     a = MaxHeap()
     b = MaxHeap()
     self.assertIsNone(a.merge(b))
Beispiel #13
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)
Beispiel #14
0
 def test_delete_when_elem_does_not_exist(self):
     self.assertRaises(LookupError, MaxHeap().delete, 3)
Beispiel #15
0
 def test_add_when_argument_is_None(self):
     h = MaxHeap()
     self.assertRaises(ValueError, h.add, None)
Beispiel #16
0
 def test_delete_when_elem_is_last(self):
     h = MaxHeap([3, 4])
     self.assertIsNone(h.delete(4))
     self.assertTrue(is_max_heap(h))
     self.assertEqual(h.size, 1)
     self.assertFalse(h.is_empty())
Beispiel #17
0
 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)
Beispiel #18
0
 def test_find_max_when_heap_has_size_1(self):
     h = MaxHeap([5])
     self.assertEqual(h.find_max(), 5)
Beispiel #19
0
 def test_contains_when_argument_is_None(self):
     h = MaxHeap()
     self.assertRaises(ValueError, h.contains, None)
Beispiel #20
0
 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))
Beispiel #21
0
 def test_remove_max_when_empty_heap(self):
     h = MaxHeap()
     self.assertIsNone(h.remove_max())