Exemple #1
0
    static void test_sequence_buffer32()
    {
        Debug.Log("test_sequence_buffer32");

        const int Size = 256;

        var sequenceBuffer = new Network.SequenceBuffer32 <TestPacketData32>(Size);

        for (int i = 0; i < Size; ++i)
        {
            TestPacketData entry;
            entry.sequence = 0;
            Assert.IsTrue(sequenceBuffer.Exists((uint)i) == false);
            Assert.IsTrue(sequenceBuffer.Available((uint)i) == true);
            Assert.IsTrue(sequenceBuffer.Find((uint)i) == -1);
        }

        for (int i = 0; i <= Size * 4; ++i)
        {
            int index = sequenceBuffer.Insert((uint)i);
            Assert.IsTrue(index != -1);
            Assert.IsTrue(sequenceBuffer.GetSequence() == i + 1);
            sequenceBuffer.Entries[index].sequence = (uint)i;
        }

        for (int i = 0; i <= Size; ++i)
        {
            // note: outside bounds!
            int index = sequenceBuffer.Insert((uint)i);
            Assert.IsTrue(index == -1);
        }

        uint sequence = Size * 4;

        for (int i = 0; i < Size; ++i)
        {
            int index = sequenceBuffer.Find(sequence);
            Assert.IsTrue(index >= 0);
            Assert.IsTrue(index < Size);
            Assert.IsTrue(sequenceBuffer.Entries[index].sequence == sequence);
            sequence--;
        }

        sequenceBuffer.Reset();

        Assert.IsTrue(sequenceBuffer.GetSequence() == 0);

        for (int i = 0; i < Size; ++i)
        {
            Assert.IsTrue(sequenceBuffer.Exists((uint)i) == false);
            Assert.IsTrue(sequenceBuffer.Available((uint)i) == true);
            Assert.IsTrue(sequenceBuffer.Find((uint)i) == -1);
        }
    }