Ejemplo n.º 1
0
        public void TestRemoveAt()
        {
            var buffer = new CCircularBuffer <long>(5);

            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            Assert.AreEqual(default(long), buffer.Enqueue(3));
            Assert.AreEqual(default(long), buffer.Enqueue(4));
            Assert.AreEqual(default(long), buffer.Enqueue(5));
            buffer.RemoveAt(buffer.IndexOf(2));
            buffer.RemoveAt(buffer.IndexOf(4));
            Assert.AreEqual(3, buffer.Count);
            Assert.AreEqual(1, buffer.Dequeue());
            Assert.AreEqual(3, buffer.Dequeue());
            Assert.AreEqual(5, buffer.Dequeue());
            Assert.AreEqual(0, buffer.Count);
            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            Assert.AreEqual(default(long), buffer.Enqueue(3));
            Assert.AreEqual(default(long), buffer.Enqueue(4));
            Assert.AreEqual(default(long), buffer.Enqueue(5));
            buffer.RemoveAt(buffer.IndexOf(1));
            buffer.RemoveAt(buffer.IndexOf(3));
            buffer.RemoveAt(buffer.IndexOf(5));
            Assert.AreEqual(2, buffer.Count);
            Assert.AreEqual(2, buffer.Dequeue());
            Assert.AreEqual(4, buffer.Dequeue());
            Assert.AreEqual(0, buffer.Count);
        }
Ejemplo n.º 2
0
        public void TestUnderwrite()
        {
            var buffer = new CCircularBuffer <long>(5);

            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            Assert.AreEqual(default(long), buffer.Enqueue(3));
            Assert.AreEqual(3, buffer.Count);
            Assert.AreEqual(1, buffer.Dequeue());
            Assert.AreEqual(2, buffer.Dequeue());
            Assert.AreEqual(3, buffer.Dequeue());
            Assert.AreEqual(0, buffer.Count);
        }
Ejemplo n.º 3
0
        public void TestEnumerationWhenPartiallyFull()
        {
            var buffer = new CCircularBuffer <long>(3);

            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            var i = 0;

            foreach (var value in buffer)
            {
                Assert.AreEqual(++i, value);
            }
            Assert.AreEqual(i, 2);
        }
Ejemplo n.º 4
0
        public void TestDecreaseCapacityWhenFull()
        {
            var buffer = new CCircularBuffer <long>(3);

            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            Assert.AreEqual(default(long), buffer.Enqueue(3));
            Assert.AreEqual(3, buffer.Count);
            buffer.Capacity = 2;
            Assert.AreEqual(2, buffer.Count);
            Assert.AreEqual(1, buffer.Dequeue());
            Assert.AreEqual(2, buffer.Dequeue());
            Assert.AreEqual(0, buffer.Count);
        }
Ejemplo n.º 5
0
        public void TestPeek()
        {
            var buffer = new CCircularBuffer <long>(5);

            Assert.AreEqual(default(long), buffer.Enqueue(1));
            Assert.AreEqual(default(long), buffer.Enqueue(2));
            Assert.AreEqual(default(long), buffer.Enqueue(3));

            Assert.AreEqual(1, buffer.Peek());

            long[] arrPeek = buffer.Peek_OrNull(4);
            Assert.AreEqual(1, arrPeek[0]);
            Assert.AreEqual(2, arrPeek[1]);
            Assert.AreEqual(3, arrPeek[2]);
            Assert.AreEqual(3, arrPeek.Length);
        }
Ejemplo n.º 6
0
    private byte[] CombineBuffer_Header_And_Packet <Packet>(Packet pPacket, Packet_Header pPacketHeader) where Packet : INetworkPacket
    {
        bool bIsGenerate = pPacketHeader != null;

        if (bIsGenerate == false)
        {
            OnGeneratePacketHeader(pPacket, out bIsGenerate, out pPacketHeader);
        }

        _pBufferSend.Clear();
        if (bIsGenerate)
        {
            pPacketHeader.INetworkPacketHeader_Set_Header(ByteExtension.SizeOf <Packet>(), pPacket.INetworkPacket_Get_PacketID());
            _pBufferSend.Enqueue(ByteExtension.ConvertByteArray(pPacketHeader));
        }
        _pBufferSend.Enqueue(ByteExtension.ConvertByteArray(pPacket));

        return(_pBufferSend.Dequeue_OrNull(_pBufferSend.Count));
    }
Ejemplo n.º 7
0
        public void RingBuffer_Enqueue_Dequeue_Test()
        {
            SPacketTest_Struct pPacketTest  = new SPacketTest_Struct(1, "인큐_디큐_테스트");
            SPacketTest_Struct pPacketTest2 = new SPacketTest_Struct(2, "더미데이터");

            byte[] arrPacketData = ByteExtension.ConvertByteArray(pPacketTest);
            int    iDataSize     = arrPacketData.Length;

            var pBuffer = new CCircularBuffer <byte>(10240);

            pBuffer.Enqueue(arrPacketData);

            Assert.AreNotEqual(pPacketTest.iValue, pPacketTest2.iValue);
            Assert.AreNotEqual(pPacketTest.strValue, pPacketTest2.strValue);

            byte[] arrPacketData2 = pBuffer.Dequeue_OrNull(iDataSize);
            arrPacketData2.Convert_ToStruct(out pPacketTest2);

            Assert.AreEqual(pPacketTest.iValue, pPacketTest2.iValue);
            Assert.AreEqual(pPacketTest.strValue, pPacketTest2.strValue);
        }