class MaxHeap_TestCase_1_Pop_With_Predictable_SmallSet_Of_Elements( unittest.TestCase): """ Create only. No heap modification. Small predictable set of elements. """ def setUp(self): self._heap = Heap(min_heap=False) self._heap.add_items([3, 1, 2]) def test_heap_status(self): self.assertFalse(self._heap.is_min_heap, 'heap must be a max heap.') self.assertTrue( assert_max_heap_property(self._heap._get_heap_as_list()), 'heap property must be satisfied.') self.assertTrue([None, 3, 1, 2] == self._heap._get_heap_as_list(), 'heap contents are not same as expected.') #Pop self._heap.get() # self.assertTrue( assert_max_heap_property(self._heap._get_heap_as_list()), 'heap property must be satisfied.') self.assertTrue([None, 2, 1] == self._heap._get_heap_as_list(), 'heap contents are not same as expected.') def tearDown(self): unittest.TestCase.tearDown(self)
class MaxHeap_TestCase_Iterator_Element(unittest.TestCase): """ Create only. No heap modification. No Elements. """ def setUp(self): self._heap = Heap(min_heap=False) self._sortedListofElements = [40, 20, 10, 9, 4] self._heap.add_items([10, 9, 4, 20, 40]) def test_heap_iterator(self): self.assertFalse(self._heap.is_min_heap, 'heap must be a max heap.') self.assertTrue( assert_max_heap_property(self._heap._get_heap_as_list()), 'heap property must be satisfied.') # Iterate through the heap and make sure the elements are present list_index = 0 for element in self._heap: self.assertEqual( element, self._sortedListofElements[list_index], 'heap contents did not match up when iterating over a known list of elements.' ) list_index = list_index + 1 def tearDown(self): unittest.TestCase.tearDown(self)