def test_traverse(self): self.assertEqual({"root", "child1", "child2", "child3", "child4"}, set(t.obj for t in Tree.from_tuples(self.tree).traverse())) self.assertEqual( {"t", "1", "2", "3", "4"}, set(Tree.from_tuples(self.tree).traverse(lambda x: x.obj[-1])))
def test_traverse(self): self.assertEqual( {"root", "child1", "child2", "child3", "child4"}, set(t.obj for t in Tree.from_tuples(self.tree).traverse()) ) self.assertEqual( {"t", "1", "2", "3", "4"}, set(Tree.from_tuples(self.tree).traverse(lambda x: x.obj[-1])) )
def test_get_level(self): tree = Tree.from_tuples(self.tree) self.assertEqual(set(t.obj for t in tree.get_level(0)), {"root"}) self.assertEqual(set(t.obj for t in tree.get_level(1)), {"child1", "child2"}) self.assertEqual(set(t.obj for t in tree.get_level(2)), {"child3", "child4"}) self.assertEqual(set(t.obj for t in tree.get_level(5)), set())