When you create nodes with specifying an integer as the name of the node, finding a node like so @tree[node_name] results in the node at the index, not the node named as the integer. The test below fails:
@root = Tree::TreeNode.new("ROOT", "Root Node")
@child1 = Tree::TreeNode.new("Child1", "Child Node 1")
@child2 = Tree::TreeNode.new("Child2", "Child Node 2")
@child3 = Tree::TreeNode.new("Child3", "Child Node 3")
@child4 = Tree::TreeNode.new("Child4", "Grand Child 1")
@child5 = Tree::TreeNode.new("Child5", "Child Node 4")
@n_root = Tree::TreeNode.new(0, "Root Node")
@n_child1 = Tree::TreeNode.new(1, "Child Node 1")
@n_child2 = Tree::TreeNode.new(2, "Child Node 2")
@n_child3 = Tree::TreeNode.new(3, "Child Node 3")
@n_child4 = Tree::TreeNode.new(4, "Grand Child 1")
@n_child5 = Tree::TreeNode.new(5, "Child Node 4")
@root << @child1
@root << @child2
@root << @child3 << @child4
@n_root << @n_child1
@n_root << @n_child2
@n_root << @n_child3 << @n_child4
assert_equal(@root['Child1'].name,'Child1') #passes
assert_equal(@n_root[1].name,1) #fails
Perhaps integers should be explicitly disallowed as node names?
When you create nodes with specifying an integer as the name of the node, finding a node like so @tree[node_name] results in the node at the index, not the node named as the integer. The test below fails:
Perhaps integers should be explicitly disallowed as node names?