/// <summary> /// Main method /// </summary> /// <param name="args"></param> static void Main(string[] args) { HashTable hashTable = new HashTable(); bool cont = true; while (cont) { Console.WriteLine("1 - добавить значение в таблицу"); Console.WriteLine("2 - удалить значение из таблицы"); Console.WriteLine("3 - проверить существование"); Console.WriteLine("Другое - выход"); Console.Write("Ваш выбор: "); int number = Convert.ToInt32(Console.ReadLine()); switch (number) { case 1: Add(hashTable); break; case 2: Delete(hashTable); break; case 3: Check(hashTable); break; default: cont = false; break; } } }
public void DeleteValue() { HashTable myHashTable = new HashTable(); myHashTable.AddValue("sdbgkjsgfskfjnbsf,gmbnfsgbsfgjbnrtbkjadfvjwrblhygwtlekjbg;qkejrbfdnfbvsmngv ae;erjgejgbjtrhvbgmd fveqjrgfq;owrfgqoreihgeqjbgvkdnfvm,nqegforewgftwrf"); Assert.AreEqual(true, myHashTable.Exists("sdbgkjsgfskfjnbsf,gmbnfsgbsfgjbnrtbkjadfvjwrblhygwtlekjbg;qkejrbfdnfbvsmngv ae;erjgejgbjtrhvbgmd fveqjrgfq;owrfgqoreihgeqjbgvkdnfvm,nqegforewgftwrf")); Assert.AreEqual(true, myHashTable.DeleteValue("sdbgkjsgfskfjnbsf,gmbnfsgbsfgjbnrtbkjadfvjwrblhygwtlekjbg;qkejrbfdnfbvsmngv ae;erjgejgbjtrhvbgmd fveqjrgfq;owrfgqoreihgeqjbgvkdnfvm,nqegforewgftwrf")); }
private static void Add(HashTable hashTable) { Console.Write("Введите строку: "); string newString = Console.ReadLine(); hashTable.Add(newString); Console.WriteLine("Элемент добавлен!"); }
private static void Delete(HashTable hashTable) { Console.Write("Введите строку: "); string newString = Console.ReadLine(); if (hashTable.Delete(newString)) Console.WriteLine("Данный элемент удален!"); else Console.WriteLine("Данного элемента не существует!"); }
public void LastTest() { HashTable myHashTable = new HashTable(1, new AnotherSimpleHashFunction()); Assert.AreEqual(false, myHashTable.DeleteValue("bye")); myHashTable.AddValue("i don't know"); myHashTable.AddValue("what"); myHashTable.AddValue("to"); myHashTable.AddValue("write"); Assert.AreEqual(true, myHashTable.DeleteValue("what")); Assert.AreEqual(false, myHashTable.DeleteValue("what")); Assert.AreEqual(false, myHashTable.DeleteValue("what")); Assert.AreEqual(true, myHashTable.DeleteValue("to")); }
public void LastTest() { HashTable myHashTable = new HashTable(); Assert.AreEqual(false, myHashTable.DeleteValue("bye")); myHashTable.AddValue("i don't know"); myHashTable.AddValue("what"); myHashTable.AddValue("to"); myHashTable.AddValue("write"); Assert.AreEqual(true, myHashTable.DeleteValue("what")); Assert.AreEqual(false, myHashTable.DeleteValue("what")); Assert.AreEqual(false, myHashTable.DeleteValue("what")); Assert.AreEqual(true, myHashTable.DeleteValue("to")); }
public void InitialTest() { HashTable myHashTable = new HashTable(1, new AnotherSimpleHashFunction()); }
public void ExistsTest() { HashTable myHashTable = new HashTable(10, new AnotherSimpleHashFunction()); myHashTable.AddValue("hello"); Assert.AreEqual(true, myHashTable.Exists("hello")); }
public void DoesntExistTest() { HashTable myHashTable = new HashTable(12, new AnotherSimpleHashFunction()); Assert.AreEqual(false, myHashTable.Exists("hello")); }
public void Exists() { HashTable myHashTable = new HashTable(); myHashTable.AddValue("hello"); Assert.AreEqual(true, myHashTable.Exists("hello")); }
public void DoesntExist() { HashTable myHashTable = new HashTable(); Assert.AreEqual(false, myHashTable.Exists("hello")); }
private static void Add(HashTable hashTable) { Console.WriteLine("Enter a string"); hashTable.AddValue(Console.ReadLine()); Console.WriteLine("Element is added"); }
private static void Delete(HashTable hashTable) { Console.WriteLine("Enter a string"); if (hashTable.DeleteValue(Console.ReadLine())) { Console.WriteLine("Element is deleted"); } else { Console.WriteLine("There's no such element"); } }
private static void CheckBeloning(HashTable hashTable) { Console.WriteLine("Enter a string"); if (hashTable.Exists(Console.ReadLine())) { Console.WriteLine("This elements exists in the hash table"); } else { Console.WriteLine("This elements doesn't exist in the hash table"); } }
public static void Main(string[] args) { HashTable myHashTable; int hashTableSize; while (true) { Console.WriteLine("Enter a size of hash table"); if (!int.TryParse(Console.ReadLine(), out hashTableSize)) { Console.WriteLine("Incorrect input. Enter a positive integer number"); } else { if (hashTableSize > 0) { break; } else { Console.WriteLine("Incorrect input. Enter a positive integer number"); } } } int hashFunction; Console.WriteLine("Choose a hash function:"); Console.WriteLine("1 - simple hash function"); Console.WriteLine("2 - hash function Hash37"); Console.WriteLine("3 - second simple hash function"); while (true) { if (!int.TryParse(Console.ReadLine(), out hashFunction)) { Console.WriteLine("Incorrect input. Enter a number from 1 to 3"); } else { break; } } switch (hashFunction) { case 1: myHashTable = new HashTable(hashTableSize, new SimpleHashFunction()); break; case 2: myHashTable = new HashTable(hashTableSize, new HashFunction37()); break; case 3: myHashTable = new HashTable(hashTableSize, new SimpleHashFunction()); break; default: myHashTable = new HashTable(hashTableSize, new AnotherSimpleHashFunction()); break; } bool goOn = true; while (goOn) { Console.WriteLine("Choose an action:"); Console.WriteLine("1 - check if there is a specific element"); Console.WriteLine("2 - add a new element"); Console.WriteLine("3 - delete a specific element"); Console.WriteLine("4 - exit the program"); int choice = 0; if (int.TryParse(Console.ReadLine(), out choice)) { switch (choice) { case 1: CheckBeloning(myHashTable); break; case 2: Add(myHashTable); break; case 3: Delete(myHashTable); break; case 4: goOn = false; break; default: Console.WriteLine("Incorrect input. Please try again"); break; } } } }
public void InitialTest() { HashTable myHashTable = new HashTable(10, new HashFunction37()); }