コード例 #1
0
        public void ValueCollection()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();
            ICollection <int> valueColl = dict["Eric"];

            Assert.AreEqual(3, valueColl.Count);
            valueColl.Add(19);
            valueColl.Add(-4);
            Assert.IsTrue(valueColl.Remove(1));
            Assert.IsTrue(valueColl.Remove(19));
            valueColl.Add(12);

            string[] s_array = new string[] { "Eric", "Clapton", "Rules", "The", "World" };
            int[][]  i_array = new int[][] { new int[] { 9, 11, -4, 12 },
                                             new int[] { 6, 10 },
                                             new int[] { 4 },
                                             new int[] { 1, 2, 3, 4, 5, 6 },
                                             new int[] { 8 } };
            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);

            dict.Remove("Eric", 12);
            dict.Add("Eric", 19);
            InterfaceTests.TestReadWriteCollectionGeneric(valueColl, new int[] { 9, 11, -4, 19 }, true);

            dict.Remove("Eric");
            InterfaceTests.TestReadWriteCollectionGeneric(valueColl, new int[] { }, true);
            InterfaceTests.TestReadWriteCollectionGeneric(dict["BananaZip"], new int[] { }, true);

            dict["The"].Clear();
            Assert.IsFalse(dict.ContainsKey("The"));

            valueColl = dict["Foo"];
            valueColl.Add(3);
            valueColl.Add(4);
            valueColl.Add(5);

            s_array = new string[] { "Clapton", "Rules", "World", "Foo" };
            i_array = new int[][] {
                new int[] { 6, 10 },
                new int[] { 4 },
                new int[] { 8 },
                new int[] { 3, 4, 5 }
            };
            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "fizzle", 113, null, null);

            ICollection <int> valueColl2 = dict["Foo"];

            Assert.IsFalse(object.ReferenceEquals(valueColl, valueColl2));

            valueColl2.Add(11);
            valueColl.Add(19);
            Assert.IsTrue(Algorithms.EqualCollections(valueColl, valueColl2));
        }
コード例 #2
0
        public void DebuggerDisplay()
        {
            string[]           s_array = { "Eric", "null", "Rules", "The", "World" };
            int[][]            i_array = { new int[] { 1, 9, 11 },
                                           new int[]            { 6,10 },
                                           new int[]            {4 },
                                           new int[]            { 1, 2,3, 4, 5, 6 },
                                           new int[]            { 8 } };
            List <string>      s_list = new List <string>(s_array);
            List <List <int> > i_list = new List <List <int> >();

            foreach (int[] arr in i_array)
            {
                i_list.Add(new List <int>(arr));
            }

            ReadWriteTestMultiDictionary <string, int> dict = new ReadWriteTestMultiDictionary <string, int>(s_list, i_list);

            string s = dict.DebuggerDisplayString();

            Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);

            ReadOnlyTestMultiDictionary <string, int> dict2 = new ReadOnlyTestMultiDictionary <string, int>(s_list, i_list);

            s = dict2.DebuggerDisplayString();
            Assert.AreEqual("{Eric->(1,9,11), null->(6,10), Rules->(4), The->(1,2,3,4,5,6), World->(8)}", s);

            ReadWriteTestMultiDictionary <string, int> dict3 = new ReadWriteTestMultiDictionary <string, int>(new List <string>(), new List <List <int> >());

            s = dict3.DebuggerDisplayString();
            Assert.AreEqual("{}", s);

            ReadOnlyTestMultiDictionary <string, int> dict4 = new ReadOnlyTestMultiDictionary <string, int>(new List <string>(), new List <List <int> >());

            s = dict4.DebuggerDisplayString();
            Assert.AreEqual("{}", s);

            ReadWriteTestMultiDictionary <string, int> dict5 = new ReadWriteTestMultiDictionary <string, int>(new List <string>(), new List <List <int> >());

            for (int i = 0; i < 20; ++i)
            {
                for (int j = 0; j < i; ++j)
                {
                    dict5.Add(string.Format("foo{0}bar", i), j);
                }
            }

            s = dict5.DebuggerDisplayString();
            Assert.AreEqual("{foo1bar->(0), foo2bar->(0,1), foo3bar->(0,1,2), foo4bar->(0,1,2,3), foo5bar->(0,1,2,3,4), foo6bar->(0,1,2,3,4,5), foo7bar->(0,1,2,3,4,5,6), foo8bar->(0,1,2,3,4,5,6,7), foo9bar->(0,1,2,3,4,5,6,7,8), foo10bar->(0,1,2,3,4,5,6,7,8,9), foo11bar->(0,1,2,3,4,5,6,7,8,9,10), ...}", s);

            s_list = new List <string>(dict5.Keys);
            i_list = new List <List <int> >();
            foreach (string key in s_list)
            {
                i_list.Add(new List <int>(dict5[key]));
            }

            ReadOnlyTestMultiDictionary <string, int> dict6 = new ReadOnlyTestMultiDictionary <string, int>(s_list, i_list);

            s = dict6.DebuggerDisplayString();
            Assert.AreEqual("{foo1bar->(0), foo2bar->(0,1), foo3bar->(0,1,2), foo4bar->(0,1,2,3), foo5bar->(0,1,2,3,4), foo6bar->(0,1,2,3,4,5), foo7bar->(0,1,2,3,4,5,6), foo8bar->(0,1,2,3,4,5,6,7), foo9bar->(0,1,2,3,4,5,6,7,8), foo10bar->(0,1,2,3,4,5,6,7,8,9), foo11bar->(0,1,2,3,4,5,6,7,8,9,10), ...}", s);
        }
コード例 #3
0
        public void Add()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            dict.Add(new KeyValuePair <string, ICollection <int> >("Rules", new int[] { 9, -8, 18 }));
            dict.Add(new KeyValuePair <string, ICollection <int> >("World", new OrderedBag <int>(new int[] { })));
            dict.Add(new KeyValuePair <string, ICollection <int> >("Bizzle", new List <int>(new int[] { 3, 2, 1 })));
            dict.Add(new KeyValuePair <string, ICollection <int> >("Dazzle", new BigList <int>(new int[] { })));
            dict.Add("Eric", 16);
            dict.Add("The", 11);
            dict.Add("The", 22);
            dict.Add("Fizzle", 1);
            dict.Add("Fizzle", 11);
            dict.Add("Gizzle", -7);
            dict.Add("Bizzle", 8);

            string[] s_array = new string[] { "Eric", "Clapton", "Rules", "The", "World", "Bizzle", "Fizzle", "Gizzle" };
            int[][]  i_array = new int[][] {
                new int[] { 1, 9, 11, 16 },
                new int[] { 6, 10 },
                new int[] { 4, 9, -8, 18 },
                new int[] { 1, 2, 3, 4, 5, 6, 11, 22 },
                new int[] { 8 },
                new int[] { 3, 2, 1, 8 },
                new int[] { 1, 11 },
                new int[] { -7 }
            };

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }