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 TryGetValueTest() { var set = UnsafeDictionary.Allocate <int, int>(10); Assert.IsFalse(UnsafeDictionary.TryGetValue(set, 1, out int value)); UnsafeDictionary.Add(set, 1, 1); UnsafeDictionary.Add(set, 7, 2); UnsafeDictionary.Add(set, 51, 3); UnsafeDictionary.Add(set, 13, 4); Assert.IsFalse(UnsafeDictionary.TryGetValue(set, 3, out value)); Assert.IsTrue(UnsafeDictionary.TryGetValue(set, 1, out value)); Assert.AreEqual(1, value); Assert.IsTrue(UnsafeDictionary.TryGetValue(set, 7, out value)); Assert.AreEqual(2, value); Assert.IsTrue(UnsafeDictionary.TryGetValue(set, 13, out value)); Assert.AreEqual(4, value); Assert.IsTrue(UnsafeDictionary.TryGetValue(set, 51, out value)); Assert.AreEqual(3, value); Assert.IsFalse(UnsafeDictionary.TryGetValue(set, 14, out value)); UnsafeDictionary.Free(set); }
public void SetterTest() { var set = UnsafeDictionary.Allocate <int, int>(4); UnsafeDictionary.Add(set, 1, 1); UnsafeDictionary.Add(set, 7, 2); // Add new key UnsafeDictionary.Set(set, 2, 412); Assert.IsTrue(UnsafeDictionary.TryGetValue <int, int>(set, 2, out int valNew)); Assert.AreEqual(412, valNew); // Overwrite existing key UnsafeDictionary.Set(set, 1, 333); Assert.IsTrue(UnsafeDictionary.TryGetValue <int, int>(set, 1, out int valExist)); Assert.AreEqual(333, valExist); }