Beispiel #1
0
 def test_one_right_child(self):
     """
     Test count_leaves on a BTNode with one right child
     """
     t = BTNode(1, None, BTNode(2))
     self.assertNotEqual(count_leaves(t), 2, "count_leaves should not " +
                         "count None or any BTNodes with children as" +
                         " leaf nodes.")
     self.assertEqual(count_leaves(t), 1, "count_leaves should return 1 " +
                      "when used on a BTNode with only one child, " +
                      "where the child is a leaf.")
 def test_one_left_child(self):
     """
     Test count_leaves on a BinaryTree with one left child.
     """
     t = BinaryTree(1, BinaryTree(2))
     self.assertNotEqual(
         count_leaves(t), 2, "count_leaves should not " +
         "count None or any BinaryTrees with children as" + " leaf nodes.")
     self.assertEqual(
         count_leaves(t), 1, "count_leaves should return 1 " +
         "when used on a BinaryTree with only one child, " +
         "where the child is a leaf.")
 def test_leaf(self):
     """
     Test count_leaves on a leaf.
     """
     self.assertEqual(
         count_leaves(BinaryTree(1)), 1,
         "count_leaves should" + " return 1 when used on a leaf.")
Beispiel #4
0
 def test_two_leaf_children(self):
     """
     Test count_leaves on a BTNode with two leaf children.
     """
     t = BTNode(1, BTNode(2), BTNode(3))
     self.assertEqual(count_leaves(t), 2, "count_leaves should count all " +
                      "of the leaves in the entire BTNode.")
    def test_returns_int(self):
        """
        Test count_leaves to make sure it returns an int.
        """
        return_type = type(count_leaves(BinaryTree(1)))

        self.assertEqual(
            return_type, int, "count_leaves should return type " +
            "int, but instead returned type {}.".format(return_type))
 def test_count_leaves(self, tuple_tree):
     """
     Test count_leaves on a randomly generated BinaryTree.
     """
     (t, expected) = tuples_to_tree(tuple_tree)
     actual = count_leaves(t)
     self.assertEqual(actual, expected,
                      ("test_count_leaves on BinaryTree\n{}\nReturned {}" +
                       " instead of {}.").format(tuple_tree, actual,
                                                 expected))
 def test_none(self):
     """
     Test count_leaves on None.
     """
     self.assertEqual(count_leaves(None), 0,
                      "count_leaves on None should " + "return 0.")