def test_one_left_child(self): """ Test concatenate_leaves on a BinaryTree with one left child. """ t = BinaryTree("a", BinaryTree("b")) self.assertNotEqual( concatenate_leaves(t), "ab", "concatenate_leaves should not " + "count None or any BinaryTrees with children as" + " leaf nodes.") self.assertNotEqual( concatenate_leaves(t), "a", "concatenate_leaves should not " + "count None or any BinaryTrees with children as" + " leaf nodes.") self.assertEqual( concatenate_leaves(t), "b", "concatenate_leaves should return the " + "value of the leaf child when used on a BinaryTree " + "with a single leaf child.")
def test_leaf(self): """ Test concatenate_leaves on a leaf. """ self.assertEqual( concatenate_leaves(BTNode("a")), "a", "concatenate_leaves should" + " return the leaf's data when used on a leaf.")
def test_one_right_child(self): """ Test concatenate_leaves on a BTNode with one right child """ t = BTNode("a", None, BTNode("b")) self.assertNotEqual( concatenate_leaves(t), "ab", "concatenate_leaves should not " + "count None or any BTNodes with children as" + " leaf nodes.") self.assertNotEqual( concatenate_leaves(t), "a", "concatenate_leaves should not " + "count None or any BTNodes with children as" + " leaf nodes.") self.assertEqual( concatenate_leaves(t), "b", "concatenate_leaves should return the " + "data of the leaf child when used on a BTNode " + "with a single leaf child.")
def test_leaf(self): """ Test concatenate_leaves on a leaf. """ self.assertEqual( concatenate_leaves(BinaryTree("a")), "a", "concatenate_leaves should" + " return the leaf's value when used on a leaf.")
def test_two_leaf_children(self): """ Test concatenate_leaves on a BinaryTree with two leaf children. """ t = BinaryTree("a", BinaryTree("b"), BinaryTree("c")) self.assertEqual( concatenate_leaves(t), "bc", "concatenate_leaves should sum all " + "of the leaves in the entire BinaryTree.")
def test_returns_int(self): """ Test concatenate_leaves to make sure it returns an int. """ return_type = type(concatenate_leaves(BinaryTree("a"))) self.assertEqual( return_type, str, "concatenate_leaves should return type " + "int, but instead returned type {}.".format(return_type))
def test_concatenate_leaves(self, tuple_tree): """ Test concatenate_leaves on a randomly generated BinaryTree. """ (t, expected) = tuples_to_tree(tuple_tree) actual = concatenate_leaves(t) self.assertEqual(actual, expected, ("test_concatenate_leaves on BinaryTree\n{}" + "\nReturned {}" + " instead of {}.").format( tuple_tree, actual, expected))
def test_none(self): """ Test concatenate_leaves on None. """ self.assertEqual(concatenate_leaves(None), "", "concatenate_leaves on None should " + "return ''.")