Nessuna descrizione
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.

NativeHashSetTests.tt 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 System;
  6. using NUnit.Framework;
  7. using Unity.Collections;
  8. using Unity.Collections.LowLevel.Unsafe;
  9. using Unity.Collections.Tests;
  10. internal class NativeHashSetTestsGenerated : CollectionsTestFixture
  11. {
  12. <#
  13. {
  14. foreach (var ContainerType in new[] {
  15. ( "NativeHashSet" ),
  16. ( "UnsafeHashSet" ),
  17. }) {
  18. #>
  19. static void ExpectedCount<T>(ref <#=ContainerType#><T> container, int expected)
  20. where T : unmanaged, IEquatable<T>
  21. {
  22. Assert.AreEqual(expected == 0, container.IsEmpty);
  23. Assert.AreEqual(expected, container.Count);
  24. }
  25. <#
  26. foreach (var OtherContainerType in new[] {
  27. ( "NativeHashSet" ),
  28. ( "UnsafeHashSet" ),
  29. ( "NativeParallelHashSet" ),
  30. ( "UnsafeParallelHashSet" ),
  31. ( "NativeList" ),
  32. ( "UnsafeList" ),
  33. }) {
  34. #>
  35. [Test]
  36. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_ExceptWith_Empty()
  37. {
  38. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  39. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  40. container.ExceptWith(other);
  41. ExpectedCount(ref container, 0);
  42. container.Dispose();
  43. other.Dispose();
  44. }
  45. [Test]
  46. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_ExceptWith_AxB()
  47. {
  48. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  49. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { 3, 4, 5, 6, 7, 8 };
  50. container.ExceptWith(other);
  51. ExpectedCount(ref container, 3);
  52. Assert.True(container.Contains(0));
  53. Assert.True(container.Contains(1));
  54. Assert.True(container.Contains(2));
  55. container.Dispose();
  56. other.Dispose();
  57. }
  58. [Test]
  59. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_IntersectWith_Empty()
  60. {
  61. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  62. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  63. container.IntersectWith(other);
  64. ExpectedCount(ref container, 0);
  65. container.Dispose();
  66. other.Dispose();
  67. }
  68. [Test]
  69. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_IntersectWith()
  70. {
  71. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  72. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { 3, 4, 5, 6, 7, 8 };
  73. container.IntersectWith(other);
  74. ExpectedCount(ref container, 3);
  75. Assert.True(container.Contains(3));
  76. Assert.True(container.Contains(4));
  77. Assert.True(container.Contains(5));
  78. container.Dispose();
  79. other.Dispose();
  80. }
  81. [Test]
  82. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_UnionWith_Empty()
  83. {
  84. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  85. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  86. container.UnionWith(other);
  87. ExpectedCount(ref container, 0);
  88. container.Dispose();
  89. other.Dispose();
  90. }
  91. [Test]
  92. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_UnionWith()
  93. {
  94. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  95. var other = new <#=OtherContainerType#><int>(8, CommonRwdAllocator.Handle) { 3, 4, 5, 6, 7, 8 };
  96. container.UnionWith(other);
  97. ExpectedCount(ref container, 9);
  98. Assert.True(container.Contains(0));
  99. Assert.True(container.Contains(1));
  100. Assert.True(container.Contains(2));
  101. Assert.True(container.Contains(3));
  102. Assert.True(container.Contains(4));
  103. Assert.True(container.Contains(5));
  104. Assert.True(container.Contains(6));
  105. Assert.True(container.Contains(7));
  106. Assert.True(container.Contains(8));
  107. container.Dispose();
  108. other.Dispose();
  109. }
  110. <#}#>
  111. <#
  112. foreach (var OtherContainerType in new[] {
  113. ( "FixedList32Bytes" ),
  114. ( "FixedList64Bytes" ),
  115. ( "FixedList128Bytes" ),
  116. ( "FixedList512Bytes" ),
  117. ( "FixedList4096Bytes" ),
  118. }) {
  119. #>
  120. [Test]
  121. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_ExceptWith_Empty()
  122. {
  123. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  124. var other = new <#=OtherContainerType#><int>() { };
  125. container.ExceptWith(other);
  126. ExpectedCount(ref container, 0);
  127. container.Dispose();
  128. }
  129. [Test]
  130. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_ExceptWith_AxB()
  131. {
  132. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  133. var other = new <#=OtherContainerType#><int>() { 3, 4, 5, 6, 7, 8 };
  134. container.ExceptWith(other);
  135. ExpectedCount(ref container, 3);
  136. Assert.True(container.Contains(0));
  137. Assert.True(container.Contains(1));
  138. Assert.True(container.Contains(2));
  139. container.Dispose();
  140. }
  141. [Test]
  142. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_IntersectWith_Empty()
  143. {
  144. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  145. var other = new <#=OtherContainerType#><int>() { };
  146. container.IntersectWith(other);
  147. ExpectedCount(ref container, 0);
  148. container.Dispose();
  149. }
  150. [Test]
  151. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_IntersectWith()
  152. {
  153. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  154. var other = new <#=OtherContainerType#><int>() { 3, 4, 5, 6, 7, 8 };
  155. container.IntersectWith(other);
  156. ExpectedCount(ref container, 3);
  157. Assert.True(container.Contains(3));
  158. Assert.True(container.Contains(4));
  159. Assert.True(container.Contains(5));
  160. container.Dispose();
  161. }
  162. [Test]
  163. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_UnionWith_Empty()
  164. {
  165. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { };
  166. var other = new <#=OtherContainerType#><int>() { };
  167. container.UnionWith(other);
  168. ExpectedCount(ref container, 0);
  169. container.Dispose();
  170. }
  171. [Test]
  172. public void <#=ContainerType#>_<#=OtherContainerType#>_EIU_UnionWith()
  173. {
  174. var container = new <#=ContainerType#><int>(8, CommonRwdAllocator.Handle) { 0, 1, 2, 3, 4, 5 };
  175. var other = new <#=OtherContainerType#><int>() { 3, 4, 5, 6, 7, 8 };
  176. container.UnionWith(other);
  177. ExpectedCount(ref container, 9);
  178. Assert.True(container.Contains(0));
  179. Assert.True(container.Contains(1));
  180. Assert.True(container.Contains(2));
  181. Assert.True(container.Contains(3));
  182. Assert.True(container.Contains(4));
  183. Assert.True(container.Contains(5));
  184. Assert.True(container.Contains(6));
  185. Assert.True(container.Contains(7));
  186. Assert.True(container.Contains(8));
  187. container.Dispose();
  188. }
  189. <#}}}#>
  190. }