Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
21 changes: 11 additions & 10 deletions AAD.Tests/TreeNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,28 @@ public class TreeNode<T>
public T Value { get; }
public TreeNode<T>? Parent { get; private set; }
public List<TreeNode<T>> Children { get; }

private int _level;
public TreeNode(T value, TreeNode<T>? parent = null)
{
Value = value;
Parent = parent;
Children = new List<TreeNode<T>>();

if (Parent != null)
{
this._level = Parent.Level() + 1;
}
else
{
this._level = 0;
}
}

public bool IsRoot => Parent == null;

public int Level()
{
var level = 0;
var current = this;
while (current.Parent != null)
{
level++;
current = current.Parent;
}

return level;
return this._level;
}

public TreeNode<T> Add(T childValue) =>
Expand Down