private Dictionary <PersonWithHashCodeConst, string> GeneratePersonsWithHashCodeConstDictionary(int count) { if (count <= 0) { throw new ArgumentException("Недопустимое значение для количества элементов в справочнике"); } stopwatch.Reset(); Dictionary <PersonWithHashCodeConst, string> dictionary = new Dictionary <PersonWithHashCodeConst, string>(); while (count > 0) { try { PersonWithHashCodeConst person = GeneratorOfPersons.GeneratePersonWithHashCodeConst(); string plaseOfWork = GeneratorOfPersons.GeneratePlaceOfWork(); stopwatch.Start(); dictionary.Add(person, plaseOfWork); stopwatch.Stop(); count--; } catch (ArgumentException) { Console.WriteLine("Ошибка про добавлении элемента в справочник."); } } return(dictionary); }
public void FindPersonNotInDictionaryTest() { int countOfElements = 10000; Dictionary <Person, string> referenceBook = GeneratePersonsDictionary(countOfElements); Person person = GeneratorOfPersons.GeneratePerson(); bool actual = IsContainsInDictionary(referenceBook, person); Assert.AreEqual(false, actual, "Искомого человека нет в справочнике."); }
public void GenerationUniqueCollectionWith10000UniquePersonsTest() { int countOfElements = 10000; UniqueCollection <Person> uniqueCollection = new UniqueCollection <Person>(); for (int i = 0; i < countOfElements; i++) { uniqueCollection.Add(GeneratorOfPersons.GeneratePerson()); } int actual = uniqueCollection.Count; int expected = countOfElements; Assert.AreEqual(expected, actual); Assert.IsTrue(CheckForNotRepetInTheCollection(uniqueCollection)); }
public void GenerationUniqueCollectionWith100NotUniquePersonsTest() { int countOfElements = 100; UniqueCollection <Person> uniqueCollection = new UniqueCollection <Person>(); for (int i = 0; i < countOfElements; i++) { uniqueCollection.Add(GeneratorOfPersons.GeneratePerson()); } Person[] uniqueCollectionItems = new Person[uniqueCollection.Count]; uniqueCollection.CopyTo(uniqueCollectionItems, 0); uniqueCollection.Add(uniqueCollectionItems[countOfElements / 2]); int actual = uniqueCollection.Count; int expected = countOfElements; Assert.AreEqual(expected, actual); CollectionAssert.AllItemsAreUnique((ICollection)uniqueCollection); }