def testYieldRootReturnsRoot(self): """Test that the yieldRoot function yields the root or not.""" n1, n2, n3, n4, n5 = createTree() val = tuple(it.treeyield_breadthfirst(n1, lambda n: n.children())) self.assertEqual(val, (n2, n3, n4, n5)) # Test without val = tuple(it.treeyield_breadthfirst( n1, lambda n: n.children(), yieldnode=True)) self.assertEqual(val, (n1, n2, n3, n4, n5))
def testGetChild(self): """Test that the getChild argument is called with proper parameters and yields the correct result.""" n1, n2, n3, n4, n5 = createTree() val = tuple(it.treeyield_breadthfirst( n1, lambda n: len(n.children()), lambda node, arg: node.getChild(arg))) self.assertEqual(val, (n2, n3, n4, n5))
def testIsBreadthFirst(self): """Test that the depth first sort returns as expected.""" n1, n2, n3, n4, n5 = createTree() ordered = n2, n3, n4, n5 val = tuple(it.treeyield_breadthfirst(n1, lambda n: n.children())) self.assertEqual(val, ordered)