Пример #1
0
    public void FixedListByte128HasExpectedCapacity()
    {
        var list             = new FixedListByte128();
        var expectedCapacity = 126;

        for (int i = 0; i < expectedCapacity; ++i)
        {
            list.Add((byte)i);
        }
        Assert.Throws <IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
    }
Пример #2
0
    public void FixedListByte128RemoveRange()
    {
        var list = new FixedListByte128();

        list.Add(0);
        list.Add(3);
        list.Add(3);
        list.Add(1);
        list.Add(2);
        list.RemoveRange(1, 2);
        for (var i = 0; i < 3; ++i)
        {
            Assert.AreEqual(i, list[i]);
        }
    }
Пример #3
0
    public void FixedListByte128InsertRange()
    {
        var list = new FixedListByte128();

        list.Add(0);
        list.Add(3);
        list.Add(4);
        list.InsertRange(1, 2);
        list[1] = 1;
        list[2] = 2;
        for (var i = 0; i < 5; ++i)
        {
            Assert.AreEqual(i, list[i]);
        }
    }
Пример #4
0
    public void FixedListByte128ToFixedListByte64()
    {
        var a = new FixedListByte128();

        for (var i = 0; i < 126; ++i)
        {
            a.Add((byte)i);
        }
        Assert.Throws <IndexOutOfRangeException> (() => { var b = new FixedListByte64(a); });
    }
Пример #5
0
    public void FixedListByte128Sort()
    {
        var list = new FixedListByte128();

        for (var i = 0; i < 5; ++i)
        {
            list.Add((byte)(4 - i));
        }
        list.Sort();
        for (var i = 0; i < 5; ++i)
        {
            Assert.AreEqual(i, list[i]);
        }
    }
Пример #6
0
    public void FixedListByte128HasExpectedLayout()
    {
        var actual = new FixedListByte128();

        for (var i = 0; i < 126; ++i)
        {
            actual.Add((byte)i);
        }
        unsafe
        {
            var e = stackalloc byte[128];
            e[0] = (byte)((126 >> 0) & 0xFF);
            e[1] = (byte)((126 >> 8) & 0xFF);
            for (var i = 0; i < 126; ++i)
            {
                var s = (byte)i;
                UnsafeUtility.MemCpy(e + 2 + sizeof(byte) * i, &s, sizeof(byte));
            }
            Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
        }
    }