//------------------------------------------------------------------------------
//
// This code was generated by a tool.
//
// TextTransform Samples/Packages/com.unity.collections/Unity.Collections.Tests/FixedListTests.tt
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using NUnit.Framework;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Collections.Tests;
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
using UnityEngine;
#endif
internal class FixedListTests : CollectionsTestFixture
{
struct NonComparableStruct
{
public int a;
}
struct DescendingComparer : IComparer where T : IComparable
{
public int Compare(T x, T y) => y.CompareTo(x);
}
[Test]
[IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
public void FixedList32BytesDebugView()
{
var list = new FixedList32Bytes();
CollectionAssert.IsEmpty(new FixedList32BytesDebugView(list).Items);
var reference = new []
{
new NonComparableStruct{ a = 123 },
new NonComparableStruct{ a = 234 },
new NonComparableStruct{ a = 345 },
};
list.Add(reference[0]);
list.Add(reference[1]);
list.Add(reference[2]);
CollectionAssert.AreEqual(reference, new FixedList32BytesDebugView(list).Items);
}
[Test]
[IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
public void FixedList64BytesDebugView()
{
var list = new FixedList64Bytes();
CollectionAssert.IsEmpty(new FixedList64BytesDebugView(list).Items);
var reference = new []
{
new NonComparableStruct{ a = 123 },
new NonComparableStruct{ a = 234 },
new NonComparableStruct{ a = 345 },
};
list.Add(reference[0]);
list.Add(reference[1]);
list.Add(reference[2]);
CollectionAssert.AreEqual(reference, new FixedList64BytesDebugView(list).Items);
}
[Test]
[IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
public void FixedList128BytesDebugView()
{
var list = new FixedList128Bytes();
CollectionAssert.IsEmpty(new FixedList128BytesDebugView(list).Items);
var reference = new []
{
new NonComparableStruct{ a = 123 },
new NonComparableStruct{ a = 234 },
new NonComparableStruct{ a = 345 },
};
list.Add(reference[0]);
list.Add(reference[1]);
list.Add(reference[2]);
CollectionAssert.AreEqual(reference, new FixedList128BytesDebugView(list).Items);
}
[Test]
public void FixedList32Byte_FixedBytes30ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 30; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 30; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Byte_ToNativeArrayWorks()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 30; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 30; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Byte_GenericHasExpectedLayout()
{
var actual = new FixedList32Bytes();
for(var i = 0; i < 30; ++i)
actual.Add((byte)i);
unsafe
{
var e = stackalloc byte[32];
e[0] = (byte)((30 >> 0) & 0xFF);
e[1] = (byte)((30 >> 8) & 0xFF);
for(var i = 0; i < 30; ++i)
{
var s = (byte)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
}
}
[Test]
public void FixedList32Byte_GenericHasExpectedCapacity()
{
var list = new FixedList32Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
[Test]
public void FixedList32Byte_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericRemoveRange()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericInsert()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericRemoveAt()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericRemove()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericRemoveSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_GenericSort()
{
var list = new FixedList32Bytes();
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]);
}
[Test]
public void FixedList32Byte_GenericSortCustomComparer()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((byte)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList32Byte_IndexOf()
{
var list = new FixedList32Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((byte)145);
r1 = list.Contains((byte)123);
r2 = list.Contains((byte)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList64Byte_FixedBytes62ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 62; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 62; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Byte_ToNativeArrayWorks()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 62; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 62; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Byte_GenericHasExpectedLayout()
{
var actual = new FixedList64Bytes();
for(var i = 0; i < 62; ++i)
actual.Add((byte)i);
unsafe
{
var e = stackalloc byte[64];
e[0] = (byte)((62 >> 0) & 0xFF);
e[1] = (byte)((62 >> 8) & 0xFF);
for(var i = 0; i < 62; ++i)
{
var s = (byte)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
}
}
[Test]
public void FixedList64Byte_GenericHasExpectedCapacity()
{
var list = new FixedList64Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
[Test]
public void FixedList64Byte_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericRemoveRange()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericInsert()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericRemoveAt()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericRemove()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericRemoveSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_GenericSort()
{
var list = new FixedList64Bytes();
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]);
}
[Test]
public void FixedList64Byte_GenericSortCustomComparer()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 5; ++i)
list.Add((byte)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList64Byte_IndexOf()
{
var list = new FixedList64Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((byte)145);
r1 = list.Contains((byte)123);
r2 = list.Contains((byte)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList128Byte_FixedBytes126ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 126; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 126; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList128Byte_ToNativeArrayWorks()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 126; ++i)
list.Add((byte)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 126; ++i)
Assert.AreEqual((byte)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList128Byte_GenericHasExpectedLayout()
{
var actual = new FixedList128Bytes();
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() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
}
}
[Test]
public void FixedList128Byte_GenericHasExpectedCapacity()
{
var list = new FixedList128Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
[Test]
public void FixedList128Byte_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericRemoveRange()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericInsert()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericRemoveAt()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericRemove()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericRemoveSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_GenericSort()
{
var list = new FixedList128Bytes();
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]);
}
[Test]
public void FixedList128Byte_GenericSortCustomComparer()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 5; ++i)
list.Add((byte)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList128Byte_IndexOf()
{
var list = new FixedList128Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((byte)145);
r1 = list.Contains((byte)123);
r2 = list.Contains((byte)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList32Byte_HasExpectedLayout()
{
var actual = new FixedList32Bytes();
for(var i = 0; i < 30; ++i)
actual.Add((byte)i);
unsafe
{
var e = stackalloc byte[32];
e[0] = (byte)((30 >> 0) & 0xFF);
e[1] = (byte)((30 >> 8) & 0xFF);
for(var i = 0; i < 30; ++i)
{
var s = (byte)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
}
}
[Test]
public void FixedList32Byte_HasExpectedCapacity()
{
var list = new FixedList32Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList32Byte_ : UnityEngine.ScriptableObject
{
public FixedList32Bytes List;
}
[Test]
public void FixedList32Byte_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((byte)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList32Byte_InsertRangeWithBeginEnd()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList32Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList32Byte_RemoveAt()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Byte_Remove()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Byte_RemoveSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Byte_RemoveRange()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Byte_RemoveAtSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList32Byte_RemoveRangeSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Byte_Insert()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Byte_Sort()
{
var list = new FixedList32Bytes();
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]);
}
[Test]
public void FixedList32Byte_To_FixedList64Byte()
{
var a = new FixedList32Bytes();
for(var i = 0; i < 30; ++i)
a.Add((byte)i);
var b = new FixedList64Bytes(a);
for(var i = 0; i < 30; ++i)
Assert.AreEqual((byte)i, b[i]);
}
[Test]
public void FixedList32Byte_To_FixedList128Byte()
{
var a = new FixedList32Bytes();
for(var i = 0; i < 30; ++i)
a.Add((byte)i);
var b = new FixedList128Bytes(a);
for(var i = 0; i < 30; ++i)
Assert.AreEqual((byte)i, b[i]);
}
[Test]
public void FixedList64Byte_HasExpectedLayout()
{
var actual = new FixedList64Bytes();
for(var i = 0; i < 62; ++i)
actual.Add((byte)i);
unsafe
{
var e = stackalloc byte[64];
e[0] = (byte)((62 >> 0) & 0xFF);
e[1] = (byte)((62 >> 8) & 0xFF);
for(var i = 0; i < 62; ++i)
{
var s = (byte)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
}
}
[Test]
public void FixedList64Byte_HasExpectedCapacity()
{
var list = new FixedList64Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList64Byte_ : UnityEngine.ScriptableObject
{
public FixedList64Bytes List;
}
[Test]
public void FixedList64Byte_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((byte)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList64Byte_InsertRangeWithBeginEnd()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList64Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList64Byte_RemoveAt()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Byte_Remove()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Byte_RemoveSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Byte_RemoveRange()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Byte_RemoveAtSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList64Byte_RemoveRangeSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Byte_Insert()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Byte_Sort()
{
var list = new FixedList64Bytes();
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]);
}
[Test]
public void FixedList64Byte_To_FixedList32Byte()
{
var a = new FixedList64Bytes();
for(var i = 0; i < 62; ++i)
a.Add((byte)i);
Assert.Throws (() => { var b = new FixedList32Bytes(a); } );
}
[Test]
public void FixedList64Byte_To_FixedList128Byte()
{
var a = new FixedList64Bytes();
for(var i = 0; i < 62; ++i)
a.Add((byte)i);
var b = new FixedList128Bytes(a);
for(var i = 0; i < 62; ++i)
Assert.AreEqual((byte)i, b[i]);
}
[Test]
public void FixedList128Byte_HasExpectedLayout()
{
var actual = new FixedList128Bytes();
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() + sizeof(byte) * i, &s, sizeof(byte));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
}
}
[Test]
public void FixedList128Byte_HasExpectedCapacity()
{
var list = new FixedList128Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((byte)i);
Assert.Throws (() => { list.Add((byte)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList128Byte_ : UnityEngine.ScriptableObject
{
public FixedList128Bytes List;
}
[Test]
public void FixedList128Byte_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((byte)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList128Byte_InsertRangeWithBeginEnd()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList128Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList128Byte_RemoveAt()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Byte_Remove()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((byte)3));
Assert.True(list.Remove((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Byte_RemoveSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((byte)3));
Assert.True(list.RemoveSwapBack((byte)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Byte_RemoveRange()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Byte_RemoveAtSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList128Byte_RemoveRangeSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Byte_Insert()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Byte_Sort()
{
var list = new FixedList128Bytes();
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]);
}
[Test]
public void FixedList128Byte_To_FixedList32Byte()
{
var a = new FixedList128Bytes();
for(var i = 0; i < 126; ++i)
a.Add((byte)i);
Assert.Throws (() => { var b = new FixedList32Bytes(a); } );
}
[Test]
public void FixedList128Byte_To_FixedList64Byte()
{
var a = new FixedList128Bytes();
for(var i = 0; i < 126; ++i)
a.Add((byte)i);
Assert.Throws (() => { var b = new FixedList64Bytes(a); } );
}
[Test]
public void FixedList32Int_FixedBytes30ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 7; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 7; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Int_ToNativeArrayWorks()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 7; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 7; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Int_GenericHasExpectedLayout()
{
var actual = new FixedList32Bytes();
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() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
}
}
[Test]
public void FixedList32Int_GenericHasExpectedCapacity()
{
var list = new FixedList32Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
[Test]
public void FixedList32Int_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericRemoveRange()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericInsert()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericRemoveAt()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericRemove()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericRemoveSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericSort()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_GenericSortCustomComparer()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList32Int_IndexOf()
{
var list = new FixedList32Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((int)145);
r1 = list.Contains((int)123);
r2 = list.Contains((int)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList64Int_FixedBytes62ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 15; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 15; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Int_ToNativeArrayWorks()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 15; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Int_GenericHasExpectedLayout()
{
var actual = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
actual.Add((int)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 = (int)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
}
}
[Test]
public void FixedList64Int_GenericHasExpectedCapacity()
{
var list = new FixedList64Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
[Test]
public void FixedList64Int_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericRemoveRange()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericInsert()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericRemoveAt()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericRemove()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericRemoveSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericSort()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_GenericSortCustomComparer()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList64Int_IndexOf()
{
var list = new FixedList64Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((int)145);
r1 = list.Contains((int)123);
r2 = list.Contains((int)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList128Int_FixedBytes126ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 31; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 31; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList128Int_ToNativeArrayWorks()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 31; ++i)
list.Add((int)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 31; ++i)
Assert.AreEqual((int)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList128Int_GenericHasExpectedLayout()
{
var actual = new FixedList128Bytes();
for(var i = 0; i < 31; ++i)
actual.Add((int)i);
unsafe
{
var e = stackalloc byte[128];
e[0] = (byte)((31 >> 0) & 0xFF);
e[1] = (byte)((31 >> 8) & 0xFF);
for(var i = 0; i < 31; ++i)
{
var s = (int)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
}
}
[Test]
public void FixedList128Int_GenericHasExpectedCapacity()
{
var list = new FixedList128Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
[Test]
public void FixedList128Int_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericRemoveRange()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericInsert()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericRemoveAt()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericRemove()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericRemoveSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericSort()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_GenericSortCustomComparer()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList128Int_IndexOf()
{
var list = new FixedList128Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((int)145);
r1 = list.Contains((int)123);
r2 = list.Contains((int)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList32Int_HasExpectedLayout()
{
var actual = new FixedList32Bytes();
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() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
}
}
[Test]
public void FixedList32Int_HasExpectedCapacity()
{
var list = new FixedList32Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList32Int_ : UnityEngine.ScriptableObject
{
public FixedList32Bytes List;
}
[Test]
public void FixedList32Int_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((int)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList32Int_InsertRangeWithBeginEnd()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList32Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList32Int_RemoveAt()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Int_Remove()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Int_RemoveSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Int_RemoveRange()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Int_RemoveAtSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList32Int_RemoveRangeSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList32Int_Insert()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_Sort()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Int_To_FixedList64Int()
{
var a = new FixedList32Bytes();
for(var i = 0; i < 7; ++i)
a.Add((int)i);
var b = new FixedList64Bytes(a);
for(var i = 0; i < 7; ++i)
Assert.AreEqual((int)i, b[i]);
}
[Test]
public void FixedList32Int_To_FixedList128Int()
{
var a = new FixedList32Bytes();
for(var i = 0; i < 7; ++i)
a.Add((int)i);
var b = new FixedList128Bytes(a);
for(var i = 0; i < 7; ++i)
Assert.AreEqual((int)i, b[i]);
}
[Test]
public void FixedList64Int_HasExpectedLayout()
{
var actual = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
actual.Add((int)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 = (int)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
}
}
[Test]
public void FixedList64Int_HasExpectedCapacity()
{
var list = new FixedList64Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList64Int_ : UnityEngine.ScriptableObject
{
public FixedList64Bytes List;
}
[Test]
public void FixedList64Int_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((int)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList64Int_InsertRangeWithBeginEnd()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList64Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList64Int_RemoveAt()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Int_Remove()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Int_RemoveSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Int_RemoveRange()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Int_RemoveAtSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList64Int_RemoveRangeSwapBack()
{
var list = new FixedList64Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList64Int_Insert()
{
var list = new FixedList64Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_Sort()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList64Int_To_FixedList32Int()
{
var a = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
a.Add((int)i);
Assert.Throws (() => { var b = new FixedList32Bytes(a); } );
}
[Test]
public void FixedList64Int_To_FixedList128Int()
{
var a = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
a.Add((int)i);
var b = new FixedList128Bytes(a);
for(var i = 0; i < 15; ++i)
Assert.AreEqual((int)i, b[i]);
}
[Test]
public void FixedList128Int_HasExpectedLayout()
{
var actual = new FixedList128Bytes();
for(var i = 0; i < 31; ++i)
actual.Add((int)i);
unsafe
{
var e = stackalloc byte[128];
e[0] = (byte)((31 >> 0) & 0xFF);
e[1] = (byte)((31 >> 8) & 0xFF);
for(var i = 0; i < 31; ++i)
{
var s = (int)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(int) * i, &s, sizeof(int));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
}
}
[Test]
public void FixedList128Int_HasExpectedCapacity()
{
var list = new FixedList128Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((int)i);
Assert.Throws (() => { list.Add((int)expectedCapacity); });
}
#if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
class ScriptableObjectFixedList128Int_ : UnityEngine.ScriptableObject
{
public FixedList128Bytes List;
}
[Test]
public void FixedList128Int_Serializes()
{
var a = UnityEngine.ScriptableObject.CreateInstance();
for(int i = 0; i < a.List.Capacity; ++i)
a.List.Add((int)i);
var b = UnityEngine.Object.Instantiate(a);
CollectionAssert.AreEqual(a.List, b.List);
}
#endif
[Test]
public void FixedList128Int_InsertRangeWithBeginEnd()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
private static void Expected(ref FixedList128Bytes container, int expectedLength, int[] expected)
{
Assert.AreEqual(expectedLength == 0, container.IsEmpty);
Assert.AreEqual(container.Length, expectedLength);
for (var i = 0; i < container.Length; ++i)
{
Assert.AreEqual(expected[i], container[i]);
}
}
[Test]
public void FixedList128Int_RemoveAt()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Int_Remove()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((int)3));
Assert.True(list.Remove((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Int_RemoveSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((int)3));
Assert.True(list.RemoveSwapBack((int)3));
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Int_RemoveRange()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Int_RemoveAtSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAtSwapBack(1);
list.RemoveAtSwapBack(1);
Expected(ref list, 3, new int[] { 0, 1, 3 });
}
[Test]
public void FixedList128Int_RemoveRangeSwapBack()
{
var list = new FixedList128Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRangeSwapBack(1, 2);
Expected(ref list, 3, new int[] { 0, 1, 2 });
}
[Test]
public void FixedList128Int_Insert()
{
var list = new FixedList128Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_Sort()
{
var list = new FixedList128Bytes();
for(var i = 0; i < 5; ++i)
list.Add((int)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList128Int_To_FixedList32Int()
{
var a = new FixedList128Bytes();
for(var i = 0; i < 31; ++i)
a.Add((int)i);
Assert.Throws (() => { var b = new FixedList32Bytes(a); } );
}
[Test]
public void FixedList128Int_To_FixedList64Int()
{
var a = new FixedList128Bytes();
for(var i = 0; i < 31; ++i)
a.Add((int)i);
Assert.Throws (() => { var b = new FixedList64Bytes(a); } );
}
[Test]
public void FixedList32Float_FixedBytes30ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 7; ++i)
list.Add((float)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 7; ++i)
Assert.AreEqual((float)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Float_ToNativeArrayWorks()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 7; ++i)
list.Add((float)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 7; ++i)
Assert.AreEqual((float)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList32Float_GenericHasExpectedLayout()
{
var actual = new FixedList32Bytes();
for(var i = 0; i < 7; ++i)
actual.Add((float)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 = (float)i;
UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes() + sizeof(float) * i, &s, sizeof(float));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
}
}
[Test]
public void FixedList32Float_GenericHasExpectedCapacity()
{
var list = new FixedList32Bytes();
var expectedCapacity = list.Capacity;
for(int i = 0; i < expectedCapacity; ++i)
list.Add((float)i);
Assert.Throws (() => { list.Add((float)expectedCapacity); });
}
[Test]
public void FixedList32Float_GenericInsertRangeWithBeginEnd()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.InsertRangeWithBeginEnd(1,3);
list[1] = 1;
list[2] = 2;
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericRemoveRange()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveRange(1, 2);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericInsert()
{
var list = new FixedList32Bytes() { 0, 3, 4 };
list.Insert(1,1);
list.Insert(2,2);
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericRemoveAt()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
list.RemoveAt(1);
list.RemoveAt(1);
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericRemove()
{
var list = new FixedList32Bytes() { 0, 3, 3, 1, 2 };
Assert.True(list.Remove((float)3));
Assert.True(list.Remove((float)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericRemoveSwapBack()
{
var list = new FixedList32Bytes() { 0, 3, 3, 2, 1 };
Assert.True(list.RemoveSwapBack((float)3));
Assert.True(list.RemoveSwapBack((float)3));
for(var i = 0; i < 3; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericSort()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((float)(4-i));
list.Sort();
for(var i = 0; i < 5; ++i)
Assert.AreEqual(i, list[i]);
}
[Test]
public void FixedList32Float_GenericSortCustomComparer()
{
var list = new FixedList32Bytes();
for(var i = 0; i < 5; ++i)
list.Add((float)(i));
list.Sort(new DescendingComparer());
for(var i = 0; i < 5; ++i)
Assert.AreEqual(4-i, list[i]);
}
[Test]
public unsafe void FixedList32Float_IndexOf()
{
var list = new FixedList32Bytes() { 123, 178 };
bool r0 = false, r1 = false, r2 = false;
GCAllocRecorder.ValidateNoGCAllocs(() =>
{
r0 = -1 != list.IndexOf((float)145);
r1 = list.Contains((float)123);
r2 = list.Contains((float)178);
});
Assert.False(r0);
Assert.True(r1);
Assert.True(r2);
}
[Test]
public void FixedList64Float_FixedBytes62ToNativeArrayWorksGeneric()
{
var list = new FixedList();
for(var i = 0; i < 15; ++i)
list.Add((float)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 15; ++i)
Assert.AreEqual((float)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Float_ToNativeArrayWorks()
{
var list = new FixedList64Bytes();
for(var i = 0; i < 15; ++i)
list.Add((float)(i * 123 + 234));
using(var array = list.ToNativeArray(Allocator.Temp))
{
for(var i = 0; i < 15; ++i)
Assert.AreEqual((float)(i * 123 + 234), array[i]);
}
}
[Test]
public void FixedList64Float_GenericHasExpectedLayout()
{
var actual = new FixedList64Bytes();
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() + sizeof(float) * i, &s, sizeof(float));
}
Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
}
}
[Test]
public void FixedList64Float_GenericHasExpectedCapacity()
{
var list = new FixedList64Bytes