public void ClearDictionary() { var map = UnsafeDictionary.Allocate <int, int>(16, fixedSize: false); for (int i = 0; i < 3; i++) { UnsafeDictionary.Add(map, i, 3); } Assert.IsTrue(UnsafeDictionary.ContainsKey(map, 2)); Assert.AreEqual(3, UnsafeDictionary.GetCount(map)); UnsafeDictionary.TryGetValue(map, 2, out int result); Assert.AreEqual(3, result); UnsafeDictionary.Add(map, 3, 1); Assert.AreEqual(4, UnsafeDictionary.GetCount(map)); UnsafeDictionary.Clear(map); Assert.AreEqual(0, UnsafeDictionary.GetCount(map)); Assert.IsFalse(UnsafeDictionary.ContainsKey(map, 2)); UnsafeDictionary.Add(map, 3, 10); Assert.AreEqual(1, UnsafeDictionary.GetCount(map)); Assert.IsTrue(UnsafeDictionary.ContainsKey(map, 3)); UnsafeDictionary.TryGetValue(map, 3, out int result2); Assert.AreEqual(10, result2); UnsafeDictionary.Clear(map); Assert.AreEqual(0, UnsafeDictionary.GetCount(map)); UnsafeDictionary.Free(map); }
public void CopyToTest() { var set = UnsafeDictionary.Allocate <int, decimal>(10); // Fill set for (int i = 0; i < 10; i++) { UnsafeDictionary.Add <int, decimal>(set, i, i * i * i); } var count = UnsafeDictionary.GetCount(set); var arr = new KeyValuePair <int, decimal> [count]; UnsafeDictionary.CopyTo(set, arr, 0); // Check int num = 0; for (int i = 0; i < count; i++) { Assert.AreEqual(i, arr[num].Key); Assert.AreEqual(i * i * i, arr[num++].Value); } UnsafeDictionary.Free(set); }
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); }