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')
@author: hans-werner """ from mesh import Tree import matplotlib.pyplot as plt import numpy as np tree = Tree(n_children=2, regular=True) tree.split() for c in tree.get_children(): c.split() for cc in c.get_children(): cc.split() print(tree.get_depth()) leaves = tree.get_leaves() leaves.pop() w = 0 max_depth = 0 for leaf in leaves: ld = leaf.get_depth() w += 2**(-leaf.get_depth()) if ld > max_depth: max_depth = ld h = 2**(-max_depth) fig, ax = plt.subplots()