示例#1
0
        public void AddTest()
        {
            var pair = new KeyValuePair <int, int>(4, 2);
            var dict = new DictionaryCollection <int, int>(4);

            dict.Add(pair);
            Assert.Single(dict);
        }
示例#2
0
        public void SetIndexNullKeyException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary[null] = "f");
        }
示例#3
0
        public void KeyAlreadyInListAddException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentException>(() => dictionary.Add(1, "f"));
        }
示例#4
0
        public void KeyNotFoundGetIndexException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <KeyNotFoundException>(() => dictionary[5] == "f");
        }
示例#5
0
        public void NullKeyTryGetValueException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary.TryGetValue(null, out string value));
        }
示例#6
0
        public void NullKeyRemoveException()
        {
            var dictionary = new DictionaryCollection <int?, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Throws <ArgumentNullException>(() => dictionary.Remove(null));
        }
示例#7
0
        public void GetValuesTest()
        {
            var dict = new DictionaryCollection <string, int>(5);

            dict.Add(new KeyValuePair <string, int>("Cat", 1));
            dict.Add(new KeyValuePair <string, int>("Dog", 2));
            dict.Add(new KeyValuePair <string, int>("Rabbit", 4));
            ICollection <int> valueList = dict.Values;

            Assert.Equal(3, valueList.Count);
        }
示例#8
0
        public void ContainsKeyTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.True(dictionary.ContainsKey(7));
        }
示例#9
0
        public void GetIndexerTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            Assert.Equal("a", dictionary[1]);
        }
示例#10
0
        public void IsReadonlyAddException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary = dictionary.ReadOnlyDictionary();
            Assert.Throws <NotSupportedException>(() => dictionary.Add(13, "f"));
        }
示例#11
0
        public void RemoveTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary.Remove(2);
            Assert.False(dictionary.ContainsKey(2));
        }
示例#12
0
        public void CointainsTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> toFind = new KeyValuePair <int, string>(2, "b");

            Assert.Contains(toFind, dictionary);
        }
示例#13
0
        public void ReadOnlyAddPairException()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            dictionary = dictionary.ReadOnlyDictionary();
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(13, "f");

            Assert.Throws <NotSupportedException>(() => dictionary.Add(pair));
        }
示例#14
0
        public void RemoveLastPairTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(12, "e");

            dictionary.Remove(pair);
            Assert.False(dictionary.ContainsKey(12));
        }
示例#15
0
        public void RemoveThenAddOnEmptySpaceTest()
        {
            var dictionary = new DictionaryCollection <int, string>(5);

            dictionary.Add(1, "a");
            dictionary.Add(2, "b");
            dictionary.Add(10, "c");
            dictionary.Add(7, "d");
            dictionary.Add(12, "e");
            KeyValuePair <int, string> pair = new KeyValuePair <int, string>(2, "b");

            dictionary.Remove(pair);
            dictionary.Add(5, "b");
            Assert.Contains(5, dictionary);
        }