Esempio n. 1
0
        public void PTreeFetchesByIndexRange()
        {
            _testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
            Cleanup();

            var objs = TestResourceFactory.GetMockClassAObjects(5000).ToList();

            var seedIndex = new Seed32();
            var seedSegment = new Seed64();

            objs.ForEach(o => o.Id = seedIndex.Increment());
            var toAdd = objs.Select(o => new Tuple<MockClassA, long>(o, seedSegment.Increment())).ToList();

            using (var tree = new PTree<int, MockClassA, long>("Id", _testName + ".index"))
            {
                tree.Load();

                var ids = tree.AddOrUpdateRange(toAdd);

                Assert.AreEqual(5000, tree.Length);

                Assert.AreEqual(5, tree.GetFirstByIndex(5));
                Assert.AreEqual(5, tree.GetFirstBySegment(5));
                Assert.AreEqual(1, tree.GetByIndex(5).Count());

                tree.AddOrUpdate(new Tuple<MockClassA, long>(TestResourceFactory.CreateRandom().WithId(seedIndex.Increment()), seedSegment.Increment()));

                Assert.AreEqual(5001, tree.Length);

                long[] loc;
                var range = tree.GetByIndexRangeInclusive(51, 250, out loc);

                Assert.AreEqual(200, range.Length);
            }

            using (var tree = new PTree<int, MockClassA, long>("Id", _testName + ".index"))
            {
                tree.Load();

                Assert.AreEqual(5001, tree.Length);
            }
        }