예제 #1
0
 private void AddToTree(IntervalTree <DateTimeRange> tree, List <DateTimeRange> list)
 {
     foreach (DateTimeRange s in list)
     {
         tree.Insert(s, s);
     }
 }
예제 #2
0
        public void TestIntervalTree()
        {
            DateTimeRange r0 = new DateTimeRange(baseDate, baseDate.AddHours(2));
            DateTimeRange r1 = new DateTimeRange(baseDate, baseDate.AddHours(4));
            DateTimeRange r2 = new DateTimeRange(baseDate.AddHours(5), baseDate.AddHours(7));
            DateTimeRange r3 = new DateTimeRange(baseDate, baseDate.AddHours(7));
            DateTimeRange r4 = new DateTimeRange(baseDate.AddHours(3), baseDate.AddHours(3));
            DateTimeRange r5 = new DateTimeRange(baseDate.AddHours(4), baseDate.AddHours(12));

            tree.Insert(r0, r0);
            tree.Insert(r1, r1);
            tree.Insert(r2, r2);
            tree.Insert(r3, r3);
            tree.Insert(r4, r4);
            tree.Insert(r5, r5);

            Assert.AreEqual(6, tree.NumNodes);
            Assert.AreEqual(5, tree.MaxDepth);

            DateTimeRange        s0     = new DateTimeRange(baseDate.AddHours(1), baseDate.AddHours(1));
            List <DateTimeRange> result = tree.FindAll(s0);

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual(r0, result[0]);
            Assert.AreEqual(r1, result[1]);
            Assert.AreEqual(r3, result[2]);
        }