public void SeparateChainingMaintenanceHashTable() { var sut = new SeparateChainingHashTable <string, int>(100000); for (var i = 0; i < 100000; i++) { sut.Add(i.ToString(CultureInfo.InvariantCulture), i); } for (var i = 0; i < 100000; i++) { Assert.Equal(i, sut.Get(i.ToString(CultureInfo.InvariantCulture))); } for (var i = 0; i < 100000; i++) { sut.Add(i.ToString(CultureInfo.InvariantCulture), i * 2); } for (var i = 0; i < 100000; i++) { Assert.Equal(i * 2, sut.Get(i.ToString(CultureInfo.InvariantCulture))); } for (var i = 0; i < 100000; i++) { sut.Delete(i.ToString(CultureInfo.InvariantCulture)); } for (var i = 0; i < 100000; i++) { Assert.False(sut.Find(i.ToString(CultureInfo.InvariantCulture))); } }
public void CanUpdateHashEntryValue() { var sut = new SeparateChainingHashTable <string, int>(2); sut.Add("One", 1); sut.Add("Two", 2); sut.Add("Two", 3); Assert.Equal(3, sut.Get("Two")); }
public void Container_SeparateChainingHashTable() { // Arrange SeparateChainingHashTable <int, string> separateChainingHashTable = new SeparateChainingHashTable <int, string>(); // Act for (int i = 0; i < 100; i++) { separateChainingHashTable.Add(i, i.ToString()); } Container <int, string> container = new Container <int, string>(separateChainingHashTable); container.RemoveByKey(20); container.RemoveByKey(80); // Assert for (int i = 0; i < 100; i++) { if (i != 20 && i != 80) { Assert.AreEqual(container.GetValue(i), i.ToString()); } else { Assert.AreEqual(container.GetValue(i), default); } } }
public void SeparateChainingHashTable_GetAddRemove() { // Arrange var hashTable = new SeparateChainingHashTable <int, string>(); // Act for (int i = 0; i < 100; i++) { hashTable.Add(i, i.ToString()); } hashTable.Remove(50); hashTable.Remove(40); // Assert for (int i = 0; i < 100; i++) { if (i != 40 && i != 50) { Assert.AreEqual(i.ToString(), hashTable.Get(i)); } else { Assert.AreEqual(null, hashTable.Get(i)); } } }
public void CanGetEntryFromHashTable() { var sut = new SeparateChainingHashTable <string, int>(); sut.Add("One", 1); Assert.True(sut.Find("One")); }
public void FindForNonExistingEntryReturnFalse() { var sut = new SeparateChainingHashTable <string, int>(); sut.Add("One", 1); Assert.False(sut.Find("Two")); }
public void CanDeleteNonExistingEntryFromHashTable() { var sut = new SeparateChainingHashTable <string, int>(); sut.Add("One", 1); sut.Delete("Two"); }
public void CanDeleteEntryFromHashTable() { #pragma warning disable HAA0302 // Display class allocation to capture closure var sut = new SeparateChainingHashTable <string, int>(); #pragma warning restore HAA0302 // Display class allocation to capture closure sut.Add("One", 1); sut.Delete("One"); #pragma warning disable HAA0301 // Closure Allocation Source _ = Assert.Throws <ArgumentException>(() => sut.Get("One")); #pragma warning restore HAA0301 // Closure Allocation Source }
public void CanAddEntryToHashTable() { var sut = new SeparateChainingHashTable <string, int>(); sut.Add("One", 1); }