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); } }
public static void Init(int personCount, IHashTable ht) { switch (personCount) { case 1: ht.Add(new Person(1, "Uasya", "Pipirkin", 41)); break; case 2: ht.Add(new Person(1, "Uasya", "Pipirkin", 41)); ht.Add(new Person(2, "Vasya", "Pupkin", 42)); break; case 7: ht.Add(new Person(1, "Uasya", "Pipirkin", 41)); ht.Add(new Person(2, "Vasya", "Pupkin", 42)); ht.Add(new Person(3, "Vasya", "Papkin", 43)); ht.Add(new Person(4, "Kasya", "Babkin", 44)); ht.Add(new Person(5, "Masya", "Lapkin", 45)); ht.Add(new Person(6, "Figasya", "Lupkin", 46)); ht.Add(new Person(7, "Pupasya", "Lurkin", 47)); break; default: break; } }
public void SizeOfHashTableTest(IHashTable hashTable) { hashTable.Add("TestString 1"); hashTable.Add("TestString 2"); hashTable.Add("TestString 3"); hashTable.Delete("TestString 2"); Assert.AreEqual(2, hashTable.NumberOfElements); }
public void DeleteTest(IHashTable hashTable) { hashTable.Add("TestString1"); hashTable.Add("TestString2"); hashTable.Add("TestString3"); Assert.IsTrue(hashTable.Delete("TestString1")); Assert.IsFalse(hashTable.Delete("TestString1")); Assert.IsTrue(hashTable.Delete("TestString3")); Assert.IsFalse(hashTable.Exists("TestString1")); Assert.IsFalse(hashTable.Exists("TestString3")); Assert.IsTrue(hashTable.Exists("TestString2")); }
public void AddAndExistsTest(IHashTable hashTable) { hashTable.Add("Existing string"); Assert.IsTrue(hashTable.Exists("Existing string")); Assert.IsFalse(hashTable.Exists("Not existing string")); }
/// <summary> /// Performs an action depending on the entered command. /// </summary> /// <param name="hashTable">Hash table to work with.</param> /// <param name="command">Command entered by user.</param> public void CommandExecution(IHashTable hashTable, int command) { switch (command) { case 0: break; case 1: { Console.WriteLine("Enter the data of element you want to add"); var data = int.Parse(Console.ReadLine()); if (!hashTable.Add(data)) { Console.WriteLine("The element with the given data already exists"); } break; } case 2: { Console.WriteLine("Enter the data of element you want to delete"); var data = int.Parse(Console.ReadLine()); if (!hashTable.Delete(data)) { Console.WriteLine("The element with the given data does not exists"); } break; } case 3: { Console.WriteLine("Enter the data of hash table element"); var data = int.Parse(Console.ReadLine()); if (hashTable.Exists(data)) { Console.WriteLine("The element with the given data exists"); } else { Console.WriteLine("The element with the given data does not exists"); } break; } case 4: Console.WriteLine("The hash table:"); hashTable.Print(); break; default: Console.WriteLine("The command you entered is incorrect"); break; } }
public void Test_Add() { IHashTable <string> ht = this.CreateInstance(2); ht.Add("Metal Church"); Assert.True(ht.Contains("Metal Church")); Assert.Equal(1, ht.Count); }
private static void AddAll(IHashTable <K, V> ht, long number) { for (int i = 0; i < number; i++) { K k = (K)Convert.ChangeType(i.ToString(), typeof(K)); V v = (V)Convert.ChangeType((i + 100).ToString(), typeof(V)); HashNode <K, V> node = new HashNode <K, V>(k, v); ht.Add(node); } }
public void Test_Add_ArgOutOfRange_Exc() { TestFabrics.Init(7, ht); ht.Add(new Person(8, "name", "surname", 48)); ht.Add(new Person(9, "name", "surname", 49)); ht.Add(new Person(10, "name", "surname", 50)); ht.Add(new Person(11, "name", "surname", 51)); Assert.Throws <ArgumentOutOfRangeException>(() => ht.Add(new Person(5, "Sasya", "Lapkin", 45))); }
protected IHashTable <string> CreateFullHashTable() { IHashTable <string> hashTable = this.CreateInstance(VALUES.Length, AsciiCharSumHashFunction.Instance); foreach (string value in VALUES) { hashTable.Add(value); } return(hashTable); }
public void HashTableAddingTest() { foreach (Type hashTableType in this.hashTableTypes) { IHashTable hashTable = Activator.CreateInstance(hashTableType) as IHashTable; Assert.IsTrue(hashTable.Add(5)); Assert.IsTrue(hashTable.Contains(5), "hash table [{0}] should contains added value", hashTableType.Name); } }
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()); } }
public void HashTableClearTest() { foreach (Type hashTableType in this.hashTableTypes) { IHashTable hashTable = Activator.CreateInstance(hashTableType) as IHashTable; Assert.IsTrue(hashTable.Add(5)); hashTable.Clear(); Assert.IsTrue(hashTable.Count() == 0, "hash table [{0}] should contains 0 elements after clearing", hashTableType.Name); } }
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 HashTable_Add_AddNullKey_ThrowsArgumentNullException() { try { _ht.Add(null, "one"); Assert.Fail(); } catch (ArgumentNullException) { Assert.IsTrue(true); } catch (Exception) { Assert.Fail(); } }
public void HashTableRebuildTest() { foreach (Type hashTableType in this.hashTableTypes) { IHashTable hashTable = Activator.CreateInstance(hashTableType, 2) as IHashTable; Assert.IsTrue(hashTable.Add(5)); Assert.IsTrue(hashTable.Add(15)); Assert.IsTrue(hashTable.Add(13)); Assert.IsTrue(hashTable.Add(17)); Assert.IsTrue(hashTable.Contains(15), "hash table [{0}] should contains element 15 after rebuilding", hashTableType.Name); Assert.IsTrue(hashTable.Contains(5), "hash table [{0}] should contains element 5 after rebuilding", hashTableType.Name); Assert.IsTrue(hashTable.Contains(13), "hash table [{0}] should contains element 14 after rebuilding", hashTableType.Name); } }
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); } } }
public void Test_Resize_Up() { IHashTable <string> ht = this.CreateInstance(10); int oldSize = ht.Size; // It's needed more than 75% to trigger // a resize up. for (int i = 0; i < oldSize; i++) { ht.Add(i.ToString()); } for (int i = 0; i < oldSize; i++) { Assert.True(ht.Contains(i.ToString())); } Assert.Equal(oldSize * 2, ht.Size); Assert.Equal(oldSize, ht.Count); }
public void Test_Resize_Down() { IHashTable <string> ht = this.CreateInstance(10); int oldSize = ht.Size; // It's needed more than 75% to trigger // a resize up. for (int i = 0; i < oldSize; i++) { ht.Add(i.ToString()); } oldSize = ht.Size; // Resize up = 20 // 20 - 20 * 0.75 = 5 // Trigger count = 5 int triggerCount = (int)(oldSize - oldSize * 0.75); // It's needed less than 25% to trigger // a resize down. // Removing the upper values eases testing. for (int i = oldSize; i >= triggerCount; i--) { ht.Delete(i.ToString()); } for (int i = 0; i < (oldSize - oldSize * 0.75); i++) { Assert.True(ht.Contains(i.ToString())); } Assert.Equal(oldSize / 2, ht.Size); Assert.Equal(triggerCount, ht.Count); }
static public void Add(IHashTable <K, V> ht, HashNode <K, V> node) { ht.Add(node); }
public void AddTheSameElementTwiceTest(IHashTable hashTable) { Assert.IsTrue(hashTable.Add("TestString")); Assert.IsFalse(hashTable.Add("TestString")); }
public virtual IntPtr Add(string key, IntPtr value) { return(impl.Add(Native, key, value)); }
public void Contains_ShouldReturnFalse_WhenElementIsNotInTable(string notExistingKey) { // arrange _hashTable.Add(Key2, Value2); // act & assert _hashTable.Contains(notExistingKey).ShouldBeFalse(); }