Esempio n. 1
0
        public void TestPuttingObject()
        {
            Int32 key   = GetRandomKey();
            House house = GetRandomHouse();

            houseMap.Put(key, house);
            Assert.IsTrue(houseMap.ContainsKey(key));
            Assert.IsTrue(houseMap.ContainsValue(house));
        }
Esempio n. 2
0
        public void ContainsValue_returns_expected(string needle, bool expected)
        {
            var map = new HashMap <string, string> {
                ["one"] = "hello", ["two"] = "world"
            };

            Assert.Equal(expected, map.ContainsValue(needle));
        }
        public void UpdateOfKeys()
        {
            int expected = 1;

            HashMap <string, string> hashMap = new HashMap <string, string>();

            hashMap.Put("The same key", "The different value 1");
            hashMap.Put("The same key", "The different value 2");
            int actual = hashMap.Count;

            Assert.IsTrue(hashMap.ContainsValue("The different value 2"));
            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void Remove_removes_key_and_value_and_decrements_count_and_returns_value_associated_with_key()
        {
            var map = new HashMap <string, string>();

            map["hello"]   = "world";
            map["goodbye"] = "sky";

            var val = map.Remove("hello");

            Assert.Equal(1, map.Count);
            Assert.False(map.ContainsKey("hello"));
            Assert.False(map.ContainsValue("world"));
            Assert.Equal("world", val);
        }
Esempio n. 5
0
        protected virtual void DoThread()
        {
            for (int i = 1; i <= Iterations; i++)
            {
                IterationsCompleted = i - 1;
                string input = GetString(BlockSize);
                while (HashMap.ContainsKey(Hasher.SanitizeInput(input)))
                {
                    InputCollisions++;
                    input = GetString(BlockSize);
                }

                string key   = Hasher.SanitizeInput(input);
                string value = Hasher.ComputeHash(input);

                if (HashMap.ContainsValue(value))
                {
                    Collisions++;

                    HashMap.ContainsValue(value, out HSD.Tuple <string, string> item, out long address);

                    string confirmed;
                    if (string.Equals(Hasher.ComputeHash(key), Hasher.ComputeHash(item.Key), StringComparison.OrdinalIgnoreCase))
                    {
                        confirmed = "*C*";
                    }
                    else
                    {
                        confirmed = "";
                    }

                    OnCollisionMessage(string.Format("Collision: {0} || {1} ==> {2} {3}", item.Key, key, value, confirmed), item.Key, key, value);
                }
                else
                {
                    HashMap.Add(new HSD.Tuple <string, string>(key, value));
                }

                LastInputString  = input;
                LastOutputString = value;
            }
            IterationsCompleted = Iterations;
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            IMap<string, int> map = new HashMap<string, int>();

            map.Put("yellow", 1);
            map.Put("blue", 10);
            map.Put("red", 67);

            while(true)
            {
                string[] command = Console.ReadLine().Split(' ');
                try
                {
                    switch (command[0].ToLower())
                    {
                        case "clear":
                            map.Clear();
                            break;
                        case "put":
                            map.Put(command[1], Convert.ToInt32(command[2]));
                            break;
                        case "remove":
                            map.Remove(command[1]);
                            break;
                        case "containskey":
                            Console.WriteLine(map.ContainsKey(command[1]));
                            break;
                        case "containsvalue":
                            Console.WriteLine(map.ContainsValue(Convert.ToInt32(command[1])));
                            break;
                        case "list":
                            foreach (IEntry<string, int> e in map)
                                Console.WriteLine(e.ToString());
                            break;
                        case "keys":
                            foreach (string s in map.Keys)
                                Console.WriteLine(s);
                            break;
                        case "values":
                            foreach (int i in map.Values)
                                Console.WriteLine(i.ToString());
                            break;

                        case "testum":  //test
                            UnmutableMap<string, int> um = new UnmutableMap<string, int>(map);
                            Console.WriteLine(um["red"].ToString());
                            um["red"] = 3;
                            break;

                        case "testfind":
                            map = MapUtilsGeneric<string, int>.FindAll(map,
                                new MapUtilsGeneric<string, int>.CheckDelegate( (Entry<string, int> e) => { return e.Key[0] == 'r'; } ),
                                MapUtilsGeneric<string, int>.ArrayMapConstructor);
                            break;

                        default:
                            throw new Exception("Unknown command.");
                    }
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                }
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            int RowCount = 20;
            HashMap <string, string> ConcertProgram = new HashMap <string, string>(RowCount);

            Console.WriteLine("Воспользуйтесь меню для управлениями номерами концерта");
            Console.WriteLine("МЕНЮ\n" +
                              "1 - Вывести содержимое концертной программы\n" +
                              "2 - Добавить номер\n" +
                              "3 - Удалить номер\n" +
                              "4 - Проверить существование номера(ключ)\n" +
                              "5 - Узнать участвует ли исполнитель в концерте\n" +
                              "6 - Вывести количество номеров(пар ключ-значение)\n" +
                              "7 - Проверить таблицу на пустоту\n" +
                              "8 - Узнать исполнителя по произведению\n" +
                              "9 - Очистить таблицу\n" +
                              "10 - Завершить\n");
            int act;

            do
            {
                string strAct = Console.ReadLine();
                if (!Int32.TryParse(strAct, out act))
                {
                    Console.WriteLine("Неверный формат ввода, попробуйте еще раз");
                }
                else
                {
                    switch (act)
                    {
                    case 1:
                        Console.WriteLine(ConcertProgram);
                        break;

                    case 2:
                        Console.WriteLine("Введите название номера(ключ)");
                        string Key2 = Console.ReadLine();

                        Console.WriteLine("Введите имя исполнителя(значение)");
                        string Value2 = Console.ReadLine();

                        ConcertProgram.Put(Key2, Value2);
                        if (Key2 == "" || Value2 == "")
                        {
                            Console.WriteLine("Операция вставки была не выполнена, попробуйте снова");
                        }
                        else
                        {
                            Console.WriteLine("Операция вставки выполнена");
                        }
                        break;

                    case 3:    //test
                        Console.WriteLine("Введите название номера(ключ), который вы хотите удалить");
                        string Key3 = Console.ReadLine();
                        ConcertProgram.Remove(Key3);
                        Console.WriteLine("Удаление завершено");
                        break;

                    case 4:
                        Console.WriteLine("Введите название номера(ключ), который вы хотите проверить");
                        string Key4 = Console.ReadLine();
                        if (!ConcertProgram.ContainsKey(Key4))
                        {
                            Console.WriteLine($"Номер с названием {Key4} НЕ включен в концертную программу");
                            break;
                        }
                        Console.WriteLine($"Номер с названием {Key4} включен в концертную программу");
                        break;

                    case 5:
                        Console.WriteLine("Введите имя исполнителя(значение), которое вы хотите проверить");
                        string Value5 = Console.ReadLine();
                        if (ConcertProgram.ContainsValue(Value5))
                        {
                            Console.WriteLine($"Номер с названием {Value5} включен в концертную программу");
                        }
                        else
                        {
                            Console.WriteLine($"Номер с названием {Value5} НЕ включен в концертную программу");
                        }
                        break;

                    case 6:
                        Console.WriteLine($"В концертной программе {ConcertProgram.Count} номеров");
                        break;

                    case 7:
                        if (ConcertProgram.IsEmpty)
                        {
                            Console.WriteLine("В концертной программе нет номеров(таблица пуста)");
                        }
                        else
                        {
                            Console.WriteLine("В концертной программе есть номера(таблица не пуста)");
                        }
                        break;

                    case 8:
                        Console.WriteLine("Введите название номера(ключ)");
                        string Key8 = Console.ReadLine();
                        try
                        {
                            Console.WriteLine($"Исполнитель(значение) - {ConcertProgram[Key8]}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Ошибка: {ex.Message}");
                        }
                        break;

                    case 9:
                        ConcertProgram.Clear();
                        Console.WriteLine("Все номера удалены из программы");
                        break;

                    case 10:
                        act = 10;
                        break;
                    }
                }
            } while (act != 10);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            IMap <string, int> map = new HashMap <string, int>();

            map.Put("yellow", 1);
            map.Put("blue", 10);
            map.Put("red", 67);

            while (true)
            {
                string[] command = Console.ReadLine().Split(' ');
                try
                {
                    switch (command[0].ToLower())
                    {
                    case "clear":
                        map.Clear();
                        break;

                    case "put":
                        map.Put(command[1], Convert.ToInt32(command[2]));
                        break;

                    case "remove":
                        map.Remove(command[1]);
                        break;

                    case "containskey":
                        Console.WriteLine(map.ContainsKey(command[1]));
                        break;

                    case "containsvalue":
                        Console.WriteLine(map.ContainsValue(Convert.ToInt32(command[1])));
                        break;

                    case "list":
                        foreach (IEntry <string, int> e in map)
                        {
                            Console.WriteLine(e.ToString());
                        }
                        break;

                    case "keys":
                        foreach (string s in map.Keys)
                        {
                            Console.WriteLine(s);
                        }
                        break;

                    case "values":
                        foreach (int i in map.Values)
                        {
                            Console.WriteLine(i.ToString());
                        }
                        break;

                    case "testum":      //test
                        UnmutableMap <string, int> um = new UnmutableMap <string, int>(map);
                        Console.WriteLine(um["red"].ToString());
                        um["red"] = 3;
                        break;

                    case "testfind":
                        map = MapUtilsGeneric <string, int> .FindAll(map,
                                                                     new MapUtilsGeneric <string, int> .CheckDelegate((Entry <string, int> e) => { return(e.Key[0] == 'r'); }),
                                                                     MapUtilsGeneric <string, int> .ArrayMapConstructor);

                        break;

                    default:
                        throw new Exception("Unknown command.");
                    }
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                }
            }
        }