Exemplo n.º 1
0
        public void AddAndExistsTest(IHashTable hashTable)
        {
            hashTable.Add("Existing string");

            Assert.IsTrue(hashTable.Exists("Existing string"));
            Assert.IsFalse(hashTable.Exists("Not existing string"));
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        /// <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;
            }
        }
Exemplo n.º 4
0
        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());
            }
        }
Exemplo n.º 5
0
 public void ExistsInEmptyHashTableTest(IHashTable hashTable) => Assert.IsFalse(hashTable.Exists("TestString"));