/// <summary> /// This test demonstrates how the hashtable handles null keys and null values. /// </summary> public void Test5() { Table <string, string> myHashTable = TableFactory.Make <string, string>(4, 0.5); Console.WriteLine("This test will check null keys and null values."); try { Console.WriteLine("\nAdding null as key and value"); myHashTable.Put(null, null); Console.WriteLine("\nCalling Contains function with null parameter"); myHashTable.Contains(null); Console.WriteLine("\nAdding a key with a null value in the hashtable: "); myHashTable.Put("Amy", null); Console.WriteLine("Fetching key with null"); Console.WriteLine("Amy : " + myHashTable.Get("Amy")); Console.WriteLine("TestCase completed"); } catch (ArgumentNullException ane) { Console.WriteLine(ane.Message); } }
private void Test2() { try { Console.WriteLine("This test case checks if a key is present in the hastTable or not. " + "Throws NonExistentKey exception if an exception occurs in Get method"); Table <string, int> myHashTable = TableFactory.Make <string, int>(10, 0.5); myHashTable.Put("1234", 1234); myHashTable.Put("4321", 4321); myHashTable.Put("4321", 1234); myHashTable.Put("Goku", 1234); myHashTable.Put("Saiyan", 1234); foreach (string key in myHashTable) { Console.WriteLine(key + " -> " + myHashTable.Get(key)); } Console.WriteLine("Check value of key - Saiyan in hashTable"); Console.WriteLine(myHashTable.Get("Saiyan")); myHashTable.Get("Husky"); } catch (NonExistentKey <String> nek) { Console.WriteLine(nek.Message); Console.WriteLine(nek.StackTrace); } Console.WriteLine("TestCase completed"); }
public void Test6() { Table <int, int> myHashTable = TableFactory.Make <int, int>(10, 0.45); Console.WriteLine("This test case test chaining"); for (int i = 0; i < 1000; i += 10) { myHashTable.Put(i, i); } Console.WriteLine("Enumerating through the hashtable"); foreach (int key in myHashTable) { Console.WriteLine(key + " : " + myHashTable.Get(key)); } Console.WriteLine("TestCase completed"); }
/// <summary> /// This test case has been taken from Prakash Mishra (pm1739). I don't own this test case. /// </summary> private void Test4() { Table <String, String> ht = TableFactory.Make <String, String>(6, 0.5); Console.WriteLine("This is to make sure that rehashing works properly"); ht.Put("Betty", "boop"); ht.Put("Buggs", "Bunny"); ht.Put("Charlie", "Brown"); ht.Put("Duffy", "Duck"); ht.Put("Dennis", "The Mennace"); ht.Put("Donald", "Duck"); ht.Put("Garfield", "MickeyMouse"); ht.Put("Olive", "Oyl"); ht.Put("Popeye", "Tailorman"); ht.Put("Powerpuff", "Girls"); ht.Put("Road", "Runner"); ht.Put("Scooby", "Doo"); ht.Put("Snoopy", "Dog"); ht.Put("Ninja", "Turtle"); ht.Put("The", "Simpsons"); ht.Put("Tom", "Jerry"); ht.Put("Yogi", "Bear"); try { foreach (String first in ht) { Console.WriteLine(first + " -> " + ht.Get(first)); } Console.WriteLine("========================="); } catch (NonExistentKey <String> nek) { Console.WriteLine(nek.Message); Console.WriteLine(nek.StackTrace); } Console.WriteLine("TestCase completed"); }
private void Test1() { Console.WriteLine("This test case is not written by me. Prof Brown owns this. This has" + " general test cases"); Table <String, String> ht = TableFactory.Make <String, String>(4, 0.5); ht.Put("Joe", "Doe"); ht.Put("Jane", "Brain"); ht.Put("Chris", "Swiss"); try { foreach (String first in ht) { Console.WriteLine(first + " -> " + ht.Get(first)); } Console.WriteLine("========================="); ht.Put("Wavy", "Gravy"); ht.Put("Chris", "Bliss"); foreach (String first in ht) { Console.WriteLine(first + " -> " + ht.Get(first)); } Console.WriteLine("========================="); Console.Write("Jane -> "); Console.WriteLine(ht.Get("Jane")); Console.Write("John -> "); Console.WriteLine(ht.Get("John")); } catch (NonExistentKey <String> nek) { Console.WriteLine(nek.Message); Console.WriteLine(nek.StackTrace); } Console.WriteLine("TestCase completed"); }
/// <summary> /// This test case has been shared with Prakash Mishra (pm1739) and Devavrat Kalam(dk2792). /// </summary> public void Test3() { Console.WriteLine("This test case checkes performance of my hashtable. " + "It also feeds hashtable with size having negative values and loadThreshold "); DateTime start = DateTime.Now; Console.WriteLine("Testing hashTable with threshold of 0.633 and start capacity" + " of 10"); Table <int, int> myHashTable1 = TableFactory.Make <int, int>(10, 0.633); Console.WriteLine("Inserting 10 million entries into hashtable"); for (int i = 0; i < 10000000; i++) { myHashTable1.Put(i, i); } Console.WriteLine("Enumerating throught each entries in HashTable"); foreach (int x in myHashTable1) { myHashTable1.Get(x); } DateTime end = DateTime.Now; Console.WriteLine("Time taken for execution: " + (end - start) + "\n"); Console.WriteLine("Test case 2"); start = DateTime.Now; Console.WriteLine("Testing hashTable with threshold of 0.56 and start capacity" + " of 1"); myHashTable1 = TableFactory.Make <int, int>(1, 0.56); Console.WriteLine("Inserting 10 million entries into hashtable"); for (int i = 0; i < 10000000; i++) { myHashTable1.Put(i, i); } Console.WriteLine("Enumerating throught each entries in HashTable"); foreach (int x in myHashTable1) { myHashTable1.Get(x); } end = DateTime.Now; Console.WriteLine("Time taken for execution: " + (end - start) + "\n"); Console.WriteLine("Test case 3"); start = DateTime.Now; Console.WriteLine("Testing hashTable with threshold of -10 and start capacity " + " of -0.43333"); myHashTable1 = TableFactory.Make <int, int>(-10, -0.43333); Console.WriteLine("Inserting 10 million entries into hashtable"); for (int i = 0; i < 10000000; i++) { myHashTable1.Put(i, i); } Console.WriteLine("Enumerating throught each entries in HashTable"); foreach (int x in myHashTable1) { myHashTable1.Get(x); } end = DateTime.Now; Console.WriteLine("Time taken for execution: " + (end - start) + "\n"); Console.WriteLine("TestCase completed"); }