def createSimpleTree(self, child_count, tree_name="base"): root = EntityTreeNode(EntityStructure(tree_name)) for i in range(child_count): child = EntityTreeNode(EntityStructure("child {0} ({1})".format(i, tree_name))) root.append_a_child(child) EntityTrees().update_subtree_width(root) return root
def test_node_subtree_with_two_children_has_two_unit_width(self): node = EntityTreeNode(None) node2 = EntityTreeNode(None) node3 = EntityTreeNode(None) node.append_a_child(node2) node.append_a_child(node3) self.assertEqual(EntityTrees().update_subtree_width(node), 2) self.assertEqual(node.subtree_width_in_units, 2)
def test_node_arbitrary_subtree_width(self): node1 = EntityTreeNode(None) node11 = EntityTreeNode(None) node111 = EntityTreeNode(None) node112 = EntityTreeNode(None) node12 = EntityTreeNode(None) node121 = EntityTreeNode(None) node122 = EntityTreeNode(None) node123 = EntityTreeNode(None) node1. append_a_child(node11) node1. append_a_child(node12) node11.append_a_child(node111) node11.append_a_child(node112) node12.append_a_child(node121) node12.append_a_child(node122) node12.append_a_child(node123) self.assertEqual(EntityTrees().update_subtree_width(node1), 5) self.assertEqual(node1.subtree_width_in_units, 5) self.assertEqual(node11.subtree_width_in_units, 2) self.assertEqual(node12.subtree_width_in_units, 3)
def test_node_subtree_with_one_child_has_one_unit_width(self): node = EntityTreeNode(None) node2 = EntityTreeNode(None) node.append_a_child(node2) self.assertEqual(EntityTrees().update_subtree_width(node), 1) self.assertEqual(node.subtree_width_in_units, 1)
def test_subtree_of_default_node_has_one_unit_width(self): node = EntityTreeNode(None) self.assertEqual(EntityTrees().update_subtree_width(node), 1) self.assertEqual(node.subtree_width_in_units, 1)
def test_default_node_has_one_unit_width(self): node = EntityTreeNode(None) self.assertEqual(node.node_width_in_units, 1)
def test_build_tree_from_one_node(self): node = EntityTreeNode(EntityStructure("Test name")) self.tree_widget.build_from_root(node) node_name = node.get_name() root_name = self.tree_widget.get_root_widget().name self.assertEqual(node_name, root_name)