public void FixedListFloat32HasExpectedCapacity() { var list = new FixedListFloat32(); var expectedCapacity = 7; for (int i = 0; i < expectedCapacity; ++i) { list.Add((float)i); } Assert.Throws <IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); }); }
public void FixedListFloat32RemoveRange() { var list = new FixedListFloat32(); 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]); } }
public void FixedListFloat32InsertRange() { var list = new FixedListFloat32(); 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]); } }
public ExchangeRecipeBufferElement(ExchangeItem[] sourceItems, ExchangeItem[] resultItems, float timeRequired = 0, bool isCrafting = false) { FixedList128 <FixedString32> sourceResourcesNames = new FixedList128 <FixedString32>(); FixedListFloat32 sourceResourcesMultipliers = new FixedListFloat32(); FixedList128 <FixedString32> resultResourcesNames = new FixedList128 <FixedString32>(); FixedListFloat32 resultResourcesMultipliers = new FixedListFloat32(); for (int i = 0; i < sourceItems.Length; i++) { sourceResourcesNames.Add(sourceItems[i].ResourceName); sourceResourcesMultipliers.Add(sourceItems[i].Multiplier); } for (int i = 0; i < resultItems.Length; i++) { resultResourcesNames.Add(resultItems[i].ResourceName); resultResourcesMultipliers.Add(resultItems[i].Multiplier); } SourceResourcesNames = sourceResourcesNames; SourceResourcesMultipliers = sourceResourcesMultipliers; ResultResourcesNames = resultResourcesNames; ResultResourcesMultipliers = resultResourcesMultipliers; Hash = SourceResourcesNames.GetHashCode() + SourceResourcesMultipliers.GetHashCode() + ResultResourcesNames.GetHashCode() + ResultResourcesMultipliers.GetHashCode(); IsCrafting = isCrafting; }
public void FixedListFloat32Sort() { var list = new FixedListFloat32(); 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]); } }
public void FixedListFloat32ToFixedListFloat128() { var a = new FixedListFloat32(); for (var i = 0; i < 7; ++i) { a.Add((float)i); } var b = new FixedListFloat128(a); for (var i = 0; i < 7; ++i) { Assert.AreEqual((float)i, b[i]); } }
public void FixedListFloat32HasExpectedLayout() { var actual = new FixedListFloat32(); 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 + sizeof(float) * i, &s, sizeof(float)); } Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32)); } }