public void SearchingOneElement() { var rnd = new Random(); var List = new HashTableList(10000); var toFindKey = RandomString(10); var toFindValue = RandomString(10); var put = rnd.Next(0, 1000); for (int i = 0; i < 10000; i++) { if (i == put) { List.PutPair(toFindKey, toFindValue); } else { List.PutPair(RandomString(5), RandomString(5)); } } Assert.AreEqual(toFindValue, List.GetValueByKey(toFindKey)); for (int i = 1; i < 10000; i++) { List.PutPair(RandomString(10), RandomString(10)); } Assert.AreEqual(toFindValue, List.GetValueByKey(toFindKey)); }
public static void run() { #region Hash Table Test Console.WriteLine("\n----------------Hash Table Test-----------------"); Console.WriteLine("-------Hash Table Array Test:"); HashTableArray <string> tableArray = new HashTableArray <string>(3); tableArray.Add(312, "abcbca"); tableArray.Add(123, "qwer"); tableArray.Add(2, "qw"); tableArray.View(); Console.WriteLine("\nHash-table after removing by key 123:"); tableArray.Remove(123); tableArray.View(); Console.WriteLine("\n------Hash Table List Test:"); HashTableList <string> tableList = new HashTableList <string>(5); tableList.Add(1, "abc"); tableList.Add(6, "abc"); tableList.Add(11, "abc"); tableList.Add(16, "a"); tableList.Add(0, "bc"); tableList.View(); Console.WriteLine("\nHash-table after removing by key 11 & 0:"); tableList.Remove(11); tableList.Remove(0); tableList.View(); #endregion }
public void AddingTheSameElement() { var List = new HashTableList(2); List.PutPair("BMW", "E39"); List.PutPair("BMW", "M5"); Assert.AreEqual("M5", List.GetValueByKey("BMW")); }
public void ThreeElements() { var List = new HashTableList(3); List.PutPair("BMW", "E39"); List.PutPair("Audi", "A6"); List.PutPair("JDM", "Tourer V"); Assert.AreEqual("E39", List.GetValueByKey("BMW")); Assert.AreEqual("A6", List.GetValueByKey("Audi")); Assert.AreEqual("Tourer V", List.GetValueByKey("JDM")); }
static void Main(string[] args) { var List = new HashTableList(3); List.PutPair("BMW", "E39"); List.PutPair("Audi", "A6"); List.PutPair("JDM", "Tourer V"); List.PutPair("Mercedes", "V-klasse"); List.PutPair("BMW", "M5"); Console.WriteLine(List.GetValueByKey("Mercedes")); Console.WriteLine(List.GetValueByKey("BMW")); Console.WriteLine(List.GetValueByKey("Audi")); Console.WriteLine(List.GetValueByKey("JDM")); }