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.")
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.")
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.")
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))
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))
def test_none(self): """ Test sum_internal on None. """ self.assertEqual(sum_internal(None), 0, "sum_internal on None should " + "return 0.")