示例#1
0
        public void TestUnclaimedRanges()
        {
            var parentRanges = new NestedRanges <int>(-1, 0, 10);

            var range1 = parentRanges.ClaimSubrangeWithin(1, 1, 1);
            var range2 = parentRanges.ClaimSubrangeWithin(2, 3, 1);
            var range3 = parentRanges.ClaimSubrangeWithin(3, 5, 1);
            var range4 = parentRanges.ClaimSubrangeWithin(4, 7, 1);

            AssertLengthAndOffsets(parentRanges, 10, 0, 0);
            AssertLengthAndOffsets(range1, 1, 1, 1);
            AssertLengthAndOffsets(range2, 1, 3, 3);
            AssertLengthAndOffsets(range3, 1, 5, 5);
            AssertLengthAndOffsets(range4, 1, 7, 7);

            range1.ResizeInPlace(2);
            range2.ResizeSelfAndParents(2);
            range3.ClaimSubrangeAtEnd(-1, 1);
            range4.FreeAndMarkAsUnclaimed();

            AssertLengthAndOffsets(parentRanges, 12, 0, 0);
            AssertLengthAndOffsets(range1, 2, 1, 1);
            AssertLengthAndOffsets(range2, 2, 3, 3);
            AssertLengthAndOffsets(range3, 2, 6, 6);

            parentRanges.RemoveAllUnclaimedSpace();

            AssertLengthAndOffsets(parentRanges, 6, 0, 0);
            AssertLengthAndOffsets(range1, 2, 0, 0);
            AssertLengthAndOffsets(range2, 2, 2, 2);
            AssertLengthAndOffsets(range3, 2, 4, 4);
        }
示例#2
0
        public void TestClaimingChildrenWithin()
        {
            var nestedRanges = new NestedRanges <int>(-1, -1, 10);

            Assert.AreEqual(-1, nestedRanges.Data);
            Assert.AreEqual(10, nestedRanges.Length);

            var zeroethChild = nestedRanges.ClaimSubrangeWithin(0, 0, 0);

            Assert.AreEqual(0, zeroethChild.Data);
            Assert.AreEqual(0, zeroethChild.GetAbsoluteOffset());
            Assert.AreEqual(0, zeroethChild.GetRelativeOffset());
            Assert.AreEqual(0, zeroethChild.Length);

            var firstChild = nestedRanges.ClaimSubrangeWithin(1, 0, 1);

            Assert.AreEqual(1, firstChild.Data);
            Assert.AreEqual(0, firstChild.GetAbsoluteOffset());
            Assert.AreEqual(0, firstChild.GetRelativeOffset());
            Assert.AreEqual(1, firstChild.Length);

            var secondChild = nestedRanges.ClaimSubrangeWithin(2, 1, 2);

            Assert.AreEqual(2, secondChild.Data);
            Assert.AreEqual(1, secondChild.GetAbsoluteOffset());
            Assert.AreEqual(1, secondChild.GetRelativeOffset());
            Assert.AreEqual(2, secondChild.Length);

            var thirdChild = nestedRanges.ClaimSubrangeWithin(3, 3, 3);

            Assert.AreEqual(3, thirdChild.Data);
            Assert.AreEqual(3, thirdChild.GetAbsoluteOffset());
            Assert.AreEqual(3, thirdChild.GetRelativeOffset());
            Assert.AreEqual(3, thirdChild.Length);

            var fourthChild = nestedRanges.ClaimSubrangeWithin(4, 6, 4);

            Assert.AreEqual(4, fourthChild.Data);
            Assert.AreEqual(6, fourthChild.GetAbsoluteOffset());
            Assert.AreEqual(6, fourthChild.GetRelativeOffset());
            Assert.AreEqual(4, fourthChild.Length);

            Assert.AreEqual(10, nestedRanges.Length);
        }