def test_height_of_known_height_tree(self): ''' assert that the height of a tree known to be 4 is actually 4 ''' t = Tree() t.add(1) t.add(2) t.add(3) t.add(4) self.assertEqual(t.height(), 4)
def create_three_node_tree(self): ''' create a sample tree which looks like: 23 /\ 15 47 ''' t = Tree() t.add(23) t.add(15) t.add(47) return t
def test_4_node_right_tree(self): ''' another sample tree, this one with only right nodes 13 \ 14 \ 15 ''' t = Tree() t.add(13) t.add(14) t.add(15) self.assertIsNone(t.root.left) self.assertEqual(t.root.value, 13) self.assertEqual(t.root.right.value, 14) self.assertEqual(t.root.right.right.value, 15)
def create_sample_tree(self): ''' create a sample tree to use in the traversal implementations ''' t = Tree() t.add(100) t.add(50) t.add(25) t.add(75) t.add(150) t.add(125) t.add(175) t.add(110) return t.root
def create_sample_tree(self): ''' create a sample tree to use in the traversal implementations ''' t = Tree() t.add(100) t.add(50) t.add(25) t.add(75) t.add(150) t.add(125) t.add(175) t.add(110) return t.root
def test_one_node_tree(self): t = Tree() t.add(23) self.assertEqual(t.root.value, 23)