public void TestHashIndexNumber1() { HashTable2 testHashTable1 = new HashTable2(); int htAnswer1 = testHashTable1.Hash("a"); Assert.Equal(97, htAnswer1); }
public void TestHashIndexNumber2() { HashTable2 testHashTable2 = new HashTable2(); int htAnswer2 = testHashTable2.Hash("}}}}}}}}y"); Assert.Equal(97, htAnswer2); }
public static string RepeatedWord(string str) { //put the words into an array HashTable2 hTable = new HashTable2(); string[] strArr = new string[str.Length]; string pattern = @"\W"; strArr = Regex.Split(str, pattern); //hashes each word from the array foreach (var item in strArr) { string itemToUpper = item.ToUpper(); if (hTable.HashTableArray[hTable.Hash(itemToUpper)] == null || hTable.HashTableArray[hTable.Hash(itemToUpper)].Head.Key == "") { hTable.AddToHashTable(itemToUpper, itemToUpper); //i want the value to be the same as the key for this } else if (hTable.HashTableContains(itemToUpper) == true) { return(item); } } //means went through all the words and didn't find a collision therefore returning and exiting before this point, so no duplicates Console.WriteLine("There were no duplicate words in this string"); return(null); }