public void ConstructorTest() { var count = UnsafeHashCollection.GetNextPrime(10); var set = UnsafeDictionary.Allocate <int, bool>(10); Assert.AreEqual(0, UnsafeDictionary.GetCount(set)); Assert.AreEqual(count, UnsafeDictionary.GetCapacity(set)); UnsafeDictionary.Free(set); }
public void ExpandTest() { int count = UnsafeHashCollection.GetNextPrime(8); var set = UnsafeDictionary.Allocate <int, short>(count, fixedSize: false); // Valid adds for (int i = 0; i < 8; i++) { UnsafeDictionary.Add <int, short>(set, i + 1, 2); } Assert.AreEqual(8, UnsafeDictionary.GetCount(set)); Assert.AreEqual(count, UnsafeDictionary.GetCapacity(set)); UnsafeDictionary.Add <int, short>(set, 42, 12); Assert.AreEqual(9, UnsafeDictionary.GetCount(set)); Assert.AreEqual(count, UnsafeDictionary.GetCapacity(set)); UnsafeDictionary.Free(set); }
public void ExpandFailedTest() { var count = UnsafeHashCollection.GetNextPrime(7); var set = UnsafeDictionary.Allocate <int, float>(7, true); // Valid adds for (int i = 0; i < 7; i++) { UnsafeDictionary.Add <int, float>(set, i + 1, i * i); } Assert.AreEqual(7, UnsafeDictionary.GetCount(set)); Assert.AreEqual(7, UnsafeDictionary.GetCapacity(set)); Assert.Throws <InvalidOperationException>(() => { UnsafeDictionary.Add <int, float>(set, 42, 13.3f); }); UnsafeDictionary.Free(set); }
public void ExpandTest() { var initialCapacity = 7; var set = UnsafeHashSet.Allocate <int>(initialCapacity, fixedSize: false); // Valid adds for (int i = 0; i < initialCapacity; i++) { UnsafeHashSet.Add(set, i + 1); } Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCount(set)); Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCapacity(set)); UnsafeHashSet.Add(set, 42); UnsafeHashSet.Add(set, 18); var nextCapacity = UnsafeHashCollection.GetNextPrime(initialCapacity + 1); Assert.AreEqual(9, UnsafeHashSet.GetCount(set)); Assert.AreEqual(nextCapacity, UnsafeHashSet.GetCapacity(set)); UnsafeHashSet.Free(set); }