public void CountDecreasesAfterRemoving() { var hashTable = new HashTable <int, int>(); var n = 10; for (int i = 0; i < n; i++) { hashTable.Add(i, i); } var m = 4; for (int i = 0; i < m; i++) { hashTable.Remove(i); } Assert.AreEqual(hashTable.Count, n - m); }
public void HashTableAddManyFindOne() { int amount = 10000; var hashTable = new HashTable(amount * 10); var rand = new Random(); var key = rand.Next(amount); var valueToFind = 0; for (int i = 0; i < amount; i++) { var value = rand.Next(); if (i == key) { valueToFind = value; } hashTable[i] = value; } Assert.AreEqual(valueToFind, hashTable[key]); }
public void CanShowLinkedListInCollsion() { HashTable hash = new HashTable(); hash.Add("one", 1); hash.Add("two", 2); hash.Add("three", 3); hash.Add("eerht", 1001); hash.Add("hreet", 1002); hash.Add("ereth", 1003); int index = 0; foreach (char item in "three") { index += item; } index = (index * 599) / 1024; Assert.Equal(1003, hash.HashArray[index].Value); Assert.Equal(1002, hash.HashArray[index].Next.Value); Assert.Equal(1001, hash.HashArray[index].Next.Next.Value); Assert.Equal(3, hash.HashArray[index].Next.Next.Next.Value); }
public void Initialize() { Hash1 temp = new Hash1(); ht = new HashTable(temp); }