Ejemplo n.º 1
0
    public void UnsafeHashSet_ForEach([Values(10, 1000)] int n)
    {
        var seen = new NativeArray <int>(n, Allocator.Temp);

        using (var container = new UnsafeHashSet <int>(32, Allocator.TempJob))
        {
            for (int i = 0; i < n; i++)
            {
                container.Add(i);
            }

            var count = 0;
            foreach (var item in container)
            {
                Assert.True(container.Contains(item));
                seen[item] = seen[item] + 1;
                ++count;
            }

            Assert.AreEqual(container.Count(), count);
            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(1, seen[i], $"Incorrect item count {i}");
            }
        }
    }
 public void UnsafeHashSet_ToArray()
 {
     using (var set = new UnsafeHashSet <int>(8, Allocator.TempJob)
     {
         0, 1, 2, 3, 4, 5
     })
     {
         var array = set.ToArray();
         Array.Sort(array);
         for (int i = 0, num = set.Count(); i < num; i++)
         {
             Assert.AreEqual(array[i], i);
         }
     }
 }
Ejemplo n.º 3
0
 static void ExpectedCount <T>(ref UnsafeHashSet <T> container, int expected)
     where T : unmanaged, IEquatable <T>
 {
     Assert.AreEqual(expected == 0, container.IsEmpty);
     Assert.AreEqual(expected, container.Count());
 }