public void TestGetOrAdd() { var table = new SlimHashTable <string, MyTestType>(x => x.Key, 10); var item = new MyTestType("test", 5); var result = table.GetOrAdd(item.Key, item); Assert.IsTrue(ReferenceEquals(item, result)); var item2 = new MyTestType("test", 5); var result2 = table.GetOrAdd(item2.Key, item2); Assert.IsTrue(ReferenceEquals(item, result2)); }
public void TestUpdateOrAdd() { var table = new SlimHashTable <string, MyTestType>(x => x.Key, 10); var item = new MyTestType("test", 5); table.UpdateOrAdd(item.Key, item); Assert.IsTrue(ReferenceEquals(item, table[item.Key])); var item2 = new MyTestType("test", 5); table.UpdateOrAdd(item2.Key, item2); Assert.IsTrue(ReferenceEquals(item2, table[item.Key])); }
public void TestGetHashCodeCalls() { var table = new SlimHashTable <MyTestType, MyTestType>(x => x, 10); var item = new MyTestType("test", 5); Assert.AreEqual(0, item.HashCodeCallCount); table.Add(item); Assert.AreEqual(1, item.HashCodeCallCount); // Add 100 elements to force a grow call for (var i = 0; i < 100; i++) { table.Add(new MyTestType(i.ToString(), i)); } // Assert Assert.AreEqual(1, item.HashCodeCallCount); }