def test_find_node(self): node = Tree(n_children=4) address = [0, 2, 3, 0] # No-one lives at this address: return None self.assertIsNone(node.find_node(address)) # Generate node with given address and try to recover it. for a in address: node.split() node = node.get_child(a) self.assertEqual(node, node.get_root().find_node(address))
def test_get_depth(self): # New node should have depth 0 node = Tree(n_children=2) self.assertEqual(node.get_depth(), 0, 'ROOT node should have depth 0') # Split node 10 times for _ in range(10): node.split() node = node.get_child(1) # Last generation should have depth 10 self.assertEqual(node.get_depth(), 10, 'Node should have depth 10.') self.assertEqual(node.get_root().get_depth(), 0, \ 'ROOT node should have depth 0')
def test_tree_depth(self): # New node should have depth 0 node = Tree(n_children=2) self.assertEqual(node.tree_depth(),0,\ 'Tree should have depth 0') # Split node 10 times for i in range(10): node.split() node = node.get_child(1) # All nodes should have the same tree_depth self.assertEqual(node.tree_depth(),10,\ 'Tree should have depth 10.') self.assertEqual(node.get_root().tree_depth(),10,\ 'Tree should have depth 10.')