Пример #1
0
        public void AddRangeTests()
        {
            Tree <string> tree = new Tree <string>("Root");

            Tree <string>[] children = { new Tree <string>("Child1"), new Tree <string>("Child2"), new Tree <string>("Child3") };
            tree.AddBranches(children);

            Assert.AreEqual(3, tree.Branches.Count);
            Assert.AreEqual(tree.Branches[0].Value, "Child1");
            Assert.AreEqual(tree.Branches[1].Value, "Child2");
            Assert.AreEqual(tree.Branches[2].Value, "Child3");
        }
Пример #2
0
    public static Tree BuildTree(IEnumerable <TreeBuildingRecord> records)
    {
        var c = records.Count();

        if (c == 0 || c - 1 != records.Select(rec => rec.RecordId).Max())
        {
            throw new ArgumentException();
        }

        var tree     = new Tree(records.First(r => r.RecordId == 0));
        var branches = records.Where(r => r.RecordId > 0).Select(x => new Tree(x));

        tree.AddBranches(branches);

        return(tree);
    }