Ei kuvausta
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.

NativeParallelHashSetTests.tt 7.2KB

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