def test_greater_child_index_one(self): """ The 'greater child index' of an element without children is None. """ h = MaxHeap() h._data.append('fake') self.assertIsNone(h._greater_child_index(0))
def test_greater_child_index_left_only(self): """ The 'greater child index' of an element with just a left child (no right child) returns the index of that left child. """ h = MaxHeap() h._data.append('fake') h._data.append('fake') self.assertEqual(1, h._greater_child_index(0))
def test_greater_child_index_left(self): """ The 'greater child index' of an element with a left and right child, is the index of the left child when it has a value greater than or equal to the right child. """ h = MaxHeap() h._data.append(10) h._data.append(5) h._data.append(1) self.assertEqual(1, h._greater_child_index(0))
def test_greater_child_index_right(self): """ The 'greater child index' of an element with a left and right child, is the index of the right child when it has a larger value than the left child. Hint: Refine your logic. What are the possible states? No children, a left but no right, or a left and a right. """ h = MaxHeap() h._data.append(10) h._data.append(1) h._data.append(5) self.assertEqual(2, h._greater_child_index(0))