public void PooledHashSet_Serialization() { var ms = new MemoryStream(); using (var obj = PooledHashSet <string> .New()) { var set = obj.HashSet; set.Add("qux"); set.Add("foo"); set.Add("bar"); set.Add("baz"); var fmt = new BinaryFormatter(); fmt.Serialize(ms, set); } ms.Position = 0; { var fmt = new BinaryFormatter(); var set = (PooledHashSet <string>)fmt.Deserialize(ms); Assert.IsTrue(set.SetEquals(exp)); set.Free(); // no-op but doesn't throw } }
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_GlobalPool() { for (var i = 0; i < 100; i++) { using var obj = PooledHashSet <string> .New(); var set = obj.HashSet; Assert.AreEqual(0, set.Count); set.Add("qux"); set.Add("foo"); set.Add("bar"); set.Add("baz"); Assert.IsTrue(set.SetEquals(exp)); } }
private static void PooledHashSet_Simple_Impl(HashSetPool <string> pool) { for (var i = 0; i < 100; i++) { using var obj = i % 2 == 0 ? pool.New() : PooledHashSet <string> .New(pool); var set = obj.HashSet; Assert.AreEqual(0, set.Count); set.Add("qux"); set.Add("foo"); set.Add("bar"); set.Add("baz"); Assert.IsTrue(set.SetEquals(exp)); } }