private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <HashSet <int>, int> test) { var pool = HashSetPool <int> .Create(C); void testCore(HashSet <int> set) { var len = set.Count; Assert.AreEqual(0, len); var L = test(set); len = set.Count; Assert.AreEqual(L, len); } if (useRAII) { Run(() => pool.New(), o => o.HashSet, o => o.Dispose(), testCore, P, M, noisy); } else { Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy); } }
public void PooledHashSet_GottenTooBig() { var bigPool = HashSetPool <int> .Create(1, EqualityComparer <int> .Default, 2048); var smallPool = HashSetPool <int> .Create(1, EqualityComparer <int> .Default, 16); TooBig(() => PooledHashSet <int> .New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 1024); TooBig(() => bigPool.New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 2048); TooBig(() => smallPool.New(), h => h.HashSet, (h, n) => h.UnionWith(Enumerable.Range(0, n)), 16); }
public void PooledHashSet_ArgumentChecking() { Assert.ThrowsException <ArgumentNullException>(() => HashSetPool <string> .Create(4, comparer: null)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => HashSetPool <string> .Create(4, EqualityComparer <string> .Default, -1)); }
public void PooledHashSet_Simple2() { var pool = HashSetPool <string> .Create(4, EqualityComparer <string> .Default); PooledHashSet_Simple_Impl(pool); }
public void PooledHashSet_Simple1() { var pool = HashSetPool <string> .Create(4); PooledHashSet_Simple_Impl(pool); }