Ejemplo n.º 1
0
 def test_leaf(self):
     """
     Test sum_internal on a leaf.
     """
     self.assertEqual(
         sum_internal(BTNode(2)), 0,
         "sum_internal should" + " return 0 when used on a leaf.")
Ejemplo n.º 2
0
 def test_one_left_child(self):
     """
     Test sum_internal on a BTNode with one left child.
     """
     t = BTNode(1, BTNode(5))
     self.assertNotEqual(
         sum_internal(t), 5, "sum_internal should not " +
         "count None or any BTNodes without children as" +
         " internal nodes.")
     self.assertNotEqual(
         sum_internal(t), 6, "sum_internal should not " +
         "count None or any BTNodes without children as" +
         " internal nodes.")
     self.assertEqual(
         sum_internal(t), 1, "sum_internal should return the " +
         "data of the root node when used on a BTNode " +
         "with a single leaf child.")
Ejemplo n.º 3
0
 def test_two_leaf_children(self):
     """
     Test sum_internal on a BTNode with two leaf children.
     """
     t = BTNode(5, BTNode(4), BTNode(3))
     self.assertEqual(
         sum_internal(t), 5, "sum_internal should sum all " +
         "of the internal nodes in the entire BTNode.")
Ejemplo n.º 4
0
 def test_one_right_child(self):
     """
     Test sum_internal on a BinaryTree with one right child
     """
     t = BinaryTree(1, None, BinaryTree(5))
     self.assertNotEqual(
         sum_internal(t), 5, "sum_internal should not " +
         "count None or any BinaryTrees without children as" +
         " internal nodes.")
     self.assertNotEqual(
         sum_internal(t), 6, "sum_internal should not " +
         "count None or any BinaryTrees without children as" +
         " internal nodes.")
     self.assertEqual(
         sum_internal(t), 1, "sum_internal should return the " +
         "value of the root node when used on a BinaryTree " +
         "with a single leaf child.")
Ejemplo n.º 5
0
    def test_returns_int(self):
        """
        Test sum_internal to make sure it returns an int.
        """
        return_type = type(sum_internal(BTNode(1)))

        self.assertEqual(
            return_type, int, "sum_internal should return type " +
            "int, but instead returned type {}.".format(return_type))
Ejemplo n.º 6
0
 def test_sum_internal(self, tuple_tree):
     """
     Test sum_internal on a randomly generated BTNode.
     """
     (t, expected) = tuples_to_tree(tuple_tree)
     actual = sum_internal(t)
     self.assertEqual(actual, expected,
                      ("test_sum_internal on BTNode\n{}\nReturned {}" +
                       " instead of {}.").format(tuple_tree, actual,
                                                 expected))
Ejemplo n.º 7
0
 def test_none(self):
     """
     Test sum_internal on None.
     """
     self.assertEqual(sum_internal(None), 0,
                      "sum_internal on None should " + "return 0.")