暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FixedListTests.gen.cs 87KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981
  1. 
  2. //------------------------------------------------------------------------------
  3. // <auto-generated>
  4. // This code was generated by a tool.
  5. //
  6. // TextTransform Samples/Packages/com.unity.collections/Unity.Collections.Tests/FixedListTests.tt
  7. //
  8. // Changes to this file may cause incorrect behavior and will be lost if
  9. // the code is regenerated.
  10. // </auto-generated>
  11. //------------------------------------------------------------------------------
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Globalization;
  15. using System.Threading;
  16. using NUnit.Framework;
  17. using Unity.Collections;
  18. using Unity.Collections.LowLevel.Unsafe;
  19. using Unity.Collections.Tests;
  20. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  21. using UnityEngine;
  22. #endif
  23. internal class FixedListTests : CollectionsTestFixture
  24. {
  25. struct NonComparableStruct
  26. {
  27. public int a;
  28. }
  29. struct DescendingComparer<T> : IComparer<T> where T : IComparable<T>
  30. {
  31. public int Compare(T x, T y) => y.CompareTo(x);
  32. }
  33. [Test]
  34. [IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
  35. public void FixedList32BytesDebugView()
  36. {
  37. var list = new FixedList32Bytes<NonComparableStruct>();
  38. CollectionAssert.IsEmpty(new FixedList32BytesDebugView<NonComparableStruct>(list).Items);
  39. var reference = new []
  40. {
  41. new NonComparableStruct{ a = 123 },
  42. new NonComparableStruct{ a = 234 },
  43. new NonComparableStruct{ a = 345 },
  44. };
  45. list.Add(reference[0]);
  46. list.Add(reference[1]);
  47. list.Add(reference[2]);
  48. CollectionAssert.AreEqual(reference, new FixedList32BytesDebugView<NonComparableStruct>(list).Items);
  49. }
  50. [Test]
  51. [IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
  52. public void FixedList64BytesDebugView()
  53. {
  54. var list = new FixedList64Bytes<NonComparableStruct>();
  55. CollectionAssert.IsEmpty(new FixedList64BytesDebugView<NonComparableStruct>(list).Items);
  56. var reference = new []
  57. {
  58. new NonComparableStruct{ a = 123 },
  59. new NonComparableStruct{ a = 234 },
  60. new NonComparableStruct{ a = 345 },
  61. };
  62. list.Add(reference[0]);
  63. list.Add(reference[1]);
  64. list.Add(reference[2]);
  65. CollectionAssert.AreEqual(reference, new FixedList64BytesDebugView<NonComparableStruct>(list).Items);
  66. }
  67. [Test]
  68. [IgnoreInPortableTests("Crashes in IL2CPP on unsupported feature.")]
  69. public void FixedList128BytesDebugView()
  70. {
  71. var list = new FixedList128Bytes<NonComparableStruct>();
  72. CollectionAssert.IsEmpty(new FixedList128BytesDebugView<NonComparableStruct>(list).Items);
  73. var reference = new []
  74. {
  75. new NonComparableStruct{ a = 123 },
  76. new NonComparableStruct{ a = 234 },
  77. new NonComparableStruct{ a = 345 },
  78. };
  79. list.Add(reference[0]);
  80. list.Add(reference[1]);
  81. list.Add(reference[2]);
  82. CollectionAssert.AreEqual(reference, new FixedList128BytesDebugView<NonComparableStruct>(list).Items);
  83. }
  84. [Test]
  85. public void FixedList32Byte_FixedBytes30ToNativeArrayWorksGeneric()
  86. {
  87. var list = new FixedList<byte,FixedBytes30>();
  88. for(var i = 0; i < 30; ++i)
  89. list.Add((byte)(i * 123 + 234));
  90. using(var array = list.ToNativeArray(Allocator.Temp))
  91. {
  92. for(var i = 0; i < 30; ++i)
  93. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  94. }
  95. }
  96. [Test]
  97. public void FixedList32Byte_ToNativeArrayWorks()
  98. {
  99. var list = new FixedList32Bytes<byte>();
  100. for(var i = 0; i < 30; ++i)
  101. list.Add((byte)(i * 123 + 234));
  102. using(var array = list.ToNativeArray(Allocator.Temp))
  103. {
  104. for(var i = 0; i < 30; ++i)
  105. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  106. }
  107. }
  108. [Test]
  109. public void FixedList32Byte_GenericHasExpectedLayout()
  110. {
  111. var actual = new FixedList32Bytes<byte>();
  112. for(var i = 0; i < 30; ++i)
  113. actual.Add((byte)i);
  114. unsafe
  115. {
  116. var e = stackalloc byte[32];
  117. e[0] = (byte)((30 >> 0) & 0xFF);
  118. e[1] = (byte)((30 >> 8) & 0xFF);
  119. for(var i = 0; i < 30; ++i)
  120. {
  121. var s = (byte)i;
  122. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  123. }
  124. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  125. }
  126. }
  127. [Test]
  128. public void FixedList32Byte_GenericHasExpectedCapacity()
  129. {
  130. var list = new FixedList32Bytes<byte>();
  131. var expectedCapacity = list.Capacity;
  132. for(int i = 0; i < expectedCapacity; ++i)
  133. list.Add((byte)i);
  134. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  135. }
  136. [Test]
  137. public void FixedList32Byte_GenericInsertRangeWithBeginEnd()
  138. {
  139. var list = new FixedList32Bytes<byte>() { 0, 3, 4 };
  140. list.InsertRangeWithBeginEnd(1,3);
  141. list[1] = 1;
  142. list[2] = 2;
  143. for(var i = 0; i < 5; ++i)
  144. Assert.AreEqual(i, list[i]);
  145. }
  146. [Test]
  147. public void FixedList32Byte_GenericRemoveRange()
  148. {
  149. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  150. list.RemoveRange(1, 2);
  151. for(var i = 0; i < 3; ++i)
  152. Assert.AreEqual(i, list[i]);
  153. }
  154. [Test]
  155. public void FixedList32Byte_GenericInsert()
  156. {
  157. var list = new FixedList32Bytes<byte>() { 0, 3, 4 };
  158. list.Insert(1,1);
  159. list.Insert(2,2);
  160. for(var i = 0; i < 5; ++i)
  161. Assert.AreEqual(i, list[i]);
  162. }
  163. [Test]
  164. public void FixedList32Byte_GenericRemoveAt()
  165. {
  166. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  167. list.RemoveAt(1);
  168. list.RemoveAt(1);
  169. for(var i = 0; i < 3; ++i)
  170. Assert.AreEqual(i, list[i]);
  171. }
  172. [Test]
  173. public void FixedList32Byte_GenericRemove()
  174. {
  175. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  176. Assert.True(list.Remove((byte)3));
  177. Assert.True(list.Remove((byte)3));
  178. for(var i = 0; i < 3; ++i)
  179. Assert.AreEqual(i, list[i]);
  180. }
  181. [Test]
  182. public void FixedList32Byte_GenericRemoveSwapBack()
  183. {
  184. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 2, 1 };
  185. Assert.True(list.RemoveSwapBack((byte)3));
  186. Assert.True(list.RemoveSwapBack((byte)3));
  187. for(var i = 0; i < 3; ++i)
  188. Assert.AreEqual(i, list[i]);
  189. }
  190. [Test]
  191. public void FixedList32Byte_GenericSort()
  192. {
  193. var list = new FixedList32Bytes<byte>();
  194. for(var i = 0; i < 5; ++i)
  195. list.Add((byte)(4-i));
  196. list.Sort();
  197. for(var i = 0; i < 5; ++i)
  198. Assert.AreEqual(i, list[i]);
  199. }
  200. [Test]
  201. public void FixedList32Byte_GenericSortCustomComparer()
  202. {
  203. var list = new FixedList32Bytes<byte>();
  204. for(var i = 0; i < 5; ++i)
  205. list.Add((byte)(i));
  206. list.Sort(new DescendingComparer<byte>());
  207. for(var i = 0; i < 5; ++i)
  208. Assert.AreEqual(4-i, list[i]);
  209. }
  210. [Test]
  211. public unsafe void FixedList32Byte_IndexOf()
  212. {
  213. var list = new FixedList32Bytes<byte>() { 123, 178 };
  214. bool r0 = false, r1 = false, r2 = false;
  215. GCAllocRecorder.ValidateNoGCAllocs(() =>
  216. {
  217. r0 = -1 != list.IndexOf((byte)145);
  218. r1 = list.Contains((byte)123);
  219. r2 = list.Contains((byte)178);
  220. });
  221. Assert.False(r0);
  222. Assert.True(r1);
  223. Assert.True(r2);
  224. }
  225. [Test]
  226. public void FixedList64Byte_FixedBytes62ToNativeArrayWorksGeneric()
  227. {
  228. var list = new FixedList<byte,FixedBytes62>();
  229. for(var i = 0; i < 62; ++i)
  230. list.Add((byte)(i * 123 + 234));
  231. using(var array = list.ToNativeArray(Allocator.Temp))
  232. {
  233. for(var i = 0; i < 62; ++i)
  234. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  235. }
  236. }
  237. [Test]
  238. public void FixedList64Byte_ToNativeArrayWorks()
  239. {
  240. var list = new FixedList64Bytes<byte>();
  241. for(var i = 0; i < 62; ++i)
  242. list.Add((byte)(i * 123 + 234));
  243. using(var array = list.ToNativeArray(Allocator.Temp))
  244. {
  245. for(var i = 0; i < 62; ++i)
  246. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  247. }
  248. }
  249. [Test]
  250. public void FixedList64Byte_GenericHasExpectedLayout()
  251. {
  252. var actual = new FixedList64Bytes<byte>();
  253. for(var i = 0; i < 62; ++i)
  254. actual.Add((byte)i);
  255. unsafe
  256. {
  257. var e = stackalloc byte[64];
  258. e[0] = (byte)((62 >> 0) & 0xFF);
  259. e[1] = (byte)((62 >> 8) & 0xFF);
  260. for(var i = 0; i < 62; ++i)
  261. {
  262. var s = (byte)i;
  263. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  264. }
  265. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  266. }
  267. }
  268. [Test]
  269. public void FixedList64Byte_GenericHasExpectedCapacity()
  270. {
  271. var list = new FixedList64Bytes<byte>();
  272. var expectedCapacity = list.Capacity;
  273. for(int i = 0; i < expectedCapacity; ++i)
  274. list.Add((byte)i);
  275. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  276. }
  277. [Test]
  278. public void FixedList64Byte_GenericInsertRangeWithBeginEnd()
  279. {
  280. var list = new FixedList64Bytes<byte>() { 0, 3, 4 };
  281. list.InsertRangeWithBeginEnd(1,3);
  282. list[1] = 1;
  283. list[2] = 2;
  284. for(var i = 0; i < 5; ++i)
  285. Assert.AreEqual(i, list[i]);
  286. }
  287. [Test]
  288. public void FixedList64Byte_GenericRemoveRange()
  289. {
  290. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  291. list.RemoveRange(1, 2);
  292. for(var i = 0; i < 3; ++i)
  293. Assert.AreEqual(i, list[i]);
  294. }
  295. [Test]
  296. public void FixedList64Byte_GenericInsert()
  297. {
  298. var list = new FixedList64Bytes<byte>() { 0, 3, 4 };
  299. list.Insert(1,1);
  300. list.Insert(2,2);
  301. for(var i = 0; i < 5; ++i)
  302. Assert.AreEqual(i, list[i]);
  303. }
  304. [Test]
  305. public void FixedList64Byte_GenericRemoveAt()
  306. {
  307. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  308. list.RemoveAt(1);
  309. list.RemoveAt(1);
  310. for(var i = 0; i < 3; ++i)
  311. Assert.AreEqual(i, list[i]);
  312. }
  313. [Test]
  314. public void FixedList64Byte_GenericRemove()
  315. {
  316. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  317. Assert.True(list.Remove((byte)3));
  318. Assert.True(list.Remove((byte)3));
  319. for(var i = 0; i < 3; ++i)
  320. Assert.AreEqual(i, list[i]);
  321. }
  322. [Test]
  323. public void FixedList64Byte_GenericRemoveSwapBack()
  324. {
  325. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 2, 1 };
  326. Assert.True(list.RemoveSwapBack((byte)3));
  327. Assert.True(list.RemoveSwapBack((byte)3));
  328. for(var i = 0; i < 3; ++i)
  329. Assert.AreEqual(i, list[i]);
  330. }
  331. [Test]
  332. public void FixedList64Byte_GenericSort()
  333. {
  334. var list = new FixedList64Bytes<byte>();
  335. for(var i = 0; i < 5; ++i)
  336. list.Add((byte)(4-i));
  337. list.Sort();
  338. for(var i = 0; i < 5; ++i)
  339. Assert.AreEqual(i, list[i]);
  340. }
  341. [Test]
  342. public void FixedList64Byte_GenericSortCustomComparer()
  343. {
  344. var list = new FixedList64Bytes<byte>();
  345. for(var i = 0; i < 5; ++i)
  346. list.Add((byte)(i));
  347. list.Sort(new DescendingComparer<byte>());
  348. for(var i = 0; i < 5; ++i)
  349. Assert.AreEqual(4-i, list[i]);
  350. }
  351. [Test]
  352. public unsafe void FixedList64Byte_IndexOf()
  353. {
  354. var list = new FixedList64Bytes<byte>() { 123, 178 };
  355. bool r0 = false, r1 = false, r2 = false;
  356. GCAllocRecorder.ValidateNoGCAllocs(() =>
  357. {
  358. r0 = -1 != list.IndexOf((byte)145);
  359. r1 = list.Contains((byte)123);
  360. r2 = list.Contains((byte)178);
  361. });
  362. Assert.False(r0);
  363. Assert.True(r1);
  364. Assert.True(r2);
  365. }
  366. [Test]
  367. public void FixedList128Byte_FixedBytes126ToNativeArrayWorksGeneric()
  368. {
  369. var list = new FixedList<byte,FixedBytes126>();
  370. for(var i = 0; i < 126; ++i)
  371. list.Add((byte)(i * 123 + 234));
  372. using(var array = list.ToNativeArray(Allocator.Temp))
  373. {
  374. for(var i = 0; i < 126; ++i)
  375. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  376. }
  377. }
  378. [Test]
  379. public void FixedList128Byte_ToNativeArrayWorks()
  380. {
  381. var list = new FixedList128Bytes<byte>();
  382. for(var i = 0; i < 126; ++i)
  383. list.Add((byte)(i * 123 + 234));
  384. using(var array = list.ToNativeArray(Allocator.Temp))
  385. {
  386. for(var i = 0; i < 126; ++i)
  387. Assert.AreEqual((byte)(i * 123 + 234), array[i]);
  388. }
  389. }
  390. [Test]
  391. public void FixedList128Byte_GenericHasExpectedLayout()
  392. {
  393. var actual = new FixedList128Bytes<byte>();
  394. for(var i = 0; i < 126; ++i)
  395. actual.Add((byte)i);
  396. unsafe
  397. {
  398. var e = stackalloc byte[128];
  399. e[0] = (byte)((126 >> 0) & 0xFF);
  400. e[1] = (byte)((126 >> 8) & 0xFF);
  401. for(var i = 0; i < 126; ++i)
  402. {
  403. var s = (byte)i;
  404. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  405. }
  406. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  407. }
  408. }
  409. [Test]
  410. public void FixedList128Byte_GenericHasExpectedCapacity()
  411. {
  412. var list = new FixedList128Bytes<byte>();
  413. var expectedCapacity = list.Capacity;
  414. for(int i = 0; i < expectedCapacity; ++i)
  415. list.Add((byte)i);
  416. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  417. }
  418. [Test]
  419. public void FixedList128Byte_GenericInsertRangeWithBeginEnd()
  420. {
  421. var list = new FixedList128Bytes<byte>() { 0, 3, 4 };
  422. list.InsertRangeWithBeginEnd(1,3);
  423. list[1] = 1;
  424. list[2] = 2;
  425. for(var i = 0; i < 5; ++i)
  426. Assert.AreEqual(i, list[i]);
  427. }
  428. [Test]
  429. public void FixedList128Byte_GenericRemoveRange()
  430. {
  431. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  432. list.RemoveRange(1, 2);
  433. for(var i = 0; i < 3; ++i)
  434. Assert.AreEqual(i, list[i]);
  435. }
  436. [Test]
  437. public void FixedList128Byte_GenericInsert()
  438. {
  439. var list = new FixedList128Bytes<byte>() { 0, 3, 4 };
  440. list.Insert(1,1);
  441. list.Insert(2,2);
  442. for(var i = 0; i < 5; ++i)
  443. Assert.AreEqual(i, list[i]);
  444. }
  445. [Test]
  446. public void FixedList128Byte_GenericRemoveAt()
  447. {
  448. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  449. list.RemoveAt(1);
  450. list.RemoveAt(1);
  451. for(var i = 0; i < 3; ++i)
  452. Assert.AreEqual(i, list[i]);
  453. }
  454. [Test]
  455. public void FixedList128Byte_GenericRemove()
  456. {
  457. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  458. Assert.True(list.Remove((byte)3));
  459. Assert.True(list.Remove((byte)3));
  460. for(var i = 0; i < 3; ++i)
  461. Assert.AreEqual(i, list[i]);
  462. }
  463. [Test]
  464. public void FixedList128Byte_GenericRemoveSwapBack()
  465. {
  466. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 2, 1 };
  467. Assert.True(list.RemoveSwapBack((byte)3));
  468. Assert.True(list.RemoveSwapBack((byte)3));
  469. for(var i = 0; i < 3; ++i)
  470. Assert.AreEqual(i, list[i]);
  471. }
  472. [Test]
  473. public void FixedList128Byte_GenericSort()
  474. {
  475. var list = new FixedList128Bytes<byte>();
  476. for(var i = 0; i < 5; ++i)
  477. list.Add((byte)(4-i));
  478. list.Sort();
  479. for(var i = 0; i < 5; ++i)
  480. Assert.AreEqual(i, list[i]);
  481. }
  482. [Test]
  483. public void FixedList128Byte_GenericSortCustomComparer()
  484. {
  485. var list = new FixedList128Bytes<byte>();
  486. for(var i = 0; i < 5; ++i)
  487. list.Add((byte)(i));
  488. list.Sort(new DescendingComparer<byte>());
  489. for(var i = 0; i < 5; ++i)
  490. Assert.AreEqual(4-i, list[i]);
  491. }
  492. [Test]
  493. public unsafe void FixedList128Byte_IndexOf()
  494. {
  495. var list = new FixedList128Bytes<byte>() { 123, 178 };
  496. bool r0 = false, r1 = false, r2 = false;
  497. GCAllocRecorder.ValidateNoGCAllocs(() =>
  498. {
  499. r0 = -1 != list.IndexOf((byte)145);
  500. r1 = list.Contains((byte)123);
  501. r2 = list.Contains((byte)178);
  502. });
  503. Assert.False(r0);
  504. Assert.True(r1);
  505. Assert.True(r2);
  506. }
  507. [Test]
  508. public void FixedList32Byte_HasExpectedLayout()
  509. {
  510. var actual = new FixedList32Bytes<byte>();
  511. for(var i = 0; i < 30; ++i)
  512. actual.Add((byte)i);
  513. unsafe
  514. {
  515. var e = stackalloc byte[32];
  516. e[0] = (byte)((30 >> 0) & 0xFF);
  517. e[1] = (byte)((30 >> 8) & 0xFF);
  518. for(var i = 0; i < 30; ++i)
  519. {
  520. var s = (byte)i;
  521. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  522. }
  523. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  524. }
  525. }
  526. [Test]
  527. public void FixedList32Byte_HasExpectedCapacity()
  528. {
  529. var list = new FixedList32Bytes<byte>();
  530. var expectedCapacity = list.Capacity;
  531. for(int i = 0; i < expectedCapacity; ++i)
  532. list.Add((byte)i);
  533. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  534. }
  535. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  536. class ScriptableObjectFixedList32Byte_ : UnityEngine.ScriptableObject
  537. {
  538. public FixedList32Bytes<byte> List;
  539. }
  540. [Test]
  541. public void FixedList32Byte_Serializes()
  542. {
  543. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList32Byte_ >();
  544. for(int i = 0; i < a.List.Capacity; ++i)
  545. a.List.Add((byte)i);
  546. var b = UnityEngine.Object.Instantiate(a);
  547. CollectionAssert.AreEqual(a.List, b.List);
  548. }
  549. #endif
  550. [Test]
  551. public void FixedList32Byte_InsertRangeWithBeginEnd()
  552. {
  553. var list = new FixedList32Bytes<byte>() { 0, 3, 4 };
  554. list.InsertRangeWithBeginEnd(1,3);
  555. list[1] = 1;
  556. list[2] = 2;
  557. for(var i = 0; i < 5; ++i)
  558. Assert.AreEqual(i, list[i]);
  559. }
  560. private static void Expected(ref FixedList32Bytes<byte> container, int expectedLength, int[] expected)
  561. {
  562. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  563. Assert.AreEqual(container.Length, expectedLength);
  564. for (var i = 0; i < container.Length; ++i)
  565. {
  566. Assert.AreEqual(expected[i], container[i]);
  567. }
  568. }
  569. [Test]
  570. public void FixedList32Byte_RemoveAt()
  571. {
  572. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  573. list.RemoveAt(1);
  574. list.RemoveAt(1);
  575. Expected(ref list, 3, new int[] { 0, 1, 2 });
  576. }
  577. [Test]
  578. public void FixedList32Byte_Remove()
  579. {
  580. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  581. Assert.True(list.Remove((byte)3));
  582. Assert.True(list.Remove((byte)3));
  583. Expected(ref list, 3, new int[] { 0, 1, 2 });
  584. }
  585. [Test]
  586. public void FixedList32Byte_RemoveSwapBack()
  587. {
  588. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 2, 1 };
  589. Assert.True(list.RemoveSwapBack((byte)3));
  590. Assert.True(list.RemoveSwapBack((byte)3));
  591. Expected(ref list, 3, new int[] { 0, 1, 2 });
  592. }
  593. [Test]
  594. public void FixedList32Byte_RemoveRange()
  595. {
  596. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  597. list.RemoveRange(1, 2);
  598. Expected(ref list, 3, new int[] { 0, 1, 2 });
  599. }
  600. [Test]
  601. public void FixedList32Byte_RemoveAtSwapBack()
  602. {
  603. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  604. list.RemoveAtSwapBack(1);
  605. list.RemoveAtSwapBack(1);
  606. Expected(ref list, 3, new int[] { 0, 1, 3 });
  607. }
  608. [Test]
  609. public void FixedList32Byte_RemoveRangeSwapBack()
  610. {
  611. var list = new FixedList32Bytes<byte>() { 0, 3, 3, 1, 2 };
  612. list.RemoveRangeSwapBack(1, 2);
  613. Expected(ref list, 3, new int[] { 0, 1, 2 });
  614. }
  615. [Test]
  616. public void FixedList32Byte_Insert()
  617. {
  618. var list = new FixedList32Bytes<byte>() { 0, 3, 4 };
  619. list.Insert(1,1);
  620. list.Insert(2,2);
  621. for(var i = 0; i < 5; ++i)
  622. Assert.AreEqual(i, list[i]);
  623. }
  624. [Test]
  625. public void FixedList32Byte_Sort()
  626. {
  627. var list = new FixedList32Bytes<byte>();
  628. for(var i = 0; i < 5; ++i)
  629. list.Add((byte)(4-i));
  630. list.Sort();
  631. for(var i = 0; i < 5; ++i)
  632. Assert.AreEqual(i, list[i]);
  633. }
  634. [Test]
  635. public void FixedList32Byte_To_FixedList64Byte()
  636. {
  637. var a = new FixedList32Bytes<byte>();
  638. for(var i = 0; i < 30; ++i)
  639. a.Add((byte)i);
  640. var b = new FixedList64Bytes<byte>(a);
  641. for(var i = 0; i < 30; ++i)
  642. Assert.AreEqual((byte)i, b[i]);
  643. }
  644. [Test]
  645. public void FixedList32Byte_To_FixedList128Byte()
  646. {
  647. var a = new FixedList32Bytes<byte>();
  648. for(var i = 0; i < 30; ++i)
  649. a.Add((byte)i);
  650. var b = new FixedList128Bytes<byte>(a);
  651. for(var i = 0; i < 30; ++i)
  652. Assert.AreEqual((byte)i, b[i]);
  653. }
  654. [Test]
  655. public void FixedList64Byte_HasExpectedLayout()
  656. {
  657. var actual = new FixedList64Bytes<byte>();
  658. for(var i = 0; i < 62; ++i)
  659. actual.Add((byte)i);
  660. unsafe
  661. {
  662. var e = stackalloc byte[64];
  663. e[0] = (byte)((62 >> 0) & 0xFF);
  664. e[1] = (byte)((62 >> 8) & 0xFF);
  665. for(var i = 0; i < 62; ++i)
  666. {
  667. var s = (byte)i;
  668. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  669. }
  670. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  671. }
  672. }
  673. [Test]
  674. public void FixedList64Byte_HasExpectedCapacity()
  675. {
  676. var list = new FixedList64Bytes<byte>();
  677. var expectedCapacity = list.Capacity;
  678. for(int i = 0; i < expectedCapacity; ++i)
  679. list.Add((byte)i);
  680. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  681. }
  682. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  683. class ScriptableObjectFixedList64Byte_ : UnityEngine.ScriptableObject
  684. {
  685. public FixedList64Bytes<byte> List;
  686. }
  687. [Test]
  688. public void FixedList64Byte_Serializes()
  689. {
  690. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList64Byte_ >();
  691. for(int i = 0; i < a.List.Capacity; ++i)
  692. a.List.Add((byte)i);
  693. var b = UnityEngine.Object.Instantiate(a);
  694. CollectionAssert.AreEqual(a.List, b.List);
  695. }
  696. #endif
  697. [Test]
  698. public void FixedList64Byte_InsertRangeWithBeginEnd()
  699. {
  700. var list = new FixedList64Bytes<byte>() { 0, 3, 4 };
  701. list.InsertRangeWithBeginEnd(1,3);
  702. list[1] = 1;
  703. list[2] = 2;
  704. for(var i = 0; i < 5; ++i)
  705. Assert.AreEqual(i, list[i]);
  706. }
  707. private static void Expected(ref FixedList64Bytes<byte> container, int expectedLength, int[] expected)
  708. {
  709. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  710. Assert.AreEqual(container.Length, expectedLength);
  711. for (var i = 0; i < container.Length; ++i)
  712. {
  713. Assert.AreEqual(expected[i], container[i]);
  714. }
  715. }
  716. [Test]
  717. public void FixedList64Byte_RemoveAt()
  718. {
  719. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  720. list.RemoveAt(1);
  721. list.RemoveAt(1);
  722. Expected(ref list, 3, new int[] { 0, 1, 2 });
  723. }
  724. [Test]
  725. public void FixedList64Byte_Remove()
  726. {
  727. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  728. Assert.True(list.Remove((byte)3));
  729. Assert.True(list.Remove((byte)3));
  730. Expected(ref list, 3, new int[] { 0, 1, 2 });
  731. }
  732. [Test]
  733. public void FixedList64Byte_RemoveSwapBack()
  734. {
  735. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 2, 1 };
  736. Assert.True(list.RemoveSwapBack((byte)3));
  737. Assert.True(list.RemoveSwapBack((byte)3));
  738. Expected(ref list, 3, new int[] { 0, 1, 2 });
  739. }
  740. [Test]
  741. public void FixedList64Byte_RemoveRange()
  742. {
  743. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  744. list.RemoveRange(1, 2);
  745. Expected(ref list, 3, new int[] { 0, 1, 2 });
  746. }
  747. [Test]
  748. public void FixedList64Byte_RemoveAtSwapBack()
  749. {
  750. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  751. list.RemoveAtSwapBack(1);
  752. list.RemoveAtSwapBack(1);
  753. Expected(ref list, 3, new int[] { 0, 1, 3 });
  754. }
  755. [Test]
  756. public void FixedList64Byte_RemoveRangeSwapBack()
  757. {
  758. var list = new FixedList64Bytes<byte>() { 0, 3, 3, 1, 2 };
  759. list.RemoveRangeSwapBack(1, 2);
  760. Expected(ref list, 3, new int[] { 0, 1, 2 });
  761. }
  762. [Test]
  763. public void FixedList64Byte_Insert()
  764. {
  765. var list = new FixedList64Bytes<byte>() { 0, 3, 4 };
  766. list.Insert(1,1);
  767. list.Insert(2,2);
  768. for(var i = 0; i < 5; ++i)
  769. Assert.AreEqual(i, list[i]);
  770. }
  771. [Test]
  772. public void FixedList64Byte_Sort()
  773. {
  774. var list = new FixedList64Bytes<byte>();
  775. for(var i = 0; i < 5; ++i)
  776. list.Add((byte)(4-i));
  777. list.Sort();
  778. for(var i = 0; i < 5; ++i)
  779. Assert.AreEqual(i, list[i]);
  780. }
  781. [Test]
  782. public void FixedList64Byte_To_FixedList32Byte()
  783. {
  784. var a = new FixedList64Bytes<byte>();
  785. for(var i = 0; i < 62; ++i)
  786. a.Add((byte)i);
  787. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<byte>(a); } );
  788. }
  789. [Test]
  790. public void FixedList64Byte_To_FixedList128Byte()
  791. {
  792. var a = new FixedList64Bytes<byte>();
  793. for(var i = 0; i < 62; ++i)
  794. a.Add((byte)i);
  795. var b = new FixedList128Bytes<byte>(a);
  796. for(var i = 0; i < 62; ++i)
  797. Assert.AreEqual((byte)i, b[i]);
  798. }
  799. [Test]
  800. public void FixedList128Byte_HasExpectedLayout()
  801. {
  802. var actual = new FixedList128Bytes<byte>();
  803. for(var i = 0; i < 126; ++i)
  804. actual.Add((byte)i);
  805. unsafe
  806. {
  807. var e = stackalloc byte[128];
  808. e[0] = (byte)((126 >> 0) & 0xFF);
  809. e[1] = (byte)((126 >> 8) & 0xFF);
  810. for(var i = 0; i < 126; ++i)
  811. {
  812. var s = (byte)i;
  813. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<byte>() + sizeof(byte) * i, &s, sizeof(byte));
  814. }
  815. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  816. }
  817. }
  818. [Test]
  819. public void FixedList128Byte_HasExpectedCapacity()
  820. {
  821. var list = new FixedList128Bytes<byte>();
  822. var expectedCapacity = list.Capacity;
  823. for(int i = 0; i < expectedCapacity; ++i)
  824. list.Add((byte)i);
  825. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((byte)expectedCapacity); });
  826. }
  827. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  828. class ScriptableObjectFixedList128Byte_ : UnityEngine.ScriptableObject
  829. {
  830. public FixedList128Bytes<byte> List;
  831. }
  832. [Test]
  833. public void FixedList128Byte_Serializes()
  834. {
  835. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList128Byte_ >();
  836. for(int i = 0; i < a.List.Capacity; ++i)
  837. a.List.Add((byte)i);
  838. var b = UnityEngine.Object.Instantiate(a);
  839. CollectionAssert.AreEqual(a.List, b.List);
  840. }
  841. #endif
  842. [Test]
  843. public void FixedList128Byte_InsertRangeWithBeginEnd()
  844. {
  845. var list = new FixedList128Bytes<byte>() { 0, 3, 4 };
  846. list.InsertRangeWithBeginEnd(1,3);
  847. list[1] = 1;
  848. list[2] = 2;
  849. for(var i = 0; i < 5; ++i)
  850. Assert.AreEqual(i, list[i]);
  851. }
  852. private static void Expected(ref FixedList128Bytes<byte> container, int expectedLength, int[] expected)
  853. {
  854. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  855. Assert.AreEqual(container.Length, expectedLength);
  856. for (var i = 0; i < container.Length; ++i)
  857. {
  858. Assert.AreEqual(expected[i], container[i]);
  859. }
  860. }
  861. [Test]
  862. public void FixedList128Byte_RemoveAt()
  863. {
  864. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  865. list.RemoveAt(1);
  866. list.RemoveAt(1);
  867. Expected(ref list, 3, new int[] { 0, 1, 2 });
  868. }
  869. [Test]
  870. public void FixedList128Byte_Remove()
  871. {
  872. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  873. Assert.True(list.Remove((byte)3));
  874. Assert.True(list.Remove((byte)3));
  875. Expected(ref list, 3, new int[] { 0, 1, 2 });
  876. }
  877. [Test]
  878. public void FixedList128Byte_RemoveSwapBack()
  879. {
  880. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 2, 1 };
  881. Assert.True(list.RemoveSwapBack((byte)3));
  882. Assert.True(list.RemoveSwapBack((byte)3));
  883. Expected(ref list, 3, new int[] { 0, 1, 2 });
  884. }
  885. [Test]
  886. public void FixedList128Byte_RemoveRange()
  887. {
  888. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  889. list.RemoveRange(1, 2);
  890. Expected(ref list, 3, new int[] { 0, 1, 2 });
  891. }
  892. [Test]
  893. public void FixedList128Byte_RemoveAtSwapBack()
  894. {
  895. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  896. list.RemoveAtSwapBack(1);
  897. list.RemoveAtSwapBack(1);
  898. Expected(ref list, 3, new int[] { 0, 1, 3 });
  899. }
  900. [Test]
  901. public void FixedList128Byte_RemoveRangeSwapBack()
  902. {
  903. var list = new FixedList128Bytes<byte>() { 0, 3, 3, 1, 2 };
  904. list.RemoveRangeSwapBack(1, 2);
  905. Expected(ref list, 3, new int[] { 0, 1, 2 });
  906. }
  907. [Test]
  908. public void FixedList128Byte_Insert()
  909. {
  910. var list = new FixedList128Bytes<byte>() { 0, 3, 4 };
  911. list.Insert(1,1);
  912. list.Insert(2,2);
  913. for(var i = 0; i < 5; ++i)
  914. Assert.AreEqual(i, list[i]);
  915. }
  916. [Test]
  917. public void FixedList128Byte_Sort()
  918. {
  919. var list = new FixedList128Bytes<byte>();
  920. for(var i = 0; i < 5; ++i)
  921. list.Add((byte)(4-i));
  922. list.Sort();
  923. for(var i = 0; i < 5; ++i)
  924. Assert.AreEqual(i, list[i]);
  925. }
  926. [Test]
  927. public void FixedList128Byte_To_FixedList32Byte()
  928. {
  929. var a = new FixedList128Bytes<byte>();
  930. for(var i = 0; i < 126; ++i)
  931. a.Add((byte)i);
  932. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<byte>(a); } );
  933. }
  934. [Test]
  935. public void FixedList128Byte_To_FixedList64Byte()
  936. {
  937. var a = new FixedList128Bytes<byte>();
  938. for(var i = 0; i < 126; ++i)
  939. a.Add((byte)i);
  940. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList64Bytes<byte>(a); } );
  941. }
  942. [Test]
  943. public void FixedList32Int_FixedBytes30ToNativeArrayWorksGeneric()
  944. {
  945. var list = new FixedList<int,FixedBytes30>();
  946. for(var i = 0; i < 7; ++i)
  947. list.Add((int)(i * 123 + 234));
  948. using(var array = list.ToNativeArray(Allocator.Temp))
  949. {
  950. for(var i = 0; i < 7; ++i)
  951. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  952. }
  953. }
  954. [Test]
  955. public void FixedList32Int_ToNativeArrayWorks()
  956. {
  957. var list = new FixedList32Bytes<int>();
  958. for(var i = 0; i < 7; ++i)
  959. list.Add((int)(i * 123 + 234));
  960. using(var array = list.ToNativeArray(Allocator.Temp))
  961. {
  962. for(var i = 0; i < 7; ++i)
  963. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  964. }
  965. }
  966. [Test]
  967. public void FixedList32Int_GenericHasExpectedLayout()
  968. {
  969. var actual = new FixedList32Bytes<int>();
  970. for(var i = 0; i < 7; ++i)
  971. actual.Add((int)i);
  972. unsafe
  973. {
  974. var e = stackalloc byte[32];
  975. e[0] = (byte)((7 >> 0) & 0xFF);
  976. e[1] = (byte)((7 >> 8) & 0xFF);
  977. for(var i = 0; i < 7; ++i)
  978. {
  979. var s = (int)i;
  980. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  981. }
  982. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  983. }
  984. }
  985. [Test]
  986. public void FixedList32Int_GenericHasExpectedCapacity()
  987. {
  988. var list = new FixedList32Bytes<int>();
  989. var expectedCapacity = list.Capacity;
  990. for(int i = 0; i < expectedCapacity; ++i)
  991. list.Add((int)i);
  992. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  993. }
  994. [Test]
  995. public void FixedList32Int_GenericInsertRangeWithBeginEnd()
  996. {
  997. var list = new FixedList32Bytes<int>() { 0, 3, 4 };
  998. list.InsertRangeWithBeginEnd(1,3);
  999. list[1] = 1;
  1000. list[2] = 2;
  1001. for(var i = 0; i < 5; ++i)
  1002. Assert.AreEqual(i, list[i]);
  1003. }
  1004. [Test]
  1005. public void FixedList32Int_GenericRemoveRange()
  1006. {
  1007. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1008. list.RemoveRange(1, 2);
  1009. for(var i = 0; i < 3; ++i)
  1010. Assert.AreEqual(i, list[i]);
  1011. }
  1012. [Test]
  1013. public void FixedList32Int_GenericInsert()
  1014. {
  1015. var list = new FixedList32Bytes<int>() { 0, 3, 4 };
  1016. list.Insert(1,1);
  1017. list.Insert(2,2);
  1018. for(var i = 0; i < 5; ++i)
  1019. Assert.AreEqual(i, list[i]);
  1020. }
  1021. [Test]
  1022. public void FixedList32Int_GenericRemoveAt()
  1023. {
  1024. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1025. list.RemoveAt(1);
  1026. list.RemoveAt(1);
  1027. for(var i = 0; i < 3; ++i)
  1028. Assert.AreEqual(i, list[i]);
  1029. }
  1030. [Test]
  1031. public void FixedList32Int_GenericRemove()
  1032. {
  1033. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1034. Assert.True(list.Remove((int)3));
  1035. Assert.True(list.Remove((int)3));
  1036. for(var i = 0; i < 3; ++i)
  1037. Assert.AreEqual(i, list[i]);
  1038. }
  1039. [Test]
  1040. public void FixedList32Int_GenericRemoveSwapBack()
  1041. {
  1042. var list = new FixedList32Bytes<int>() { 0, 3, 3, 2, 1 };
  1043. Assert.True(list.RemoveSwapBack((int)3));
  1044. Assert.True(list.RemoveSwapBack((int)3));
  1045. for(var i = 0; i < 3; ++i)
  1046. Assert.AreEqual(i, list[i]);
  1047. }
  1048. [Test]
  1049. public void FixedList32Int_GenericSort()
  1050. {
  1051. var list = new FixedList32Bytes<int>();
  1052. for(var i = 0; i < 5; ++i)
  1053. list.Add((int)(4-i));
  1054. list.Sort();
  1055. for(var i = 0; i < 5; ++i)
  1056. Assert.AreEqual(i, list[i]);
  1057. }
  1058. [Test]
  1059. public void FixedList32Int_GenericSortCustomComparer()
  1060. {
  1061. var list = new FixedList32Bytes<int>();
  1062. for(var i = 0; i < 5; ++i)
  1063. list.Add((int)(i));
  1064. list.Sort(new DescendingComparer<int>());
  1065. for(var i = 0; i < 5; ++i)
  1066. Assert.AreEqual(4-i, list[i]);
  1067. }
  1068. [Test]
  1069. public unsafe void FixedList32Int_IndexOf()
  1070. {
  1071. var list = new FixedList32Bytes<int>() { 123, 178 };
  1072. bool r0 = false, r1 = false, r2 = false;
  1073. GCAllocRecorder.ValidateNoGCAllocs(() =>
  1074. {
  1075. r0 = -1 != list.IndexOf((int)145);
  1076. r1 = list.Contains((int)123);
  1077. r2 = list.Contains((int)178);
  1078. });
  1079. Assert.False(r0);
  1080. Assert.True(r1);
  1081. Assert.True(r2);
  1082. }
  1083. [Test]
  1084. public void FixedList64Int_FixedBytes62ToNativeArrayWorksGeneric()
  1085. {
  1086. var list = new FixedList<int,FixedBytes62>();
  1087. for(var i = 0; i < 15; ++i)
  1088. list.Add((int)(i * 123 + 234));
  1089. using(var array = list.ToNativeArray(Allocator.Temp))
  1090. {
  1091. for(var i = 0; i < 15; ++i)
  1092. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  1093. }
  1094. }
  1095. [Test]
  1096. public void FixedList64Int_ToNativeArrayWorks()
  1097. {
  1098. var list = new FixedList64Bytes<int>();
  1099. for(var i = 0; i < 15; ++i)
  1100. list.Add((int)(i * 123 + 234));
  1101. using(var array = list.ToNativeArray(Allocator.Temp))
  1102. {
  1103. for(var i = 0; i < 15; ++i)
  1104. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  1105. }
  1106. }
  1107. [Test]
  1108. public void FixedList64Int_GenericHasExpectedLayout()
  1109. {
  1110. var actual = new FixedList64Bytes<int>();
  1111. for(var i = 0; i < 15; ++i)
  1112. actual.Add((int)i);
  1113. unsafe
  1114. {
  1115. var e = stackalloc byte[64];
  1116. e[0] = (byte)((15 >> 0) & 0xFF);
  1117. e[1] = (byte)((15 >> 8) & 0xFF);
  1118. for(var i = 0; i < 15; ++i)
  1119. {
  1120. var s = (int)i;
  1121. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  1122. }
  1123. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  1124. }
  1125. }
  1126. [Test]
  1127. public void FixedList64Int_GenericHasExpectedCapacity()
  1128. {
  1129. var list = new FixedList64Bytes<int>();
  1130. var expectedCapacity = list.Capacity;
  1131. for(int i = 0; i < expectedCapacity; ++i)
  1132. list.Add((int)i);
  1133. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  1134. }
  1135. [Test]
  1136. public void FixedList64Int_GenericInsertRangeWithBeginEnd()
  1137. {
  1138. var list = new FixedList64Bytes<int>() { 0, 3, 4 };
  1139. list.InsertRangeWithBeginEnd(1,3);
  1140. list[1] = 1;
  1141. list[2] = 2;
  1142. for(var i = 0; i < 5; ++i)
  1143. Assert.AreEqual(i, list[i]);
  1144. }
  1145. [Test]
  1146. public void FixedList64Int_GenericRemoveRange()
  1147. {
  1148. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1149. list.RemoveRange(1, 2);
  1150. for(var i = 0; i < 3; ++i)
  1151. Assert.AreEqual(i, list[i]);
  1152. }
  1153. [Test]
  1154. public void FixedList64Int_GenericInsert()
  1155. {
  1156. var list = new FixedList64Bytes<int>() { 0, 3, 4 };
  1157. list.Insert(1,1);
  1158. list.Insert(2,2);
  1159. for(var i = 0; i < 5; ++i)
  1160. Assert.AreEqual(i, list[i]);
  1161. }
  1162. [Test]
  1163. public void FixedList64Int_GenericRemoveAt()
  1164. {
  1165. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1166. list.RemoveAt(1);
  1167. list.RemoveAt(1);
  1168. for(var i = 0; i < 3; ++i)
  1169. Assert.AreEqual(i, list[i]);
  1170. }
  1171. [Test]
  1172. public void FixedList64Int_GenericRemove()
  1173. {
  1174. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1175. Assert.True(list.Remove((int)3));
  1176. Assert.True(list.Remove((int)3));
  1177. for(var i = 0; i < 3; ++i)
  1178. Assert.AreEqual(i, list[i]);
  1179. }
  1180. [Test]
  1181. public void FixedList64Int_GenericRemoveSwapBack()
  1182. {
  1183. var list = new FixedList64Bytes<int>() { 0, 3, 3, 2, 1 };
  1184. Assert.True(list.RemoveSwapBack((int)3));
  1185. Assert.True(list.RemoveSwapBack((int)3));
  1186. for(var i = 0; i < 3; ++i)
  1187. Assert.AreEqual(i, list[i]);
  1188. }
  1189. [Test]
  1190. public void FixedList64Int_GenericSort()
  1191. {
  1192. var list = new FixedList64Bytes<int>();
  1193. for(var i = 0; i < 5; ++i)
  1194. list.Add((int)(4-i));
  1195. list.Sort();
  1196. for(var i = 0; i < 5; ++i)
  1197. Assert.AreEqual(i, list[i]);
  1198. }
  1199. [Test]
  1200. public void FixedList64Int_GenericSortCustomComparer()
  1201. {
  1202. var list = new FixedList64Bytes<int>();
  1203. for(var i = 0; i < 5; ++i)
  1204. list.Add((int)(i));
  1205. list.Sort(new DescendingComparer<int>());
  1206. for(var i = 0; i < 5; ++i)
  1207. Assert.AreEqual(4-i, list[i]);
  1208. }
  1209. [Test]
  1210. public unsafe void FixedList64Int_IndexOf()
  1211. {
  1212. var list = new FixedList64Bytes<int>() { 123, 178 };
  1213. bool r0 = false, r1 = false, r2 = false;
  1214. GCAllocRecorder.ValidateNoGCAllocs(() =>
  1215. {
  1216. r0 = -1 != list.IndexOf((int)145);
  1217. r1 = list.Contains((int)123);
  1218. r2 = list.Contains((int)178);
  1219. });
  1220. Assert.False(r0);
  1221. Assert.True(r1);
  1222. Assert.True(r2);
  1223. }
  1224. [Test]
  1225. public void FixedList128Int_FixedBytes126ToNativeArrayWorksGeneric()
  1226. {
  1227. var list = new FixedList<int,FixedBytes126>();
  1228. for(var i = 0; i < 31; ++i)
  1229. list.Add((int)(i * 123 + 234));
  1230. using(var array = list.ToNativeArray(Allocator.Temp))
  1231. {
  1232. for(var i = 0; i < 31; ++i)
  1233. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  1234. }
  1235. }
  1236. [Test]
  1237. public void FixedList128Int_ToNativeArrayWorks()
  1238. {
  1239. var list = new FixedList128Bytes<int>();
  1240. for(var i = 0; i < 31; ++i)
  1241. list.Add((int)(i * 123 + 234));
  1242. using(var array = list.ToNativeArray(Allocator.Temp))
  1243. {
  1244. for(var i = 0; i < 31; ++i)
  1245. Assert.AreEqual((int)(i * 123 + 234), array[i]);
  1246. }
  1247. }
  1248. [Test]
  1249. public void FixedList128Int_GenericHasExpectedLayout()
  1250. {
  1251. var actual = new FixedList128Bytes<int>();
  1252. for(var i = 0; i < 31; ++i)
  1253. actual.Add((int)i);
  1254. unsafe
  1255. {
  1256. var e = stackalloc byte[128];
  1257. e[0] = (byte)((31 >> 0) & 0xFF);
  1258. e[1] = (byte)((31 >> 8) & 0xFF);
  1259. for(var i = 0; i < 31; ++i)
  1260. {
  1261. var s = (int)i;
  1262. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  1263. }
  1264. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  1265. }
  1266. }
  1267. [Test]
  1268. public void FixedList128Int_GenericHasExpectedCapacity()
  1269. {
  1270. var list = new FixedList128Bytes<int>();
  1271. var expectedCapacity = list.Capacity;
  1272. for(int i = 0; i < expectedCapacity; ++i)
  1273. list.Add((int)i);
  1274. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  1275. }
  1276. [Test]
  1277. public void FixedList128Int_GenericInsertRangeWithBeginEnd()
  1278. {
  1279. var list = new FixedList128Bytes<int>() { 0, 3, 4 };
  1280. list.InsertRangeWithBeginEnd(1,3);
  1281. list[1] = 1;
  1282. list[2] = 2;
  1283. for(var i = 0; i < 5; ++i)
  1284. Assert.AreEqual(i, list[i]);
  1285. }
  1286. [Test]
  1287. public void FixedList128Int_GenericRemoveRange()
  1288. {
  1289. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1290. list.RemoveRange(1, 2);
  1291. for(var i = 0; i < 3; ++i)
  1292. Assert.AreEqual(i, list[i]);
  1293. }
  1294. [Test]
  1295. public void FixedList128Int_GenericInsert()
  1296. {
  1297. var list = new FixedList128Bytes<int>() { 0, 3, 4 };
  1298. list.Insert(1,1);
  1299. list.Insert(2,2);
  1300. for(var i = 0; i < 5; ++i)
  1301. Assert.AreEqual(i, list[i]);
  1302. }
  1303. [Test]
  1304. public void FixedList128Int_GenericRemoveAt()
  1305. {
  1306. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1307. list.RemoveAt(1);
  1308. list.RemoveAt(1);
  1309. for(var i = 0; i < 3; ++i)
  1310. Assert.AreEqual(i, list[i]);
  1311. }
  1312. [Test]
  1313. public void FixedList128Int_GenericRemove()
  1314. {
  1315. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1316. Assert.True(list.Remove((int)3));
  1317. Assert.True(list.Remove((int)3));
  1318. for(var i = 0; i < 3; ++i)
  1319. Assert.AreEqual(i, list[i]);
  1320. }
  1321. [Test]
  1322. public void FixedList128Int_GenericRemoveSwapBack()
  1323. {
  1324. var list = new FixedList128Bytes<int>() { 0, 3, 3, 2, 1 };
  1325. Assert.True(list.RemoveSwapBack((int)3));
  1326. Assert.True(list.RemoveSwapBack((int)3));
  1327. for(var i = 0; i < 3; ++i)
  1328. Assert.AreEqual(i, list[i]);
  1329. }
  1330. [Test]
  1331. public void FixedList128Int_GenericSort()
  1332. {
  1333. var list = new FixedList128Bytes<int>();
  1334. for(var i = 0; i < 5; ++i)
  1335. list.Add((int)(4-i));
  1336. list.Sort();
  1337. for(var i = 0; i < 5; ++i)
  1338. Assert.AreEqual(i, list[i]);
  1339. }
  1340. [Test]
  1341. public void FixedList128Int_GenericSortCustomComparer()
  1342. {
  1343. var list = new FixedList128Bytes<int>();
  1344. for(var i = 0; i < 5; ++i)
  1345. list.Add((int)(i));
  1346. list.Sort(new DescendingComparer<int>());
  1347. for(var i = 0; i < 5; ++i)
  1348. Assert.AreEqual(4-i, list[i]);
  1349. }
  1350. [Test]
  1351. public unsafe void FixedList128Int_IndexOf()
  1352. {
  1353. var list = new FixedList128Bytes<int>() { 123, 178 };
  1354. bool r0 = false, r1 = false, r2 = false;
  1355. GCAllocRecorder.ValidateNoGCAllocs(() =>
  1356. {
  1357. r0 = -1 != list.IndexOf((int)145);
  1358. r1 = list.Contains((int)123);
  1359. r2 = list.Contains((int)178);
  1360. });
  1361. Assert.False(r0);
  1362. Assert.True(r1);
  1363. Assert.True(r2);
  1364. }
  1365. [Test]
  1366. public void FixedList32Int_HasExpectedLayout()
  1367. {
  1368. var actual = new FixedList32Bytes<int>();
  1369. for(var i = 0; i < 7; ++i)
  1370. actual.Add((int)i);
  1371. unsafe
  1372. {
  1373. var e = stackalloc byte[32];
  1374. e[0] = (byte)((7 >> 0) & 0xFF);
  1375. e[1] = (byte)((7 >> 8) & 0xFF);
  1376. for(var i = 0; i < 7; ++i)
  1377. {
  1378. var s = (int)i;
  1379. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  1380. }
  1381. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  1382. }
  1383. }
  1384. [Test]
  1385. public void FixedList32Int_HasExpectedCapacity()
  1386. {
  1387. var list = new FixedList32Bytes<int>();
  1388. var expectedCapacity = list.Capacity;
  1389. for(int i = 0; i < expectedCapacity; ++i)
  1390. list.Add((int)i);
  1391. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  1392. }
  1393. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  1394. class ScriptableObjectFixedList32Int_ : UnityEngine.ScriptableObject
  1395. {
  1396. public FixedList32Bytes<int> List;
  1397. }
  1398. [Test]
  1399. public void FixedList32Int_Serializes()
  1400. {
  1401. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList32Int_ >();
  1402. for(int i = 0; i < a.List.Capacity; ++i)
  1403. a.List.Add((int)i);
  1404. var b = UnityEngine.Object.Instantiate(a);
  1405. CollectionAssert.AreEqual(a.List, b.List);
  1406. }
  1407. #endif
  1408. [Test]
  1409. public void FixedList32Int_InsertRangeWithBeginEnd()
  1410. {
  1411. var list = new FixedList32Bytes<int>() { 0, 3, 4 };
  1412. list.InsertRangeWithBeginEnd(1,3);
  1413. list[1] = 1;
  1414. list[2] = 2;
  1415. for(var i = 0; i < 5; ++i)
  1416. Assert.AreEqual(i, list[i]);
  1417. }
  1418. private static void Expected(ref FixedList32Bytes<int> container, int expectedLength, int[] expected)
  1419. {
  1420. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  1421. Assert.AreEqual(container.Length, expectedLength);
  1422. for (var i = 0; i < container.Length; ++i)
  1423. {
  1424. Assert.AreEqual(expected[i], container[i]);
  1425. }
  1426. }
  1427. [Test]
  1428. public void FixedList32Int_RemoveAt()
  1429. {
  1430. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1431. list.RemoveAt(1);
  1432. list.RemoveAt(1);
  1433. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1434. }
  1435. [Test]
  1436. public void FixedList32Int_Remove()
  1437. {
  1438. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1439. Assert.True(list.Remove((int)3));
  1440. Assert.True(list.Remove((int)3));
  1441. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1442. }
  1443. [Test]
  1444. public void FixedList32Int_RemoveSwapBack()
  1445. {
  1446. var list = new FixedList32Bytes<int>() { 0, 3, 3, 2, 1 };
  1447. Assert.True(list.RemoveSwapBack((int)3));
  1448. Assert.True(list.RemoveSwapBack((int)3));
  1449. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1450. }
  1451. [Test]
  1452. public void FixedList32Int_RemoveRange()
  1453. {
  1454. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1455. list.RemoveRange(1, 2);
  1456. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1457. }
  1458. [Test]
  1459. public void FixedList32Int_RemoveAtSwapBack()
  1460. {
  1461. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1462. list.RemoveAtSwapBack(1);
  1463. list.RemoveAtSwapBack(1);
  1464. Expected(ref list, 3, new int[] { 0, 1, 3 });
  1465. }
  1466. [Test]
  1467. public void FixedList32Int_RemoveRangeSwapBack()
  1468. {
  1469. var list = new FixedList32Bytes<int>() { 0, 3, 3, 1, 2 };
  1470. list.RemoveRangeSwapBack(1, 2);
  1471. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1472. }
  1473. [Test]
  1474. public void FixedList32Int_Insert()
  1475. {
  1476. var list = new FixedList32Bytes<int>() { 0, 3, 4 };
  1477. list.Insert(1,1);
  1478. list.Insert(2,2);
  1479. for(var i = 0; i < 5; ++i)
  1480. Assert.AreEqual(i, list[i]);
  1481. }
  1482. [Test]
  1483. public void FixedList32Int_Sort()
  1484. {
  1485. var list = new FixedList32Bytes<int>();
  1486. for(var i = 0; i < 5; ++i)
  1487. list.Add((int)(4-i));
  1488. list.Sort();
  1489. for(var i = 0; i < 5; ++i)
  1490. Assert.AreEqual(i, list[i]);
  1491. }
  1492. [Test]
  1493. public void FixedList32Int_To_FixedList64Int()
  1494. {
  1495. var a = new FixedList32Bytes<int>();
  1496. for(var i = 0; i < 7; ++i)
  1497. a.Add((int)i);
  1498. var b = new FixedList64Bytes<int>(a);
  1499. for(var i = 0; i < 7; ++i)
  1500. Assert.AreEqual((int)i, b[i]);
  1501. }
  1502. [Test]
  1503. public void FixedList32Int_To_FixedList128Int()
  1504. {
  1505. var a = new FixedList32Bytes<int>();
  1506. for(var i = 0; i < 7; ++i)
  1507. a.Add((int)i);
  1508. var b = new FixedList128Bytes<int>(a);
  1509. for(var i = 0; i < 7; ++i)
  1510. Assert.AreEqual((int)i, b[i]);
  1511. }
  1512. [Test]
  1513. public void FixedList64Int_HasExpectedLayout()
  1514. {
  1515. var actual = new FixedList64Bytes<int>();
  1516. for(var i = 0; i < 15; ++i)
  1517. actual.Add((int)i);
  1518. unsafe
  1519. {
  1520. var e = stackalloc byte[64];
  1521. e[0] = (byte)((15 >> 0) & 0xFF);
  1522. e[1] = (byte)((15 >> 8) & 0xFF);
  1523. for(var i = 0; i < 15; ++i)
  1524. {
  1525. var s = (int)i;
  1526. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  1527. }
  1528. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  1529. }
  1530. }
  1531. [Test]
  1532. public void FixedList64Int_HasExpectedCapacity()
  1533. {
  1534. var list = new FixedList64Bytes<int>();
  1535. var expectedCapacity = list.Capacity;
  1536. for(int i = 0; i < expectedCapacity; ++i)
  1537. list.Add((int)i);
  1538. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  1539. }
  1540. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  1541. class ScriptableObjectFixedList64Int_ : UnityEngine.ScriptableObject
  1542. {
  1543. public FixedList64Bytes<int> List;
  1544. }
  1545. [Test]
  1546. public void FixedList64Int_Serializes()
  1547. {
  1548. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList64Int_ >();
  1549. for(int i = 0; i < a.List.Capacity; ++i)
  1550. a.List.Add((int)i);
  1551. var b = UnityEngine.Object.Instantiate(a);
  1552. CollectionAssert.AreEqual(a.List, b.List);
  1553. }
  1554. #endif
  1555. [Test]
  1556. public void FixedList64Int_InsertRangeWithBeginEnd()
  1557. {
  1558. var list = new FixedList64Bytes<int>() { 0, 3, 4 };
  1559. list.InsertRangeWithBeginEnd(1,3);
  1560. list[1] = 1;
  1561. list[2] = 2;
  1562. for(var i = 0; i < 5; ++i)
  1563. Assert.AreEqual(i, list[i]);
  1564. }
  1565. private static void Expected(ref FixedList64Bytes<int> container, int expectedLength, int[] expected)
  1566. {
  1567. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  1568. Assert.AreEqual(container.Length, expectedLength);
  1569. for (var i = 0; i < container.Length; ++i)
  1570. {
  1571. Assert.AreEqual(expected[i], container[i]);
  1572. }
  1573. }
  1574. [Test]
  1575. public void FixedList64Int_RemoveAt()
  1576. {
  1577. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1578. list.RemoveAt(1);
  1579. list.RemoveAt(1);
  1580. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1581. }
  1582. [Test]
  1583. public void FixedList64Int_Remove()
  1584. {
  1585. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1586. Assert.True(list.Remove((int)3));
  1587. Assert.True(list.Remove((int)3));
  1588. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1589. }
  1590. [Test]
  1591. public void FixedList64Int_RemoveSwapBack()
  1592. {
  1593. var list = new FixedList64Bytes<int>() { 0, 3, 3, 2, 1 };
  1594. Assert.True(list.RemoveSwapBack((int)3));
  1595. Assert.True(list.RemoveSwapBack((int)3));
  1596. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1597. }
  1598. [Test]
  1599. public void FixedList64Int_RemoveRange()
  1600. {
  1601. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1602. list.RemoveRange(1, 2);
  1603. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1604. }
  1605. [Test]
  1606. public void FixedList64Int_RemoveAtSwapBack()
  1607. {
  1608. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1609. list.RemoveAtSwapBack(1);
  1610. list.RemoveAtSwapBack(1);
  1611. Expected(ref list, 3, new int[] { 0, 1, 3 });
  1612. }
  1613. [Test]
  1614. public void FixedList64Int_RemoveRangeSwapBack()
  1615. {
  1616. var list = new FixedList64Bytes<int>() { 0, 3, 3, 1, 2 };
  1617. list.RemoveRangeSwapBack(1, 2);
  1618. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1619. }
  1620. [Test]
  1621. public void FixedList64Int_Insert()
  1622. {
  1623. var list = new FixedList64Bytes<int>() { 0, 3, 4 };
  1624. list.Insert(1,1);
  1625. list.Insert(2,2);
  1626. for(var i = 0; i < 5; ++i)
  1627. Assert.AreEqual(i, list[i]);
  1628. }
  1629. [Test]
  1630. public void FixedList64Int_Sort()
  1631. {
  1632. var list = new FixedList64Bytes<int>();
  1633. for(var i = 0; i < 5; ++i)
  1634. list.Add((int)(4-i));
  1635. list.Sort();
  1636. for(var i = 0; i < 5; ++i)
  1637. Assert.AreEqual(i, list[i]);
  1638. }
  1639. [Test]
  1640. public void FixedList64Int_To_FixedList32Int()
  1641. {
  1642. var a = new FixedList64Bytes<int>();
  1643. for(var i = 0; i < 15; ++i)
  1644. a.Add((int)i);
  1645. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<int>(a); } );
  1646. }
  1647. [Test]
  1648. public void FixedList64Int_To_FixedList128Int()
  1649. {
  1650. var a = new FixedList64Bytes<int>();
  1651. for(var i = 0; i < 15; ++i)
  1652. a.Add((int)i);
  1653. var b = new FixedList128Bytes<int>(a);
  1654. for(var i = 0; i < 15; ++i)
  1655. Assert.AreEqual((int)i, b[i]);
  1656. }
  1657. [Test]
  1658. public void FixedList128Int_HasExpectedLayout()
  1659. {
  1660. var actual = new FixedList128Bytes<int>();
  1661. for(var i = 0; i < 31; ++i)
  1662. actual.Add((int)i);
  1663. unsafe
  1664. {
  1665. var e = stackalloc byte[128];
  1666. e[0] = (byte)((31 >> 0) & 0xFF);
  1667. e[1] = (byte)((31 >> 8) & 0xFF);
  1668. for(var i = 0; i < 31; ++i)
  1669. {
  1670. var s = (int)i;
  1671. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<int>() + sizeof(int) * i, &s, sizeof(int));
  1672. }
  1673. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  1674. }
  1675. }
  1676. [Test]
  1677. public void FixedList128Int_HasExpectedCapacity()
  1678. {
  1679. var list = new FixedList128Bytes<int>();
  1680. var expectedCapacity = list.Capacity;
  1681. for(int i = 0; i < expectedCapacity; ++i)
  1682. list.Add((int)i);
  1683. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((int)expectedCapacity); });
  1684. }
  1685. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  1686. class ScriptableObjectFixedList128Int_ : UnityEngine.ScriptableObject
  1687. {
  1688. public FixedList128Bytes<int> List;
  1689. }
  1690. [Test]
  1691. public void FixedList128Int_Serializes()
  1692. {
  1693. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList128Int_ >();
  1694. for(int i = 0; i < a.List.Capacity; ++i)
  1695. a.List.Add((int)i);
  1696. var b = UnityEngine.Object.Instantiate(a);
  1697. CollectionAssert.AreEqual(a.List, b.List);
  1698. }
  1699. #endif
  1700. [Test]
  1701. public void FixedList128Int_InsertRangeWithBeginEnd()
  1702. {
  1703. var list = new FixedList128Bytes<int>() { 0, 3, 4 };
  1704. list.InsertRangeWithBeginEnd(1,3);
  1705. list[1] = 1;
  1706. list[2] = 2;
  1707. for(var i = 0; i < 5; ++i)
  1708. Assert.AreEqual(i, list[i]);
  1709. }
  1710. private static void Expected(ref FixedList128Bytes<int> container, int expectedLength, int[] expected)
  1711. {
  1712. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  1713. Assert.AreEqual(container.Length, expectedLength);
  1714. for (var i = 0; i < container.Length; ++i)
  1715. {
  1716. Assert.AreEqual(expected[i], container[i]);
  1717. }
  1718. }
  1719. [Test]
  1720. public void FixedList128Int_RemoveAt()
  1721. {
  1722. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1723. list.RemoveAt(1);
  1724. list.RemoveAt(1);
  1725. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1726. }
  1727. [Test]
  1728. public void FixedList128Int_Remove()
  1729. {
  1730. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1731. Assert.True(list.Remove((int)3));
  1732. Assert.True(list.Remove((int)3));
  1733. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1734. }
  1735. [Test]
  1736. public void FixedList128Int_RemoveSwapBack()
  1737. {
  1738. var list = new FixedList128Bytes<int>() { 0, 3, 3, 2, 1 };
  1739. Assert.True(list.RemoveSwapBack((int)3));
  1740. Assert.True(list.RemoveSwapBack((int)3));
  1741. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1742. }
  1743. [Test]
  1744. public void FixedList128Int_RemoveRange()
  1745. {
  1746. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1747. list.RemoveRange(1, 2);
  1748. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1749. }
  1750. [Test]
  1751. public void FixedList128Int_RemoveAtSwapBack()
  1752. {
  1753. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1754. list.RemoveAtSwapBack(1);
  1755. list.RemoveAtSwapBack(1);
  1756. Expected(ref list, 3, new int[] { 0, 1, 3 });
  1757. }
  1758. [Test]
  1759. public void FixedList128Int_RemoveRangeSwapBack()
  1760. {
  1761. var list = new FixedList128Bytes<int>() { 0, 3, 3, 1, 2 };
  1762. list.RemoveRangeSwapBack(1, 2);
  1763. Expected(ref list, 3, new int[] { 0, 1, 2 });
  1764. }
  1765. [Test]
  1766. public void FixedList128Int_Insert()
  1767. {
  1768. var list = new FixedList128Bytes<int>() { 0, 3, 4 };
  1769. list.Insert(1,1);
  1770. list.Insert(2,2);
  1771. for(var i = 0; i < 5; ++i)
  1772. Assert.AreEqual(i, list[i]);
  1773. }
  1774. [Test]
  1775. public void FixedList128Int_Sort()
  1776. {
  1777. var list = new FixedList128Bytes<int>();
  1778. for(var i = 0; i < 5; ++i)
  1779. list.Add((int)(4-i));
  1780. list.Sort();
  1781. for(var i = 0; i < 5; ++i)
  1782. Assert.AreEqual(i, list[i]);
  1783. }
  1784. [Test]
  1785. public void FixedList128Int_To_FixedList32Int()
  1786. {
  1787. var a = new FixedList128Bytes<int>();
  1788. for(var i = 0; i < 31; ++i)
  1789. a.Add((int)i);
  1790. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<int>(a); } );
  1791. }
  1792. [Test]
  1793. public void FixedList128Int_To_FixedList64Int()
  1794. {
  1795. var a = new FixedList128Bytes<int>();
  1796. for(var i = 0; i < 31; ++i)
  1797. a.Add((int)i);
  1798. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList64Bytes<int>(a); } );
  1799. }
  1800. [Test]
  1801. public void FixedList32Float_FixedBytes30ToNativeArrayWorksGeneric()
  1802. {
  1803. var list = new FixedList<float,FixedBytes30>();
  1804. for(var i = 0; i < 7; ++i)
  1805. list.Add((float)(i * 123 + 234));
  1806. using(var array = list.ToNativeArray(Allocator.Temp))
  1807. {
  1808. for(var i = 0; i < 7; ++i)
  1809. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  1810. }
  1811. }
  1812. [Test]
  1813. public void FixedList32Float_ToNativeArrayWorks()
  1814. {
  1815. var list = new FixedList32Bytes<float>();
  1816. for(var i = 0; i < 7; ++i)
  1817. list.Add((float)(i * 123 + 234));
  1818. using(var array = list.ToNativeArray(Allocator.Temp))
  1819. {
  1820. for(var i = 0; i < 7; ++i)
  1821. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  1822. }
  1823. }
  1824. [Test]
  1825. public void FixedList32Float_GenericHasExpectedLayout()
  1826. {
  1827. var actual = new FixedList32Bytes<float>();
  1828. for(var i = 0; i < 7; ++i)
  1829. actual.Add((float)i);
  1830. unsafe
  1831. {
  1832. var e = stackalloc byte[32];
  1833. e[0] = (byte)((7 >> 0) & 0xFF);
  1834. e[1] = (byte)((7 >> 8) & 0xFF);
  1835. for(var i = 0; i < 7; ++i)
  1836. {
  1837. var s = (float)i;
  1838. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  1839. }
  1840. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  1841. }
  1842. }
  1843. [Test]
  1844. public void FixedList32Float_GenericHasExpectedCapacity()
  1845. {
  1846. var list = new FixedList32Bytes<float>();
  1847. var expectedCapacity = list.Capacity;
  1848. for(int i = 0; i < expectedCapacity; ++i)
  1849. list.Add((float)i);
  1850. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  1851. }
  1852. [Test]
  1853. public void FixedList32Float_GenericInsertRangeWithBeginEnd()
  1854. {
  1855. var list = new FixedList32Bytes<float>() { 0, 3, 4 };
  1856. list.InsertRangeWithBeginEnd(1,3);
  1857. list[1] = 1;
  1858. list[2] = 2;
  1859. for(var i = 0; i < 5; ++i)
  1860. Assert.AreEqual(i, list[i]);
  1861. }
  1862. [Test]
  1863. public void FixedList32Float_GenericRemoveRange()
  1864. {
  1865. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  1866. list.RemoveRange(1, 2);
  1867. for(var i = 0; i < 3; ++i)
  1868. Assert.AreEqual(i, list[i]);
  1869. }
  1870. [Test]
  1871. public void FixedList32Float_GenericInsert()
  1872. {
  1873. var list = new FixedList32Bytes<float>() { 0, 3, 4 };
  1874. list.Insert(1,1);
  1875. list.Insert(2,2);
  1876. for(var i = 0; i < 5; ++i)
  1877. Assert.AreEqual(i, list[i]);
  1878. }
  1879. [Test]
  1880. public void FixedList32Float_GenericRemoveAt()
  1881. {
  1882. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  1883. list.RemoveAt(1);
  1884. list.RemoveAt(1);
  1885. for(var i = 0; i < 3; ++i)
  1886. Assert.AreEqual(i, list[i]);
  1887. }
  1888. [Test]
  1889. public void FixedList32Float_GenericRemove()
  1890. {
  1891. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  1892. Assert.True(list.Remove((float)3));
  1893. Assert.True(list.Remove((float)3));
  1894. for(var i = 0; i < 3; ++i)
  1895. Assert.AreEqual(i, list[i]);
  1896. }
  1897. [Test]
  1898. public void FixedList32Float_GenericRemoveSwapBack()
  1899. {
  1900. var list = new FixedList32Bytes<float>() { 0, 3, 3, 2, 1 };
  1901. Assert.True(list.RemoveSwapBack((float)3));
  1902. Assert.True(list.RemoveSwapBack((float)3));
  1903. for(var i = 0; i < 3; ++i)
  1904. Assert.AreEqual(i, list[i]);
  1905. }
  1906. [Test]
  1907. public void FixedList32Float_GenericSort()
  1908. {
  1909. var list = new FixedList32Bytes<float>();
  1910. for(var i = 0; i < 5; ++i)
  1911. list.Add((float)(4-i));
  1912. list.Sort();
  1913. for(var i = 0; i < 5; ++i)
  1914. Assert.AreEqual(i, list[i]);
  1915. }
  1916. [Test]
  1917. public void FixedList32Float_GenericSortCustomComparer()
  1918. {
  1919. var list = new FixedList32Bytes<float>();
  1920. for(var i = 0; i < 5; ++i)
  1921. list.Add((float)(i));
  1922. list.Sort(new DescendingComparer<float>());
  1923. for(var i = 0; i < 5; ++i)
  1924. Assert.AreEqual(4-i, list[i]);
  1925. }
  1926. [Test]
  1927. public unsafe void FixedList32Float_IndexOf()
  1928. {
  1929. var list = new FixedList32Bytes<float>() { 123, 178 };
  1930. bool r0 = false, r1 = false, r2 = false;
  1931. GCAllocRecorder.ValidateNoGCAllocs(() =>
  1932. {
  1933. r0 = -1 != list.IndexOf((float)145);
  1934. r1 = list.Contains((float)123);
  1935. r2 = list.Contains((float)178);
  1936. });
  1937. Assert.False(r0);
  1938. Assert.True(r1);
  1939. Assert.True(r2);
  1940. }
  1941. [Test]
  1942. public void FixedList64Float_FixedBytes62ToNativeArrayWorksGeneric()
  1943. {
  1944. var list = new FixedList<float,FixedBytes62>();
  1945. for(var i = 0; i < 15; ++i)
  1946. list.Add((float)(i * 123 + 234));
  1947. using(var array = list.ToNativeArray(Allocator.Temp))
  1948. {
  1949. for(var i = 0; i < 15; ++i)
  1950. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  1951. }
  1952. }
  1953. [Test]
  1954. public void FixedList64Float_ToNativeArrayWorks()
  1955. {
  1956. var list = new FixedList64Bytes<float>();
  1957. for(var i = 0; i < 15; ++i)
  1958. list.Add((float)(i * 123 + 234));
  1959. using(var array = list.ToNativeArray(Allocator.Temp))
  1960. {
  1961. for(var i = 0; i < 15; ++i)
  1962. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  1963. }
  1964. }
  1965. [Test]
  1966. public void FixedList64Float_GenericHasExpectedLayout()
  1967. {
  1968. var actual = new FixedList64Bytes<float>();
  1969. for(var i = 0; i < 15; ++i)
  1970. actual.Add((float)i);
  1971. unsafe
  1972. {
  1973. var e = stackalloc byte[64];
  1974. e[0] = (byte)((15 >> 0) & 0xFF);
  1975. e[1] = (byte)((15 >> 8) & 0xFF);
  1976. for(var i = 0; i < 15; ++i)
  1977. {
  1978. var s = (float)i;
  1979. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  1980. }
  1981. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  1982. }
  1983. }
  1984. [Test]
  1985. public void FixedList64Float_GenericHasExpectedCapacity()
  1986. {
  1987. var list = new FixedList64Bytes<float>();
  1988. var expectedCapacity = list.Capacity;
  1989. for(int i = 0; i < expectedCapacity; ++i)
  1990. list.Add((float)i);
  1991. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  1992. }
  1993. [Test]
  1994. public void FixedList64Float_GenericInsertRangeWithBeginEnd()
  1995. {
  1996. var list = new FixedList64Bytes<float>() { 0, 3, 4 };
  1997. list.InsertRangeWithBeginEnd(1,3);
  1998. list[1] = 1;
  1999. list[2] = 2;
  2000. for(var i = 0; i < 5; ++i)
  2001. Assert.AreEqual(i, list[i]);
  2002. }
  2003. [Test]
  2004. public void FixedList64Float_GenericRemoveRange()
  2005. {
  2006. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2007. list.RemoveRange(1, 2);
  2008. for(var i = 0; i < 3; ++i)
  2009. Assert.AreEqual(i, list[i]);
  2010. }
  2011. [Test]
  2012. public void FixedList64Float_GenericInsert()
  2013. {
  2014. var list = new FixedList64Bytes<float>() { 0, 3, 4 };
  2015. list.Insert(1,1);
  2016. list.Insert(2,2);
  2017. for(var i = 0; i < 5; ++i)
  2018. Assert.AreEqual(i, list[i]);
  2019. }
  2020. [Test]
  2021. public void FixedList64Float_GenericRemoveAt()
  2022. {
  2023. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2024. list.RemoveAt(1);
  2025. list.RemoveAt(1);
  2026. for(var i = 0; i < 3; ++i)
  2027. Assert.AreEqual(i, list[i]);
  2028. }
  2029. [Test]
  2030. public void FixedList64Float_GenericRemove()
  2031. {
  2032. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2033. Assert.True(list.Remove((float)3));
  2034. Assert.True(list.Remove((float)3));
  2035. for(var i = 0; i < 3; ++i)
  2036. Assert.AreEqual(i, list[i]);
  2037. }
  2038. [Test]
  2039. public void FixedList64Float_GenericRemoveSwapBack()
  2040. {
  2041. var list = new FixedList64Bytes<float>() { 0, 3, 3, 2, 1 };
  2042. Assert.True(list.RemoveSwapBack((float)3));
  2043. Assert.True(list.RemoveSwapBack((float)3));
  2044. for(var i = 0; i < 3; ++i)
  2045. Assert.AreEqual(i, list[i]);
  2046. }
  2047. [Test]
  2048. public void FixedList64Float_GenericSort()
  2049. {
  2050. var list = new FixedList64Bytes<float>();
  2051. for(var i = 0; i < 5; ++i)
  2052. list.Add((float)(4-i));
  2053. list.Sort();
  2054. for(var i = 0; i < 5; ++i)
  2055. Assert.AreEqual(i, list[i]);
  2056. }
  2057. [Test]
  2058. public void FixedList64Float_GenericSortCustomComparer()
  2059. {
  2060. var list = new FixedList64Bytes<float>();
  2061. for(var i = 0; i < 5; ++i)
  2062. list.Add((float)(i));
  2063. list.Sort(new DescendingComparer<float>());
  2064. for(var i = 0; i < 5; ++i)
  2065. Assert.AreEqual(4-i, list[i]);
  2066. }
  2067. [Test]
  2068. public unsafe void FixedList64Float_IndexOf()
  2069. {
  2070. var list = new FixedList64Bytes<float>() { 123, 178 };
  2071. bool r0 = false, r1 = false, r2 = false;
  2072. GCAllocRecorder.ValidateNoGCAllocs(() =>
  2073. {
  2074. r0 = -1 != list.IndexOf((float)145);
  2075. r1 = list.Contains((float)123);
  2076. r2 = list.Contains((float)178);
  2077. });
  2078. Assert.False(r0);
  2079. Assert.True(r1);
  2080. Assert.True(r2);
  2081. }
  2082. [Test]
  2083. public void FixedList128Float_FixedBytes126ToNativeArrayWorksGeneric()
  2084. {
  2085. var list = new FixedList<float,FixedBytes126>();
  2086. for(var i = 0; i < 31; ++i)
  2087. list.Add((float)(i * 123 + 234));
  2088. using(var array = list.ToNativeArray(Allocator.Temp))
  2089. {
  2090. for(var i = 0; i < 31; ++i)
  2091. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  2092. }
  2093. }
  2094. [Test]
  2095. public void FixedList128Float_ToNativeArrayWorks()
  2096. {
  2097. var list = new FixedList128Bytes<float>();
  2098. for(var i = 0; i < 31; ++i)
  2099. list.Add((float)(i * 123 + 234));
  2100. using(var array = list.ToNativeArray(Allocator.Temp))
  2101. {
  2102. for(var i = 0; i < 31; ++i)
  2103. Assert.AreEqual((float)(i * 123 + 234), array[i]);
  2104. }
  2105. }
  2106. [Test]
  2107. public void FixedList128Float_GenericHasExpectedLayout()
  2108. {
  2109. var actual = new FixedList128Bytes<float>();
  2110. for(var i = 0; i < 31; ++i)
  2111. actual.Add((float)i);
  2112. unsafe
  2113. {
  2114. var e = stackalloc byte[128];
  2115. e[0] = (byte)((31 >> 0) & 0xFF);
  2116. e[1] = (byte)((31 >> 8) & 0xFF);
  2117. for(var i = 0; i < 31; ++i)
  2118. {
  2119. var s = (float)i;
  2120. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  2121. }
  2122. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  2123. }
  2124. }
  2125. [Test]
  2126. public void FixedList128Float_GenericHasExpectedCapacity()
  2127. {
  2128. var list = new FixedList128Bytes<float>();
  2129. var expectedCapacity = list.Capacity;
  2130. for(int i = 0; i < expectedCapacity; ++i)
  2131. list.Add((float)i);
  2132. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  2133. }
  2134. [Test]
  2135. public void FixedList128Float_GenericInsertRangeWithBeginEnd()
  2136. {
  2137. var list = new FixedList128Bytes<float>() { 0, 3, 4 };
  2138. list.InsertRangeWithBeginEnd(1,3);
  2139. list[1] = 1;
  2140. list[2] = 2;
  2141. for(var i = 0; i < 5; ++i)
  2142. Assert.AreEqual(i, list[i]);
  2143. }
  2144. [Test]
  2145. public void FixedList128Float_GenericRemoveRange()
  2146. {
  2147. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2148. list.RemoveRange(1, 2);
  2149. for(var i = 0; i < 3; ++i)
  2150. Assert.AreEqual(i, list[i]);
  2151. }
  2152. [Test]
  2153. public void FixedList128Float_GenericInsert()
  2154. {
  2155. var list = new FixedList128Bytes<float>() { 0, 3, 4 };
  2156. list.Insert(1,1);
  2157. list.Insert(2,2);
  2158. for(var i = 0; i < 5; ++i)
  2159. Assert.AreEqual(i, list[i]);
  2160. }
  2161. [Test]
  2162. public void FixedList128Float_GenericRemoveAt()
  2163. {
  2164. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2165. list.RemoveAt(1);
  2166. list.RemoveAt(1);
  2167. for(var i = 0; i < 3; ++i)
  2168. Assert.AreEqual(i, list[i]);
  2169. }
  2170. [Test]
  2171. public void FixedList128Float_GenericRemove()
  2172. {
  2173. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2174. Assert.True(list.Remove((float)3));
  2175. Assert.True(list.Remove((float)3));
  2176. for(var i = 0; i < 3; ++i)
  2177. Assert.AreEqual(i, list[i]);
  2178. }
  2179. [Test]
  2180. public void FixedList128Float_GenericRemoveSwapBack()
  2181. {
  2182. var list = new FixedList128Bytes<float>() { 0, 3, 3, 2, 1 };
  2183. Assert.True(list.RemoveSwapBack((float)3));
  2184. Assert.True(list.RemoveSwapBack((float)3));
  2185. for(var i = 0; i < 3; ++i)
  2186. Assert.AreEqual(i, list[i]);
  2187. }
  2188. [Test]
  2189. public void FixedList128Float_GenericSort()
  2190. {
  2191. var list = new FixedList128Bytes<float>();
  2192. for(var i = 0; i < 5; ++i)
  2193. list.Add((float)(4-i));
  2194. list.Sort();
  2195. for(var i = 0; i < 5; ++i)
  2196. Assert.AreEqual(i, list[i]);
  2197. }
  2198. [Test]
  2199. public void FixedList128Float_GenericSortCustomComparer()
  2200. {
  2201. var list = new FixedList128Bytes<float>();
  2202. for(var i = 0; i < 5; ++i)
  2203. list.Add((float)(i));
  2204. list.Sort(new DescendingComparer<float>());
  2205. for(var i = 0; i < 5; ++i)
  2206. Assert.AreEqual(4-i, list[i]);
  2207. }
  2208. [Test]
  2209. public unsafe void FixedList128Float_IndexOf()
  2210. {
  2211. var list = new FixedList128Bytes<float>() { 123, 178 };
  2212. bool r0 = false, r1 = false, r2 = false;
  2213. GCAllocRecorder.ValidateNoGCAllocs(() =>
  2214. {
  2215. r0 = -1 != list.IndexOf((float)145);
  2216. r1 = list.Contains((float)123);
  2217. r2 = list.Contains((float)178);
  2218. });
  2219. Assert.False(r0);
  2220. Assert.True(r1);
  2221. Assert.True(r2);
  2222. }
  2223. [Test]
  2224. public void FixedList32Float_HasExpectedLayout()
  2225. {
  2226. var actual = new FixedList32Bytes<float>();
  2227. for(var i = 0; i < 7; ++i)
  2228. actual.Add((float)i);
  2229. unsafe
  2230. {
  2231. var e = stackalloc byte[32];
  2232. e[0] = (byte)((7 >> 0) & 0xFF);
  2233. e[1] = (byte)((7 >> 8) & 0xFF);
  2234. for(var i = 0; i < 7; ++i)
  2235. {
  2236. var s = (float)i;
  2237. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  2238. }
  2239. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 32));
  2240. }
  2241. }
  2242. [Test]
  2243. public void FixedList32Float_HasExpectedCapacity()
  2244. {
  2245. var list = new FixedList32Bytes<float>();
  2246. var expectedCapacity = list.Capacity;
  2247. for(int i = 0; i < expectedCapacity; ++i)
  2248. list.Add((float)i);
  2249. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  2250. }
  2251. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  2252. class ScriptableObjectFixedList32Float_ : UnityEngine.ScriptableObject
  2253. {
  2254. public FixedList32Bytes<float> List;
  2255. }
  2256. [Test]
  2257. public void FixedList32Float_Serializes()
  2258. {
  2259. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList32Float_ >();
  2260. for(int i = 0; i < a.List.Capacity; ++i)
  2261. a.List.Add((float)i);
  2262. var b = UnityEngine.Object.Instantiate(a);
  2263. CollectionAssert.AreEqual(a.List, b.List);
  2264. }
  2265. #endif
  2266. [Test]
  2267. public void FixedList32Float_InsertRangeWithBeginEnd()
  2268. {
  2269. var list = new FixedList32Bytes<float>() { 0, 3, 4 };
  2270. list.InsertRangeWithBeginEnd(1,3);
  2271. list[1] = 1;
  2272. list[2] = 2;
  2273. for(var i = 0; i < 5; ++i)
  2274. Assert.AreEqual(i, list[i]);
  2275. }
  2276. private static void Expected(ref FixedList32Bytes<float> container, int expectedLength, int[] expected)
  2277. {
  2278. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  2279. Assert.AreEqual(container.Length, expectedLength);
  2280. for (var i = 0; i < container.Length; ++i)
  2281. {
  2282. Assert.AreEqual(expected[i], container[i]);
  2283. }
  2284. }
  2285. [Test]
  2286. public void FixedList32Float_RemoveAt()
  2287. {
  2288. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  2289. list.RemoveAt(1);
  2290. list.RemoveAt(1);
  2291. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2292. }
  2293. [Test]
  2294. public void FixedList32Float_Remove()
  2295. {
  2296. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  2297. Assert.True(list.Remove((float)3));
  2298. Assert.True(list.Remove((float)3));
  2299. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2300. }
  2301. [Test]
  2302. public void FixedList32Float_RemoveSwapBack()
  2303. {
  2304. var list = new FixedList32Bytes<float>() { 0, 3, 3, 2, 1 };
  2305. Assert.True(list.RemoveSwapBack((float)3));
  2306. Assert.True(list.RemoveSwapBack((float)3));
  2307. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2308. }
  2309. [Test]
  2310. public void FixedList32Float_RemoveRange()
  2311. {
  2312. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  2313. list.RemoveRange(1, 2);
  2314. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2315. }
  2316. [Test]
  2317. public void FixedList32Float_RemoveAtSwapBack()
  2318. {
  2319. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  2320. list.RemoveAtSwapBack(1);
  2321. list.RemoveAtSwapBack(1);
  2322. Expected(ref list, 3, new int[] { 0, 1, 3 });
  2323. }
  2324. [Test]
  2325. public void FixedList32Float_RemoveRangeSwapBack()
  2326. {
  2327. var list = new FixedList32Bytes<float>() { 0, 3, 3, 1, 2 };
  2328. list.RemoveRangeSwapBack(1, 2);
  2329. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2330. }
  2331. [Test]
  2332. public void FixedList32Float_Insert()
  2333. {
  2334. var list = new FixedList32Bytes<float>() { 0, 3, 4 };
  2335. list.Insert(1,1);
  2336. list.Insert(2,2);
  2337. for(var i = 0; i < 5; ++i)
  2338. Assert.AreEqual(i, list[i]);
  2339. }
  2340. [Test]
  2341. public void FixedList32Float_Sort()
  2342. {
  2343. var list = new FixedList32Bytes<float>();
  2344. for(var i = 0; i < 5; ++i)
  2345. list.Add((float)(4-i));
  2346. list.Sort();
  2347. for(var i = 0; i < 5; ++i)
  2348. Assert.AreEqual(i, list[i]);
  2349. }
  2350. [Test]
  2351. public void FixedList32Float_To_FixedList64Float()
  2352. {
  2353. var a = new FixedList32Bytes<float>();
  2354. for(var i = 0; i < 7; ++i)
  2355. a.Add((float)i);
  2356. var b = new FixedList64Bytes<float>(a);
  2357. for(var i = 0; i < 7; ++i)
  2358. Assert.AreEqual((float)i, b[i]);
  2359. }
  2360. [Test]
  2361. public void FixedList32Float_To_FixedList128Float()
  2362. {
  2363. var a = new FixedList32Bytes<float>();
  2364. for(var i = 0; i < 7; ++i)
  2365. a.Add((float)i);
  2366. var b = new FixedList128Bytes<float>(a);
  2367. for(var i = 0; i < 7; ++i)
  2368. Assert.AreEqual((float)i, b[i]);
  2369. }
  2370. [Test]
  2371. public void FixedList64Float_HasExpectedLayout()
  2372. {
  2373. var actual = new FixedList64Bytes<float>();
  2374. for(var i = 0; i < 15; ++i)
  2375. actual.Add((float)i);
  2376. unsafe
  2377. {
  2378. var e = stackalloc byte[64];
  2379. e[0] = (byte)((15 >> 0) & 0xFF);
  2380. e[1] = (byte)((15 >> 8) & 0xFF);
  2381. for(var i = 0; i < 15; ++i)
  2382. {
  2383. var s = (float)i;
  2384. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  2385. }
  2386. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 64));
  2387. }
  2388. }
  2389. [Test]
  2390. public void FixedList64Float_HasExpectedCapacity()
  2391. {
  2392. var list = new FixedList64Bytes<float>();
  2393. var expectedCapacity = list.Capacity;
  2394. for(int i = 0; i < expectedCapacity; ++i)
  2395. list.Add((float)i);
  2396. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  2397. }
  2398. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  2399. class ScriptableObjectFixedList64Float_ : UnityEngine.ScriptableObject
  2400. {
  2401. public FixedList64Bytes<float> List;
  2402. }
  2403. [Test]
  2404. public void FixedList64Float_Serializes()
  2405. {
  2406. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList64Float_ >();
  2407. for(int i = 0; i < a.List.Capacity; ++i)
  2408. a.List.Add((float)i);
  2409. var b = UnityEngine.Object.Instantiate(a);
  2410. CollectionAssert.AreEqual(a.List, b.List);
  2411. }
  2412. #endif
  2413. [Test]
  2414. public void FixedList64Float_InsertRangeWithBeginEnd()
  2415. {
  2416. var list = new FixedList64Bytes<float>() { 0, 3, 4 };
  2417. list.InsertRangeWithBeginEnd(1,3);
  2418. list[1] = 1;
  2419. list[2] = 2;
  2420. for(var i = 0; i < 5; ++i)
  2421. Assert.AreEqual(i, list[i]);
  2422. }
  2423. private static void Expected(ref FixedList64Bytes<float> container, int expectedLength, int[] expected)
  2424. {
  2425. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  2426. Assert.AreEqual(container.Length, expectedLength);
  2427. for (var i = 0; i < container.Length; ++i)
  2428. {
  2429. Assert.AreEqual(expected[i], container[i]);
  2430. }
  2431. }
  2432. [Test]
  2433. public void FixedList64Float_RemoveAt()
  2434. {
  2435. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2436. list.RemoveAt(1);
  2437. list.RemoveAt(1);
  2438. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2439. }
  2440. [Test]
  2441. public void FixedList64Float_Remove()
  2442. {
  2443. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2444. Assert.True(list.Remove((float)3));
  2445. Assert.True(list.Remove((float)3));
  2446. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2447. }
  2448. [Test]
  2449. public void FixedList64Float_RemoveSwapBack()
  2450. {
  2451. var list = new FixedList64Bytes<float>() { 0, 3, 3, 2, 1 };
  2452. Assert.True(list.RemoveSwapBack((float)3));
  2453. Assert.True(list.RemoveSwapBack((float)3));
  2454. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2455. }
  2456. [Test]
  2457. public void FixedList64Float_RemoveRange()
  2458. {
  2459. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2460. list.RemoveRange(1, 2);
  2461. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2462. }
  2463. [Test]
  2464. public void FixedList64Float_RemoveAtSwapBack()
  2465. {
  2466. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2467. list.RemoveAtSwapBack(1);
  2468. list.RemoveAtSwapBack(1);
  2469. Expected(ref list, 3, new int[] { 0, 1, 3 });
  2470. }
  2471. [Test]
  2472. public void FixedList64Float_RemoveRangeSwapBack()
  2473. {
  2474. var list = new FixedList64Bytes<float>() { 0, 3, 3, 1, 2 };
  2475. list.RemoveRangeSwapBack(1, 2);
  2476. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2477. }
  2478. [Test]
  2479. public void FixedList64Float_Insert()
  2480. {
  2481. var list = new FixedList64Bytes<float>() { 0, 3, 4 };
  2482. list.Insert(1,1);
  2483. list.Insert(2,2);
  2484. for(var i = 0; i < 5; ++i)
  2485. Assert.AreEqual(i, list[i]);
  2486. }
  2487. [Test]
  2488. public void FixedList64Float_Sort()
  2489. {
  2490. var list = new FixedList64Bytes<float>();
  2491. for(var i = 0; i < 5; ++i)
  2492. list.Add((float)(4-i));
  2493. list.Sort();
  2494. for(var i = 0; i < 5; ++i)
  2495. Assert.AreEqual(i, list[i]);
  2496. }
  2497. [Test]
  2498. public void FixedList64Float_To_FixedList32Float()
  2499. {
  2500. var a = new FixedList64Bytes<float>();
  2501. for(var i = 0; i < 15; ++i)
  2502. a.Add((float)i);
  2503. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<float>(a); } );
  2504. }
  2505. [Test]
  2506. public void FixedList64Float_To_FixedList128Float()
  2507. {
  2508. var a = new FixedList64Bytes<float>();
  2509. for(var i = 0; i < 15; ++i)
  2510. a.Add((float)i);
  2511. var b = new FixedList128Bytes<float>(a);
  2512. for(var i = 0; i < 15; ++i)
  2513. Assert.AreEqual((float)i, b[i]);
  2514. }
  2515. [Test]
  2516. public void FixedList128Float_HasExpectedLayout()
  2517. {
  2518. var actual = new FixedList128Bytes<float>();
  2519. for(var i = 0; i < 31; ++i)
  2520. actual.Add((float)i);
  2521. unsafe
  2522. {
  2523. var e = stackalloc byte[128];
  2524. e[0] = (byte)((31 >> 0) & 0xFF);
  2525. e[1] = (byte)((31 >> 8) & 0xFF);
  2526. for(var i = 0; i < 31; ++i)
  2527. {
  2528. var s = (float)i;
  2529. UnsafeUtility.MemCpy(e + 2 + FixedList.PaddingBytes<float>() + sizeof(float) * i, &s, sizeof(float));
  2530. }
  2531. Assert.AreEqual(0, UnsafeUtility.MemCmp(e, &actual.length, 128));
  2532. }
  2533. }
  2534. [Test]
  2535. public void FixedList128Float_HasExpectedCapacity()
  2536. {
  2537. var list = new FixedList128Bytes<float>();
  2538. var expectedCapacity = list.Capacity;
  2539. for(int i = 0; i < expectedCapacity; ++i)
  2540. list.Add((float)i);
  2541. Assert.Throws<IndexOutOfRangeException> (() => { list.Add((float)expectedCapacity); });
  2542. }
  2543. #if !UNITY_DOTSRUNTIME // DOTS-Runtime doesn't support UnityEngine
  2544. class ScriptableObjectFixedList128Float_ : UnityEngine.ScriptableObject
  2545. {
  2546. public FixedList128Bytes<float> List;
  2547. }
  2548. [Test]
  2549. public void FixedList128Float_Serializes()
  2550. {
  2551. var a = UnityEngine.ScriptableObject.CreateInstance<ScriptableObjectFixedList128Float_ >();
  2552. for(int i = 0; i < a.List.Capacity; ++i)
  2553. a.List.Add((float)i);
  2554. var b = UnityEngine.Object.Instantiate(a);
  2555. CollectionAssert.AreEqual(a.List, b.List);
  2556. }
  2557. #endif
  2558. [Test]
  2559. public void FixedList128Float_InsertRangeWithBeginEnd()
  2560. {
  2561. var list = new FixedList128Bytes<float>() { 0, 3, 4 };
  2562. list.InsertRangeWithBeginEnd(1,3);
  2563. list[1] = 1;
  2564. list[2] = 2;
  2565. for(var i = 0; i < 5; ++i)
  2566. Assert.AreEqual(i, list[i]);
  2567. }
  2568. private static void Expected(ref FixedList128Bytes<float> container, int expectedLength, int[] expected)
  2569. {
  2570. Assert.AreEqual(expectedLength == 0, container.IsEmpty);
  2571. Assert.AreEqual(container.Length, expectedLength);
  2572. for (var i = 0; i < container.Length; ++i)
  2573. {
  2574. Assert.AreEqual(expected[i], container[i]);
  2575. }
  2576. }
  2577. [Test]
  2578. public void FixedList128Float_RemoveAt()
  2579. {
  2580. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2581. list.RemoveAt(1);
  2582. list.RemoveAt(1);
  2583. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2584. }
  2585. [Test]
  2586. public void FixedList128Float_Remove()
  2587. {
  2588. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2589. Assert.True(list.Remove((float)3));
  2590. Assert.True(list.Remove((float)3));
  2591. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2592. }
  2593. [Test]
  2594. public void FixedList128Float_RemoveSwapBack()
  2595. {
  2596. var list = new FixedList128Bytes<float>() { 0, 3, 3, 2, 1 };
  2597. Assert.True(list.RemoveSwapBack((float)3));
  2598. Assert.True(list.RemoveSwapBack((float)3));
  2599. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2600. }
  2601. [Test]
  2602. public void FixedList128Float_RemoveRange()
  2603. {
  2604. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2605. list.RemoveRange(1, 2);
  2606. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2607. }
  2608. [Test]
  2609. public void FixedList128Float_RemoveAtSwapBack()
  2610. {
  2611. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2612. list.RemoveAtSwapBack(1);
  2613. list.RemoveAtSwapBack(1);
  2614. Expected(ref list, 3, new int[] { 0, 1, 3 });
  2615. }
  2616. [Test]
  2617. public void FixedList128Float_RemoveRangeSwapBack()
  2618. {
  2619. var list = new FixedList128Bytes<float>() { 0, 3, 3, 1, 2 };
  2620. list.RemoveRangeSwapBack(1, 2);
  2621. Expected(ref list, 3, new int[] { 0, 1, 2 });
  2622. }
  2623. [Test]
  2624. public void FixedList128Float_Insert()
  2625. {
  2626. var list = new FixedList128Bytes<float>() { 0, 3, 4 };
  2627. list.Insert(1,1);
  2628. list.Insert(2,2);
  2629. for(var i = 0; i < 5; ++i)
  2630. Assert.AreEqual(i, list[i]);
  2631. }
  2632. [Test]
  2633. public void FixedList128Float_Sort()
  2634. {
  2635. var list = new FixedList128Bytes<float>();
  2636. for(var i = 0; i < 5; ++i)
  2637. list.Add((float)(4-i));
  2638. list.Sort();
  2639. for(var i = 0; i < 5; ++i)
  2640. Assert.AreEqual(i, list[i]);
  2641. }
  2642. [Test]
  2643. public void FixedList128Float_To_FixedList32Float()
  2644. {
  2645. var a = new FixedList128Bytes<float>();
  2646. for(var i = 0; i < 31; ++i)
  2647. a.Add((float)i);
  2648. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList32Bytes<float>(a); } );
  2649. }
  2650. [Test]
  2651. public void FixedList128Float_To_FixedList64Float()
  2652. {
  2653. var a = new FixedList128Bytes<float>();
  2654. for(var i = 0; i < 31; ++i)
  2655. a.Add((float)i);
  2656. Assert.Throws<IndexOutOfRangeException> (() => { var b = new FixedList64Bytes<float>(a); } );
  2657. }
  2658. }