Exemplo n.º 1
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 + FixedList.PaddingBytes <byte>() + sizeof(byte) * i, &s, sizeof(byte));
            }
            Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
        }
    }
Exemplo n.º 2
0
    public void FixedListInt32HasExpectedLayout()
    {
        var actual = new FixedListInt32();

        for (var i = 0; i < 7; ++i)
        {
            actual.Add((int)i);
        }
        unsafe
        {
            var e = stackalloc byte[32];
            e[0] = (byte)((7 >> 0) & 0xFF);
            e[1] = (byte)((7 >> 8) & 0xFF);
            for (var i = 0; i < 7; ++i)
            {
                var s = (int)i;
                UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes <int>() + sizeof(int) * i, &s, sizeof(int));
            }
            Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
        }
    }
Exemplo n.º 3
0
    public void FixedListFloat64HasExpectedLayout()
    {
        var actual = new FixedListFloat64();

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