暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NativeSortTests.tt 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. <#/*THIS IS A T4 FILE - see t4_text_templating.md for what it is and how to run codegen*/#>
  2. <#@ template debug="True" #>
  3. <#@ output extension=".gen.cs" #>
  4. <#@ assembly name="System.Core" #>
  5. using NUnit.Framework;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Unity.Burst;
  10. using Unity.Collections;
  11. using Unity.Collections.Tests;
  12. using Unity.Collections.LowLevel.Unsafe;
  13. using Unity.Jobs;
  14. using Unity.Mathematics;
  15. //------------------------------------------------------------------------------
  16. // <auto-generated>
  17. // This code was generated by a tool.
  18. //
  19. // TextTransform Packages/com.unity.collections/Unity.Collections.Tests/NativeSortTests.tt
  20. //
  21. // Changes to this file may cause incorrect behavior and will be lost if
  22. // the code is regenerated.
  23. // </auto-generated>
  24. //------------------------------------------------------------------------------
  25. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortExtension.DefaultComparer<int>>))]
  26. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortExtension.DefaultComparer<int>>.SegmentSort))]
  27. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortExtension.DefaultComparer<int>>.SegmentSortMerge))]
  28. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.DescendingComparer<int>>))]
  29. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.DescendingComparer<int>>.SegmentSort))]
  30. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.DescendingComparer<int>>.SegmentSortMerge))]
  31. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer0<int>>))]
  32. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer0<int>>.SegmentSort))]
  33. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer0<int>>.SegmentSortMerge))]
  34. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer1<int>>))]
  35. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer1<int>>.SegmentSort))]
  36. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer1<int>>.SegmentSortMerge))]
  37. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer2<int>>))]
  38. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer2<int>>.SegmentSort))]
  39. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer2<int>>.SegmentSortMerge))]
  40. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer3<int>>))]
  41. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer3<int>>.SegmentSort))]
  42. [assembly: RegisterGenericJobType(typeof(SortJob<int, NativeSortTests.BrokenComparer3<int>>.SegmentSortMerge))]
  43. internal class NativeSortTests : CollectionsTestCommonBase
  44. {
  45. internal struct DescendingComparer<T> : IComparer<T> where T : IComparable<T>
  46. {
  47. public int Compare(T x, T y) => y.CompareTo(x);
  48. }
  49. internal struct BrokenComparer0<T> : IComparer<T> where T : IComparable<T>
  50. {
  51. public int Compare(T x, T y)
  52. {
  53. int result = y.CompareTo(x);
  54. return result < 0 ? -1 : 1;
  55. }
  56. }
  57. internal struct BrokenComparer1<T> : IComparer<T> where T : IComparable<T>
  58. {
  59. public int Compare(T x, T y)
  60. {
  61. int result = y.CompareTo(x);
  62. return result > 0 ? 1 : -1;
  63. }
  64. }
  65. internal struct BrokenComparer2<T> : IComparer<T> where T : IComparable<T>
  66. {
  67. public int Compare(T x, T y)
  68. {
  69. int result = y.CompareTo(x);
  70. return math.max(0, result);
  71. }
  72. }
  73. internal struct BrokenComparer3<T> : IComparer<T> where T : IComparable<T>
  74. {
  75. public int Compare(T x, T y)
  76. {
  77. int result = y.CompareTo(x);
  78. return math.min(0, result);
  79. }
  80. }
  81. [Test]
  82. public void NativeArraySlice_BinarySearch()
  83. {
  84. var init = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
  85. var container = new NativeArray<int>(16, Allocator.Persistent);
  86. var slice = new NativeSlice<int>(container, 0, container.Length);
  87. var arrayRo = container.AsReadOnly();
  88. container.CopyFrom(init);
  89. for (int i = 0, num = container.Length; i < num; ++i)
  90. {
  91. Assert.AreEqual(i, container.BinarySearch(container[i]));
  92. Assert.AreEqual(i, slice.BinarySearch(container[i]));
  93. Assert.AreEqual(i, arrayRo.BinarySearch(container[i]));
  94. }
  95. container.Dispose();
  96. }
  97. struct BinarySearch_Job : IJob
  98. {
  99. [ReadOnly]
  100. public NativeArray<int> array;
  101. [ReadOnly]
  102. public NativeSlice<int> slice;
  103. [ReadOnly]
  104. public NativeArray<int>.ReadOnly arrayRo;
  105. [ReadOnly]
  106. public NativeList<int> nativeList;
  107. public void Execute()
  108. {
  109. for (int i = 0, num = array.Length; i < num; ++i)
  110. {
  111. Assert.AreEqual(i, array.BinarySearch(array[i]));
  112. Assert.AreEqual(i, slice.BinarySearch(array[i]));
  113. Assert.AreEqual(i, arrayRo.BinarySearch(array[i]));
  114. Assert.AreEqual(i, nativeList.BinarySearch(array[i]));
  115. }
  116. }
  117. }
  118. [Test]
  119. public void BinarySearch_From_Job()
  120. {
  121. var init = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
  122. var container = new NativeArray<int>(16, Allocator.Persistent);
  123. var slice = new NativeSlice<int>(container, 0, container.Length);
  124. var arrayRo = container.AsReadOnly();
  125. container.CopyFrom(init);
  126. var nativeList = new NativeList<int>(16, Allocator.Persistent);
  127. nativeList.CopyFrom(container);
  128. new BinarySearch_Job
  129. {
  130. array = container,
  131. slice = slice,
  132. arrayRo = arrayRo,
  133. nativeList = nativeList,
  134. }.Run();
  135. container.Dispose();
  136. nativeList.Dispose();
  137. }
  138. [Test]
  139. public void NativeArraySlice_BinarySearch_NotFound()
  140. {
  141. {
  142. var container = new NativeArray<int>(1, Allocator.Temp);
  143. var slice = new NativeSlice<int>(container, 0, container.Length);
  144. var arrayRo = container.AsReadOnly();
  145. Assert.AreEqual(container.Length, 1);
  146. Assert.AreEqual(-2, container.BinarySearch(1));
  147. Assert.AreEqual(-2, slice.BinarySearch(1));
  148. Assert.AreEqual(-2, arrayRo.BinarySearch(1));
  149. slice[0] = 1;
  150. Assert.AreEqual(0, container.BinarySearch(1));
  151. Assert.AreEqual(0, slice.BinarySearch(1));
  152. Assert.AreEqual(0, arrayRo.BinarySearch(1));
  153. Assert.AreEqual(-1, container.BinarySearch(-2));
  154. Assert.AreEqual(-1, slice.BinarySearch(-2));
  155. Assert.AreEqual(-1, arrayRo.BinarySearch(-2));
  156. Assert.AreEqual(-2, container.BinarySearch(2));
  157. Assert.AreEqual(-2, slice.BinarySearch(2));
  158. Assert.AreEqual(-2, arrayRo.BinarySearch(2));
  159. container.Dispose();
  160. }
  161. {
  162. var init = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  163. var container = new NativeArray<int>(16, Allocator.Temp);
  164. var slice = new NativeSlice<int>(container, 0, container.Length);
  165. var arrayRo = container.AsReadOnly();
  166. container.CopyFrom(init);
  167. for (int i = 0, num = container.Length; i < num; ++i)
  168. {
  169. Assert.AreEqual(~container.Length, container.BinarySearch(i + 16));
  170. Assert.AreEqual(~slice.Length, slice.BinarySearch(i + 16));
  171. Assert.AreEqual(~arrayRo.Length, arrayRo.BinarySearch(i + 16));
  172. }
  173. container.Dispose();
  174. }
  175. {
  176. var init = new int[] { 0, 2, 4, 6, 8, 10, 12, 14 };
  177. var container = new NativeArray<int>(8, Allocator.Temp);
  178. var slice = new NativeSlice<int>(container, 0, container.Length);
  179. var arrayRo = container.AsReadOnly();
  180. container.CopyFrom(init);
  181. for (int i = 0, num = container.Length; i < num; ++i)
  182. {
  183. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, container.BinarySearch(i * 2 + 1));
  184. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, slice.BinarySearch(i * 2 + 1));
  185. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, arrayRo.BinarySearch(i * 2 + 1));
  186. }
  187. container.Dispose();
  188. }
  189. }
  190. [Test]
  191. public void NativeArraySlice_BinarySearch_NotFound_Reference_ArrayList()
  192. {
  193. {
  194. var reference = new ArrayList();
  195. reference.Add(0);
  196. var container = new NativeArray<int>(1, Allocator.Temp);
  197. var slice = new NativeSlice<int>(container, 0, container.Length);
  198. var arrayRo = container.AsReadOnly();
  199. Assert.AreEqual(container.Length, 1);
  200. Assert.AreEqual(-2, reference.BinarySearch(1));
  201. Assert.AreEqual(-2, container.BinarySearch(1));
  202. Assert.AreEqual(-2, slice.BinarySearch(1));
  203. Assert.AreEqual(-2, arrayRo.BinarySearch(1));
  204. reference[0] = 1;
  205. slice[0] = 1;
  206. Assert.AreEqual(0, reference.BinarySearch(1));
  207. Assert.AreEqual(0, container.BinarySearch(1));
  208. Assert.AreEqual(0, slice.BinarySearch(1));
  209. Assert.AreEqual(0, arrayRo.BinarySearch(1));
  210. Assert.AreEqual(-1, reference.BinarySearch(-2));
  211. Assert.AreEqual(-1, container.BinarySearch(-2));
  212. Assert.AreEqual(-1, slice.BinarySearch(-2));
  213. Assert.AreEqual(-1, arrayRo.BinarySearch(-2));
  214. Assert.AreEqual(-2, reference.BinarySearch(2));
  215. Assert.AreEqual(-2, container.BinarySearch(2));
  216. Assert.AreEqual(-2, slice.BinarySearch(2));
  217. Assert.AreEqual(-2, arrayRo.BinarySearch(2));
  218. }
  219. {
  220. var init = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  221. var container = new NativeArray<int>(16, Allocator.Temp);
  222. var slice = new NativeSlice<int>(container, 0, container.Length);
  223. var arrayRo = container.AsReadOnly();
  224. container.CopyFrom(init);
  225. var reference = new ArrayList(init);
  226. for (int i = 0, num = container.Length; i < num; ++i)
  227. {
  228. Assert.AreEqual(~reference.Count, reference.BinarySearch(i + 16));
  229. Assert.AreEqual(~container.Length, container.BinarySearch(i + 16));
  230. Assert.AreEqual(~slice.Length, slice.BinarySearch(i + 16));
  231. Assert.AreEqual(~arrayRo.Length, arrayRo.BinarySearch(i + 16));
  232. }
  233. }
  234. {
  235. var init = new int[] { 0, 2, 4, 6, 8, 10, 12, 14 };
  236. var container = new NativeArray<int>(8, Allocator.Temp);
  237. var slice = new NativeSlice<int>(container, 0, container.Length);
  238. var arrayRo = container.AsReadOnly();
  239. container.CopyFrom(init);
  240. var reference = new ArrayList(init);
  241. for (int i = 0, num = container.Length; i < num; ++i)
  242. {
  243. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, reference.BinarySearch(i * 2 + 1));
  244. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, container.BinarySearch(i * 2 + 1));
  245. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, slice.BinarySearch(i * 2 + 1));
  246. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, arrayRo.BinarySearch(i * 2 + 1));
  247. }
  248. }
  249. }
  250. <#
  251. {
  252. foreach (var ContainerType in new[] {
  253. ( "NativeList" ),
  254. ( "UnsafeList" ),
  255. }) {
  256. #>
  257. [Test]
  258. public void <#=ContainerType#>_BinarySearch()
  259. {
  260. using (var container = new <#=ContainerType#><int>(16, Allocator.Persistent) { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 })
  261. {
  262. for (int i = 0, num = container.Length; i < num; ++i)
  263. {
  264. Assert.AreEqual(i, container.BinarySearch(container[i]));
  265. }
  266. }
  267. }
  268. [Test]
  269. public void <#=ContainerType#>_BinarySearch_NotFound()
  270. {
  271. {
  272. var container = new <#=ContainerType#><int>(1, Allocator.Temp);
  273. Assert.AreEqual(-1, container.BinarySearch(1));
  274. container.Add(1);
  275. Assert.AreEqual(0, container.BinarySearch(1));
  276. Assert.AreEqual(-1, container.BinarySearch(-2));
  277. Assert.AreEqual(-2, container.BinarySearch(2));
  278. }
  279. using (var container = new <#=ContainerType#><int>(16, Allocator.Temp) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 })
  280. {
  281. for (int i = 0, num = container.Length; i < num; ++i)
  282. {
  283. Assert.AreEqual(~container.Length, container.BinarySearch(i + 16));
  284. }
  285. }
  286. using (var container = new <#=ContainerType#><int>(8, Allocator.Temp) { 0, 2, 4, 6, 8, 10, 12, 14 })
  287. {
  288. for (int i = 0, num = container.Length; i < num; ++i)
  289. {
  290. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, container.BinarySearch(i * 2 + 1));
  291. }
  292. }
  293. }
  294. [Test]
  295. public void <#=ContainerType#>_BinarySearch_NotFound_Reference_ArrayList()
  296. {
  297. {
  298. var reference = new ArrayList();
  299. var container = new <#=ContainerType#><int>(1, Allocator.Temp);
  300. Assert.AreEqual(-1, reference.BinarySearch(1));
  301. Assert.AreEqual(-1, container.BinarySearch(1));
  302. reference.Add(1);
  303. container.Add(1);
  304. Assert.AreEqual(0, reference.BinarySearch(1));
  305. Assert.AreEqual(0, container.BinarySearch(1));
  306. Assert.AreEqual(-1, reference.BinarySearch(-2));
  307. Assert.AreEqual(-1, container.BinarySearch(-2));
  308. Assert.AreEqual(-2, reference.BinarySearch(2));
  309. Assert.AreEqual(-2, container.BinarySearch(2));
  310. }
  311. using (var container = new <#=ContainerType#><int>(16, Allocator.Temp) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 })
  312. {
  313. var reference = new ArrayList() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  314. for (int i = 0, num = container.Length; i < num; ++i)
  315. {
  316. Assert.AreEqual(~reference.Count, reference.BinarySearch(i + 16));
  317. Assert.AreEqual(~container.Length, container.BinarySearch(i + 16));
  318. }
  319. }
  320. using (var container = new <#=ContainerType#><int>(8, Allocator.Temp) { 0, 2, 4, 6, 8, 10, 12, 14 })
  321. {
  322. var reference = new ArrayList() { 0, 2, 4, 6, 8, 10, 12, 14 };
  323. for (int i = 0, num = container.Length; i < num; ++i)
  324. {
  325. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, reference.BinarySearch(i * 2 + 1));
  326. Assert.AreEqual(~(i + 1) /* ~index of first greatest value searched */, container.BinarySearch(i * 2 + 1));
  327. }
  328. }
  329. }
  330. [Test]
  331. public void <#=ContainerType#>_GenericSortJob_NoBurst()
  332. {
  333. <#=ContainerType#>_GenericSortJob();
  334. }
  335. [BurstCompile]
  336. public static void Bursted_<#=ContainerType#>_GenericSortJob()
  337. {
  338. <#=ContainerType#>_GenericSortJob();
  339. }
  340. [Test]
  341. public void <#=ContainerType#>_GenericSortJob_Burst()
  342. {
  343. Bursted_<#=ContainerType#>_GenericSortJob();
  344. }
  345. public static void <#=ContainerType#>_GenericSortJob()
  346. {
  347. using (var container = new <#=ContainerType#><int>(5, Allocator.Persistent))
  348. {
  349. for (var i = 0; i < 5; ++i)
  350. {
  351. container.Add(4 - i);
  352. }
  353. container.Sort();
  354. for (var i = 0; i < 5; ++i)
  355. {
  356. Assert.AreEqual(i, container[i]);
  357. }
  358. }
  359. using (var container = new <#=ContainerType#><int>(5, Allocator.Persistent))
  360. {
  361. for (var i = 0; i < 5; ++i)
  362. {
  363. container.Add(4 - i);
  364. }
  365. container.SortJob().Schedule().Complete();
  366. for (var i = 0; i < 5; ++i)
  367. {
  368. Assert.AreEqual(i, container[i]);
  369. }
  370. }
  371. }
  372. [Test]
  373. [TestRequiresDotsDebugOrCollectionChecks]
  374. public void <#=ContainerType#>_GenericSortJobCustomComparer_NoBurst()
  375. {
  376. <#=ContainerType#>_GenericSortJobCustomComparer();
  377. }
  378. [BurstCompile]
  379. public static void Bursted_<#=ContainerType#>_GenericSortJobCustomComparer()
  380. {
  381. <#=ContainerType#>_GenericSortJobCustomComparer();
  382. }
  383. [Test]
  384. [TestRequiresDotsDebugOrCollectionChecks]
  385. public void <#=ContainerType#>_GenericSortJobCustomComparer_Burst()
  386. {
  387. Bursted_<#=ContainerType#>_GenericSortJobCustomComparer();
  388. }
  389. public static void <#=ContainerType#>_GenericSortJobCustomComparer()
  390. {
  391. var num = 35;
  392. using (var container = new <#=ContainerType#><int>(num, Allocator.Persistent))
  393. {
  394. for (var i = 0; i < num; ++i)
  395. {
  396. container.Add(i);
  397. }
  398. Assert.Throws<InvalidOperationException>(() => container.Sort(new BrokenComparer0<int>()));
  399. Assert.Throws<InvalidOperationException>(() => container.Sort(new BrokenComparer1<int>()));
  400. Assert.Throws<InvalidOperationException>(() => container.Sort(new BrokenComparer2<int>()));
  401. Assert.Throws<InvalidOperationException>(() => container.Sort(new BrokenComparer3<int>()));
  402. container.Sort(new DescendingComparer<int>());
  403. for (var i = 0; i < num; ++i)
  404. {
  405. Assert.AreEqual(num - 1 - i, container[i]);
  406. }
  407. }
  408. using (var container = new <#=ContainerType#><int>(num, Allocator.Persistent))
  409. {
  410. for (var i = 0; i < num; ++i)
  411. {
  412. container.Add(i);
  413. }
  414. Assert.Throws<InvalidOperationException>(() => container.SortJob(new BrokenComparer0<int>()).Schedule().Complete());
  415. Assert.Throws<InvalidOperationException>(() => container.SortJob(new BrokenComparer1<int>()).Schedule().Complete());
  416. Assert.Throws<InvalidOperationException>(() => container.SortJob(new BrokenComparer2<int>()).Schedule().Complete());
  417. Assert.Throws<InvalidOperationException>(() => container.SortJob(new BrokenComparer3<int>()).Schedule().Complete());
  418. container.SortJob(new DescendingComparer<int>()).Schedule().Complete();
  419. for (var i = 0; i < num; ++i)
  420. {
  421. Assert.AreEqual(num - 1 - i, container[i]);
  422. }
  423. }
  424. }
  425. <#}}#>
  426. <#
  427. {
  428. foreach (var ContainerType in new[] {
  429. ( "FixedList32Bytes" ),
  430. ( "FixedList64Bytes" ),
  431. ( "FixedList128Bytes" ),
  432. ( "FixedList512Bytes" ),
  433. ( "FixedList4096Bytes" ),
  434. }) {
  435. #>
  436. [Test]
  437. public void <#=ContainerType#>_GenericSort()
  438. {
  439. var container = new <#=ContainerType#><int>();
  440. for (var i = 0; i < 5; ++i)
  441. {
  442. container.Add(i);
  443. }
  444. container.Sort(new DescendingComparer<int>());
  445. for (var i = 0; i < 5; ++i)
  446. {
  447. Assert.AreEqual(4 - i, container[i]);
  448. }
  449. }
  450. <#}}#>
  451. unsafe static void IntroSortNoComparerCheck<T, U>(T* array, int length, U comp)
  452. where T : unmanaged
  453. where U : IComparer<T>
  454. {
  455. NativeSortExtension.IntroSort_R<T, U>(array, 0, length - 1, 2 * CollectionHelper.Log2Floor(length), comp);
  456. }
  457. [Test]
  458. [TestRequiresDotsDebugOrCollectionChecks]
  459. public unsafe void NativeList_BrokenCustomComparerDoesNotCrash()
  460. {
  461. var rng = new Unity.Mathematics.Random(1);
  462. var num = 10000;
  463. using (var container = new NativeList<int>(num, Allocator.Persistent))
  464. {
  465. for (var i = 0; i < num; ++i)
  466. {
  467. container.Add(rng.NextInt());
  468. }
  469. Assert.DoesNotThrow(() => IntroSortNoComparerCheck(container.GetUnsafePtr(), container.Length, new BrokenComparer0<int>()));
  470. }
  471. using (var container = new NativeList<int>(num, Allocator.Persistent))
  472. {
  473. for (var i = 0; i < num; ++i)
  474. {
  475. container.Add(rng.NextInt());
  476. }
  477. Assert.DoesNotThrow(() => IntroSortNoComparerCheck(container.GetUnsafePtr(), container.Length, new BrokenComparer1<int>()));
  478. }
  479. using (var container = new NativeList<int>(num, Allocator.Persistent))
  480. {
  481. for (var i = 0; i < num; ++i)
  482. {
  483. container.Add(rng.NextInt());
  484. }
  485. Assert.DoesNotThrow(() => IntroSortNoComparerCheck(container.GetUnsafePtr(), container.Length, new BrokenComparer2<int>()));
  486. }
  487. using (var container = new NativeList<int>(num, Allocator.Persistent))
  488. {
  489. for (var i = 0; i < num; ++i)
  490. {
  491. container.Add(rng.NextInt());
  492. }
  493. Assert.DoesNotThrow(() => IntroSortNoComparerCheck(container.GetUnsafePtr(), container.Length, new BrokenComparer3<int>()));
  494. }
  495. }
  496. }