public void ElementCheckMustWorkCorrectlyOnExistingElement() { var table = new HashTableStuff.HashTable <string, object>(); table["testproba"] = new object(); Assert.IsTrue(table.IsInTable("testproba")); }
public void TwoElementsWithTheSameHashShouldExistSeparately() { var table = new HashTableStuff.HashTable <string, int>(HashTableStuff.StringHashFunctions.SimpleHash); table.Add("+-", 100); table.Add("X", 200); // In order to demonstate that tests are correct Assert.AreEqual( HashTableStuff.StringHashFunctions.SimpleHash("+-"), HashTableStuff.StringHashFunctions.SimpleHash("X")); Assert.IsTrue(table.IsInTable("+-"), "`+-` does not exists"); Assert.IsTrue(table.IsInTable("X"), "`X` does not exists"); Assert.AreEqual(100, table["+-"], "`+-` has invalid value"); Assert.AreEqual(200, table["X"], "`X` has invalid value"); }
public void AddingAndErasingMultipleElementsMustWork() { var table = new HashTableStuff.HashTable <string, int>(); for (int i = -10000; i <= 10000; ++i) { table.Add(i.ToString(), i - 100); } for (int i = -10000; i <= 10000; ++i) { Assert.IsTrue(table.IsInTable(i.ToString())); table.Erase(i.ToString()); } Assert.AreEqual(0, table.FillFactor, 1e-5); }
public static void Main(string[] args) { PrintProgramName(); var hashFunction = ChooseHashFunction(); PrintHelp(); var hashTable = new HashTableStuff.HashTable <string, int>(hashFunction); while (true) { Console.Write("Enter command: "); if (!int.TryParse(Console.ReadLine(), out int currentCommand)) { Console.WriteLine("Invalid command!"); PrintHelp(); } if (!HashTableHelp.HelpCommands.IsDefined(typeof(HashTableHelp.HelpCommands), currentCommand)) { Console.WriteLine("Invalid command!"); PrintHelp(); } else { switch ((HashTableHelp.HelpCommands)currentCommand) { case HashTableHelp.HelpCommands.ExitProgram: Console.WriteLine("Good bye!"); return; case HashTableHelp.HelpCommands.CheckInTable: Console.Write("Enter key to check: "); var checkKey = Console.ReadLine(); Console.WriteLine(hashTable.IsInTable(checkKey) ? "In table" : "Not in table"); break; case HashTableHelp.HelpCommands.InsertElement: Console.Write("Enter key to insert (or modify): "); var insertKey = Console.ReadLine(); Console.Write($"Enter new value of table[\"{insertKey}\"] (int): "); var insertValue = int.Parse(Console.ReadLine()); hashTable[insertKey] = insertValue; break; case HashTableHelp.HelpCommands.EraseElement: Console.Write("Enter key to erase: "); var eraseKey = Console.ReadLine(); hashTable.Erase(eraseKey); break; case HashTableHelp.HelpCommands.Factor: Console.WriteLine($"Fill factor == {hashTable.FillFactor}"); break; default: PrintHelp(); break; } } } }