public static void TestSetResizing()
{
Random random = new Random(5);
UnsafeBufferPool<int> pool = new UnsafeBufferPool<int>();
QuickSet<int> set = new QuickSet<int>(pool, pool);
HashSet<int> controlSet = new HashSet<int>();
for (int iterationIndex = 0; iterationIndex < 100000; ++iterationIndex)
{
if (random.NextDouble() < 0.7)
{
set.Add(iterationIndex);
controlSet.Add(iterationIndex);
}
if (random.NextDouble() < 0.2)
{
var indexToRemove = random.Next(set.Count);
var toRemove = set[indexToRemove];
set.FastRemove(toRemove);
controlSet.Remove(toRemove);
}
if (iterationIndex % 1000 == 0)
{
set.EnsureCapacity(set.Count * 3);
}
else if (iterationIndex % 7777 == 0)
{
set.Compact();
}
}
Assert.IsTrue(set.Count == controlSet.Count);
for (int i = 0; i < set.Count; ++i)
{
Assert.IsTrue(controlSet.Contains(set[i]));
}
foreach (var element in controlSet)
{
Assert.IsTrue(set.Contains(element));
}
}