Exemple #1
0
 public void AddElementsAndCheckTheirPresenceShallReturnTrue()
 {
     table.AddElement("111");
     table.AddElement("111");
     table.AddElement("222");
     Assert.IsTrue(table.Check("111"));
     Assert.IsTrue(table.Check("222"));
 }
        private static void EventLoop(HashTable table)
        {
            Menu();

            int choice = 1;

            while (choice != 0)
            {
                WriteLine();
                WriteLine("Enter your choice: ");
                string input = ReadLine();
                while (!int.TryParse(input, out choice))
                {
                    WriteLine("It`s not a number, try again: ");
                    input = ReadLine();
                }

                switch (choice)
                {
                case 1:
                {
                    WriteLine("Write the string: ");
                    string str = ReadLine();
                    table.AddElement(str);
                    break;
                }

                case 2:
                {
                    WriteLine("Write the string: ");
                    string str = ReadLine();
                    if (table.Check(str))
                    {
                        WriteLine("There`s such string in the hash table");
                    }
                    else
                    {
                        WriteLine("There`s no such string in the hash table");
                    }
                    break;
                }

                case 3:
                {
                    WriteLine("Write the string: ");
                    string str = ReadLine();
                    while (!table.Check(str))
                    {
                        WriteLine("There`s no such string in hash table, try again: ");
                        str = ReadLine();
                    }
                    table.Delete(str);
                    break;
                }

                case 0:
                {
                    break;
                }

                default:
                {
                    WriteLine("Wrong number, try again: ");
                    break;
                }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Make actions requested by user
        /// </summary>
        /// <param name="table">Used table</param>
        private static void EventLoop(HashTable table)
        {
            Menu2();

            int choice = 1;

            while (choice != 0)
            {
                WriteLine();
                Write("Enter your choice: ");
                string input = ReadLine();
                while (!int.TryParse(input, out choice))
                {
                    WriteLine("It`s not a number, try again: ");
                    input = ReadLine();
                }

                switch (choice)
                {
                case 1:
                {
                    Write("Write the string: ");
                    string str = ReadLine();
                    try
                    {
                        table.AddElement(str);
                    }
                    catch (FormatException e)
                    {
                        WriteLine(e.Message);
                    }
                    break;
                }

                case 2:
                {
                    Write("Write the string: ");
                    string str      = ReadLine();
                    bool   presence = false;
                    try
                    {
                        presence = table.Check(str);
                    }
                    catch (FormatException e)
                    {
                        WriteLine(e.Message);
                    }
                    if (presence)
                    {
                        WriteLine("There`s such string in the hash table");
                    }
                    else
                    {
                        WriteLine("There`s no such string in the hash table");
                    }
                    break;
                }

                case 3:
                {
                    Write("Write the string: ");
                    string str = ReadLine();

                    bool presence = false;
                    try
                    {
                        presence = table.Check(str);
                    }
                    catch (FormatException e)
                    {
                        WriteLine(e.Message);
                    }

                    if (presence)
                    {
                        table.Delete(str);
                    }
                    break;
                }

                case 0:
                {
                    break;
                }

                default:
                {
                    Write("Wrong number, try again: ");
                    break;
                }
                }
            }
        }