public void ItemRemove_Test()
        {
            treeDict = new TreeDictionary <int, int>(true);
            treeDict.Add(0, 44);
            treeDict.Add(1, 55);
            treeDict.Add(2, 66);
            treeDict.Add(3, 99);
            treeDict.Add(3, 101);
            treeDict.Add(4, 88);
            treeDict.Add(5, 77);
            treeDict.Add(8, 45);
            treeDict.Add(9, 34);

            treeDict.Remove(new KeyValuePair <int, int>(8, 45));
            treeDict.Remove(new KeyValuePair <int, int>(3, 99));
            treeDict.Remove(new KeyValuePair <int, int>(9, 34));

            Assert.AreEqual(6, treeDict.Count);
            Assert.AreEqual(false, treeDict.ContainsKey(6), "Contains");
            Assert.AreEqual(true, treeDict.Contains(new KeyValuePair <int, int>(0, 44)));
            Assert.AreEqual(true, treeDict.Contains(new KeyValuePair <int, int>(1, 55)));
            Assert.AreEqual(false, treeDict.Contains(new KeyValuePair <int, int>(8, 45)), "8, 45");
            Assert.AreEqual(false, treeDict.Contains(new KeyValuePair <int, int>(3, 99)), "3, 99");
            Assert.AreEqual(false, treeDict.Contains(new KeyValuePair <int, int>(9, 34)), "9, 34");
        }
Exemplo n.º 2
0
        public void TestEmptyDictionary()
        {
            var dictionary = new TreeDictionary <int, int>();

            TreeDictionary <int, int> .KeyCollection   keys   = dictionary.Keys;
            TreeDictionary <int, int> .ValueCollection values = dictionary.Values;

            Assert.Empty(dictionary);
            Assert.Empty(keys);
            Assert.Empty(values);

#pragma warning disable xUnit2013 // Do not use equality check to check for collection size.
            Assert.Equal(0, dictionary.Count);
            Assert.Equal(0, keys.Count);
            Assert.Equal(0, values.Count);
#pragma warning restore xUnit2013 // Do not use equality check to check for collection size.

            Assert.False(dictionary.ContainsKey(0));
            Assert.False(dictionary.ContainsValue(0));
            Assert.False(dictionary.TryGetValue(0, out _));
            Assert.Throws <KeyNotFoundException>(() => dictionary[0]);

#pragma warning disable xUnit2017 // Do not use Contains() to check if a value exists in a collection
            Assert.False(keys.Contains(0));
            Assert.False(values.Contains(0));
#pragma warning restore xUnit2017 // Do not use Contains() to check if a value exists in a collection
        }
Exemplo n.º 3
0
        public void TreeDictionary_Test()
        {
            var Dictionary = new TreeDictionary <int, int>();

            int nodeCount = 1000;

            //insert test


            for (int i = 0; i <= nodeCount; i++)
            {
                Dictionary.Add(i, i);
                Assert.AreEqual(true, Dictionary.ContainsKey(i));
            }


            for (int i = 0; i <= nodeCount; i++)
            {
                Dictionary.Remove(i);
                Assert.AreEqual(false, Dictionary.ContainsKey(i));
            }


            var rnd        = new Random();
            var testSeries = Enumerable.Range(1, nodeCount).OrderBy(x => rnd.Next()).ToList();

            foreach (var item in testSeries)
            {
                Dictionary.Add(item, item);
                Assert.AreEqual(true, Dictionary.ContainsKey(item));
            }

            for (int i = 1; i <= nodeCount; i++)
            {
                Dictionary.Remove(i);
                Assert.AreEqual(false, Dictionary.ContainsKey(i));
            }
        }
Exemplo n.º 4
0
        public void ContainsKey_InsertNull_ReturnsTrue()
        {
            //Arrange
            var          dictionary = new TreeDictionary <string, string>(new BinaryTree <string, string>());
            const string key        = "testKey";

            dictionary.Add(key, null);
            //Act
            var result = dictionary.ContainsKey(key);

            //Assert
            Assert.True(result);
            Assert.Single(dictionary);
        }
        public void KeyRemove_Test()
        {
            treeDict = new TreeDictionary <int, int>(true);
            treeDict.Add(0, 44);
            treeDict.Add(1, 55);
            treeDict.Add(1, 56);
            treeDict.Add(2, 66);
            treeDict.Add(3, 99);

            treeDict.Remove(1);

            Assert.AreEqual(3, treeDict.Count);
            Assert.AreEqual(true, treeDict.ContainsKey(2));
            Assert.AreEqual(false, treeDict.Contains(new KeyValuePair <int, int>(3, 98)));
            Assert.AreEqual(true, treeDict.Contains(new KeyValuePair <int, int>(3, 99)));
            Assert.AreEqual(66, treeDict[2]);
        }
 public void AddItems_Test()
 {
     treeDict.Add(0, 44);
     treeDict.Add(1, 55);
     treeDict.Add(2, 66);
     treeDict.Add(3, 99);
     Assert.AreEqual(4, treeDict.Count);
     Assert.AreEqual(true, treeDict.ContainsKey(0));
     Assert.AreEqual(true, treeDict.ContainsKey(1));
     Assert.AreEqual(true, treeDict.ContainsKey(2));
     Assert.AreEqual(true, treeDict.ContainsKey(3));
 }
Exemplo n.º 7
0
        public void Remove_RemoveExistingItem_ReturnsTrue()
        {
            //Arrange
            var dictionary = new TreeDictionary <int, int>(new BinaryTree <int, int>())
            {
                { 3, 30 }, { 5, 50 }, { 1, 10 }, { 2, 20 }
            };
            //Act
            var result = dictionary.Remove(3);

            //Assert
            Assert.True(result);
            Assert.False(dictionary.ContainsKey(3));
            foreach (var p in dictionary)
            {
                Assert.NotEqual(3, p.Key);
            }
            Assert.Equal(3, dictionary.Count);
        }
Exemplo n.º 8
0
 public void ContainsKey()
 {
     dict.Add("C", "D");
     Assert.IsTrue(dict.ContainsKey("C"));
     Assert.IsFalse(dict.ContainsKey("D"));
 }