コード例 #1
0
        public void HeadTailIndicesStructCreationPackkedValueTest(ushort head, ushort tail)
        {
            var data = new ByteArrayPool.HeadTailIndicesStruct((int)(((uint)head << 16) | tail));

            Assert.Equal(head, data.Head);
            Assert.Equal(tail, data.Tail);

            Assert.Equal((int)(((uint)head << 16) | tail), data.Pack());
        }
コード例 #2
0
        public void HeadTailIndicesStructUpdateTest(ushort head, ushort tail, int poolSize)
        {
            var data = new ByteArrayPool.HeadTailIndicesStruct(head, tail);

            Assert.Equal((tail - head + poolSize) % poolSize, data.ElementCount(poolSize));
            Assert.Equal(data.ElementCount(poolSize) > ByteArrayPool.GapSize, data.HasAvailableElements(poolSize));

            Assert.Equal(head, data.MoveHeadForward(poolSize));
            Assert.Equal(head + 1, data.Head);

            while (data.HasAvailableElements(poolSize))
            {
                data.MoveHeadForward(poolSize);
            }

            Assert.True(data.ElementCount(poolSize) <= ByteArrayPool.GapSize);
            while (!data.HasAvailableElements(poolSize))
            {
                data.MoveTailForward(poolSize);
            }

            data.MoveHeadForward(poolSize);

            Assert.Equal((data.Tail - data.Head + poolSize) % poolSize, ByteArrayPool.GapSize);
            Assert.Equal(ByteArrayPool.GapSize, data.ElementCount(poolSize));

            Assert.True(data.HasFreeSpace(poolSize));

            int count = ByteArrayPool.GapSize;

            while (data.HasFreeSpace(poolSize))
            {
                data.MoveTailForward(poolSize);
                count++;
                Assert.Equal(count, data.ElementCount(poolSize));
            }

            Assert.True(data.HasAvailableElements(poolSize));
            Assert.Equal(count, data.ElementCount(poolSize));
        }