public void HashTableRemovingTest() { foreach (Type hashTableType in this.hashTableTypes) { IHashTable hashTable = Activator.CreateInstance(hashTableType) as IHashTable; Assert.IsTrue(hashTable.Add(5)); Assert.IsTrue(hashTable.Add(15)); Assert.IsTrue(hashTable.Add(14)); Assert.IsTrue(hashTable.Remove(15), "hash table [{0}] should remove existed element", hashTableType.Name); Assert.IsFalse(hashTable.Remove(17), "hash table [{0}] should not be able to remove not existed element", hashTableType.Name); Assert.IsTrue(hashTable.Contains(5), "hash table [{0}] should contains not removed element", hashTableType.Name); Assert.IsFalse(hashTable.Contains(15), "hash table [{0}] should not contains removed element", hashTableType.Name); } }
static public void RemoveAll(ref IHashTable <K, V> ht, int number) { for (int i = 0; i < number; i++) { K key = (K)Convert.ChangeType(i.ToString(), typeof(K)); ht.Remove(key); } }
private static void CommandExecution(IHashTable hashTable) { int number = int.Parse(Console.ReadLine()); while (number != 0) { switch (number) { case 1: { int value = ValueEntryRequest(); hashTable.Add(value); } break; case 2: { int value = ValueEntryRequest(); hashTable.Remove(value); } break; case 3: { int value = ValueEntryRequest(); if (hashTable.Exists(value)) { Console.WriteLine("Value is in the hash table"); } else { Console.WriteLine("Value is not in the hash table"); } } break; case 4: hashTable.Print(); break; case 5: hashTable.Clear(); break; default: Console.WriteLine("Enter correct number"); break; } Console.Write("Input number: "); number = int.Parse(Console.ReadLine()); } }
private static void IHashTableTest(IHashTable <string> table) { while (true) { var input = IOSystem.SafeSimpleChoice("Выберите действие с таблицей:", new string[] { "Добавить узел", "Удалить узел", "Получить узел", "Вывести таблицу", "Закончить тест" }); bool endTest = false; switch (input) { case 0: int key = IOSystem.GetInt("Введите ключ: "); Console.Write("Введите значение: "); string value = Console.ReadLine(); table.Add(key, value); break; case 1: table.Remove(IOSystem.GetInt("Введите ключ: ")); break; case 2: Console.WriteLine("Найденное значение: " + table.FindByKey(IOSystem.GetInt("Введите ключ: "))); break; case 3: Console.WriteLine("Начало вывода"); table.View(); Console.WriteLine("Конец вывода"); break; case 4: endTest = true; break; } Console.WriteLine(); if (endTest) { break; } } }
public void HashTableEnumeratorTest() { foreach (Type hashTableType in this.hashTableTypes) { IHashTable hashTable = Activator.CreateInstance(hashTableType, 2) as IHashTable; var items = new int[] { 5, 15, 13 }; foreach (var item in items) { hashTable.Add(item); } hashTable.Add(31); hashTable.Remove(31); foreach (var item in hashTable) { Assert.IsTrue(items.Contains(item), "hash table [{0}] should contains element [{1}] in enumerator", hashTableType.Name, item); } } }
static public void Remove(IHashTable <K, V> ht, K key) { ht.Remove(key); }
public virtual uint Remove(string key) { return(impl.Remove(Native, key)); }
static void TestHashTable(IHashTable hashTable) { // Check Insert Debug.Assert(hashTable.Insert("a", "a") == null); Debug.Assert(hashTable.Insert("b", "b") == null); Debug.Assert(hashTable.Insert("c", "c") == null); Debug.Assert(hashTable.Insert("abba", "abba") == null); Debug.Assert(hashTable.Insert("abracadabra", "abracadabra") == null); Debug.Assert(hashTable.Insert("baab", "baab") == null); Debug.Assert(hashTable.Insert("pika", "pika") == null); Debug.Assert(hashTable.Insert("pica", "pica") == null); Debug.Assert(hashTable.Insert("1234567890", "1234567890") == null); Debug.Assert(hashTable.Insert("0987654321", "0987654321") == null); Debug.Assert(hashTable.Insert("a", "a2") == "a"); Debug.Assert(hashTable.Insert("b", "b2") == "b"); Debug.Assert(hashTable.Insert("c", "c2") == "c"); // Check Find Debug.Assert(hashTable.Find("a") == "a2"); Debug.Assert(hashTable.Find("b") == "b2"); Debug.Assert(hashTable.Find("c") == "c2"); Debug.Assert(hashTable.Find("abba") == "abba"); Debug.Assert(hashTable.Find("abracadabra") == "abracadabra"); Debug.Assert(hashTable.Find("baab") == "baab"); Debug.Assert(hashTable.Find("pika") == "pika"); Debug.Assert(hashTable.Find("pica") == "pica"); Debug.Assert(hashTable.Find("1234567890") == "1234567890"); Debug.Assert(hashTable.Find("0987654321") == "0987654321"); Debug.Assert(hashTable.Find("aa") == null); Debug.Assert(hashTable.Find("bb") == null); Debug.Assert(hashTable.Find("cc") == null); // Check Remove Debug.Assert(hashTable.Remove("aa") == null); Debug.Assert(hashTable.Remove("bb") == null); Debug.Assert(hashTable.Remove("cc") == null); Debug.Assert(hashTable.Remove("a") == "a2"); Debug.Assert(hashTable.Remove("b") == "b2"); Debug.Assert(hashTable.Remove("c") == "c2"); Debug.Assert(hashTable.Remove("abba") == "abba"); Debug.Assert(hashTable.Remove("abracadabra") == "abracadabra"); Debug.Assert(hashTable.Remove("baab") == "baab"); Debug.Assert(hashTable.Remove("pika") == "pika"); Debug.Assert(hashTable.Remove("pica") == "pica"); Debug.Assert(hashTable.Remove("1234567890") == "1234567890"); Debug.Assert(hashTable.Remove("0987654321") == "0987654321"); Debug.Assert(hashTable.Remove("aa") == null); Debug.Assert(hashTable.Remove("bb") == null); Debug.Assert(hashTable.Remove("cc") == null); // Check Find after Remove Debug.Assert(hashTable.Find("a") == null); Debug.Assert(hashTable.Find("b") == null); Debug.Assert(hashTable.Find("c") == null); Debug.Assert(hashTable.Find("abba") == null); Debug.Assert(hashTable.Find("abracadabra") == null); Debug.Assert(hashTable.Find("baab") == null); Debug.Assert(hashTable.Find("pika") == null); Debug.Assert(hashTable.Find("pica") == null); Debug.Assert(hashTable.Find("1234567890") == null); Debug.Assert(hashTable.Find("0987654321") == null); // Check Insert after Remove Debug.Assert(hashTable.Insert("a", "a") == null); Debug.Assert(hashTable.Insert("b", "b") == null); Debug.Assert(hashTable.Insert("c", "c") == null); Debug.Assert(hashTable.Insert("abba", "abba") == null); Debug.Assert(hashTable.Insert("abracadabra", "abracadabra") == null); Debug.Assert(hashTable.Insert("baab", "baab") == null); Debug.Assert(hashTable.Insert("pika", "pika") == null); Debug.Assert(hashTable.Insert("pica", "pica") == null); Debug.Assert(hashTable.Insert("1234567890", "1234567890") == null); Debug.Assert(hashTable.Insert("0987654321", "a0987654321") == null); }