コード例 #1
0
 def test4_node_height_uneven_subtrees(self):
     """The height of a BSTNode with subtrees of uneven heights is the height of the taller subtree plus one. (0p)"""
     node = BSTNode(1)
     node.left = BSTNode(2)
     node.left.left = BSTNode(3)
     self.assertEqual(
         node.left.height(), 1,
         "Expected the height of a node with one child, which is a leaf, to be 1 but it was not."
     )
     node.right = BSTNode(4)
     self.assertEqual(
         node.right.height(), 0,
         "Expected the height of a leaf to be 0 but it was not.")
     self.assertEqual(
         node.height(),
         node.left.height() + 1,
         "Expected the height of a node with two children, left and right, of which right is a leaf and left has one child, which is a leaf, to be the height of left plus one but it was not."
     )
コード例 #2
0
 def test3_node_height_one_child(self):
     """The height of a BSTNode with one child is 1 and the height of that child is 0. (0p)"""
     node = BSTNode(1)
     node.left = BSTNode(2)
     self.assertEqual(node.height(), 1)
     self.assertEqual(node.left.height(), 0)
コード例 #3
0
 def test2_single_node_height(self):
     """The height of a BSTNode with no children is 0. (0p)"""
     node = BSTNode(1)
     self.assertEqual(node.height(), 0)