public void Add_1000_Elements_Grow_ShouldWorkCorrectly() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(1); // Act var expectedElements = new List<KeyValue<string, int>>(); for (int i = 0; i < 1000; i++) { dictionary.Add("key" + i, i); expectedElements.Add(new KeyValue<string, int>("key" + i, i)); } // Assert var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(expectedElements, actualElements); }
public void AddOrReplace_WithDuplicates_ShouldWorkCorrectly() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(); // Act dictionary.AddOrReplace("Peter", 555); dictionary.AddOrReplace("Maria", 999); dictionary.AddOrReplace("Maria", 123); dictionary.AddOrReplace("Maria", 6); dictionary.AddOrReplace("Peter", 5); // Assert var expectedElements = new KeyValue<string, int>[] { new KeyValue<string, int>("Peter", 5), new KeyValue<string, int>("Maria", 6) }; var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(expectedElements, actualElements); }
public void Add_EmptyDictionary_NoDuplicates_ShouldAddElement() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(); // Act var elements = new KeyValue<string, int>[] { new KeyValue<string, int>("Peter", 5), new KeyValue<string, int>("Maria", 6), new KeyValue<string, int>("George", 4), new KeyValue<string, int>("Kiril", 5) }; foreach (var element in elements) { dictionary.Add(element.Key, element.Value); } // Assert var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(elements, actualElements); }
public void Remove_5000_Elements_ShouldWorkCorrectly() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(); var keys = new List<string>(); var count = 5000; for (int i = 0; i < count; i++) { var key = Guid.NewGuid().ToString(); keys.Add(key); dictionary.Add(key, i); } // Assert Assert.AreEqual(count, dictionary.Count); // Act & Assert keys.Reverse(); foreach (var key in keys) { dictionary.Remove(key); count--; Assert.AreEqual(count, dictionary.Count); } // Assert var expectedElements = new List<KeyValue<string, int>>(); var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(expectedElements, actualElements); }
public void Indexer_AddReplace_WithDuplicates_ShouldWorkCorrectly() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(); // Act dictionary["Peter"] = 555; dictionary["Maria"] = 999; dictionary["Maria"] = 123; dictionary["Maria"] = 6; dictionary["Peter"] = 5; // Assert var expectedElements = new KeyValue<string, int>[] { new KeyValue<string, int>("Peter", 5), new KeyValue<string, int>("Maria", 6) }; var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(expectedElements, actualElements); }
public void Clear_ShouldWorkCorrectly() { // Arrange var dictionary = new DictionaryDataStructure.Dictionary<string, int>(); // Assert Assert.AreEqual(0, dictionary.Count); // Act dictionary.Clear(); // Assert Assert.AreEqual(0, dictionary.Count); // Arrange dictionary.Add("Peter", 5); dictionary.Add("George", 7); dictionary.Add("Maria", 3); // Assert Assert.AreEqual(3, dictionary.Count); // Act dictionary.Clear(); // Assert Assert.AreEqual(0, dictionary.Count); var expectedElements = new List<KeyValue<string, int>>(); var actualElements = dictionary.ToList(); CollectionAssert.AreEquivalent(expectedElements, actualElements); dictionary.Add("Peter", 5); dictionary.Add("George", 7); dictionary.Add("Maria", 3); // Assert Assert.AreEqual(3, dictionary.Count); }