コード例 #1
0
        public void TwoElementHierarchy_GetChildren()
        {
            short id1 = 1;
            short id2 = 2;
            short id3 = 3;

            var items = new List<Relation>();
            items.Add(new Relation { Child = id1, Parent = id2 });
            items.Add(new Relation { Child = id2, Parent = id3 });

            var result = new Hierarchy(items);

            var children1 = result.GetChildren(id1);
            Assert.AreEqual(1, children1.Count());
            Assert.IsTrue(children1.Contains(id1));

            var children2 = result.GetChildren(id2);
            Assert.AreEqual(2, children2.Count());
            Assert.IsTrue(children2.Contains(id1));
            Assert.IsTrue(children2.Contains(id2));

            var children3 = result.GetChildren(id3);
            Assert.AreEqual(3, children3.Count());
            Assert.IsTrue(children3.Contains(id1));
            Assert.IsTrue(children3.Contains(id2));
            Assert.IsTrue(children3.Contains(id3));
        }
コード例 #2
0
 public void NullParameterTest()
 {
     var hierarchy = new Hierarchy(null);
     Assert.IsNotNull(hierarchy);
     Assert.AreEqual(1, hierarchy.GetChildren(1).Single());
     Assert.AreEqual(1, hierarchy.GetParents(1).Single());
 }
コード例 #3
0
        public void SingleElement_GetChildren()
        {
            short id1 = 1;
            short id2 = 2;

            var items = new List<Relation>();
            items.Add(new Relation { Child = id1, Parent = id2 });

            var result = new Hierarchy(items);

            var children = result.GetChildren(id1);
            Assert.AreEqual(1, children.Count());
            Assert.IsTrue(children.Contains(id1));

            var children0 = result.GetChildren(id2);
            Assert.AreEqual(2, children0.Count());
            Assert.IsTrue(children0.Contains(id1));
            Assert.IsTrue(children0.Contains(id2));
        }
コード例 #4
0
        public void AllItemsPoshortDown_GetChildren()
        {
            var items = new List<Relation>();
            items.Add(new Relation{ Child = i1, Parent = i3});
            items.Add(new Relation{ Child = i1, Parent = i4});
            items.Add(new Relation{ Child = i2, Parent = i3});
            items.Add(new Relation{ Child = i2, Parent = i4});
            items.Add(new Relation{ Child = i1, Parent = i5});
            items.Add(new Relation{ Child = i2, Parent = i5});
            items.Add(new Relation{ Child = i3, Parent = i5});
            items.Add(new Relation{ Child = i4, Parent = i5});

            var result = new Hierarchy(items);

            this.AssertHelper(new List<short> { i1 }, result.GetChildren(i1));
            this.AssertHelper(new List<short> { i2 }, result.GetChildren(i2));
            this.AssertHelper(new List<short> { i1, i2, i3 }, result.GetChildren(i3));
            this.AssertHelper(new List<short> { i1, i2, i4 }, result.GetChildren(i4));
            this.AssertHelper(new List<short> { i1, i2, i3, i4, i5 }, result.GetChildren(i5));
        }
コード例 #5
0
        public void ComplexHierarchy_TwoLevelTree()
        {
            var items = new List<Relation>();
            items.Add(new Relation{ Child = i2, Parent = i1});
            items.Add(new Relation{ Child = i3, Parent = i2});
            items.Add(new Relation{ Child = i4, Parent = i2});
            items.Add(new Relation{ Child = i5, Parent = i1});
            items.Add(new Relation{ Child = i6, Parent = i5});
            items.Add(new Relation{ Child = i7, Parent = i5});
            var result = new Hierarchy(items);

            this.AssertHelper(new List<short> { i1 }, result.GetParents(i1));
            this.AssertHelper(new List<short> { i1, i2, i3, i4, i5, i6, i7 }, result.GetChildren(i1));

            this.AssertHelper(new List<short> { i1, i2 }, result.GetParents(i2));
            this.AssertHelper(new List<short> { i2, i3, i4 }, result.GetChildren(i2));

            this.AssertHelper(new List<short> { i1, i2, i3 }, result.GetParents(i3));
            this.AssertHelper(new List<short> { i3 }, result.GetChildren(i3));
        }