Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void ConvertToString()
        {
            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.ToString();

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

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

            s = dict3.ToString();
            Assert.AreEqual("{}", s);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public void ReadWriteDictionary()
        {
            string[] s_array = new string[] { "Eric", "Clapton", "Rules", "The", "World" };
            int[][]  i_array = new int[][] { new int[] { 1, 9, 11 },
                                             new int[] { 6, 10 },
                                             new int[] { 4 },
                                             new int[] { 1, 2, 3, 4, 5, 6 },
                                             new int[] { 8 } };

            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

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

            InterfaceTests.TestReadWriteMultiDictionaryGeneric <string, int>(dict, s_array, i_array, "foo", 113, true, "ReadWriteTestMultiDictionary", null, null);
            InterfaceTests.TestReadWriteMultiDictionaryGeneric <string, int>(dict, s_array, i_array, "foo", 113, false, "ReadWriteTestMultiDictionary", null, null);
        }
Ejemplo n.º 5
0
        public void ReplaceMany()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            Assert.IsTrue(dict.ReplaceMany("Eric", new int[] { 18, 13, 33 }));
            Assert.IsTrue(dict.ReplaceMany("The", new int[0]));
            Assert.IsFalse(dict.ReplaceMany("Fizzle", new int[] { 100, 2 }));

            string[] s_array = new string[] { "Clapton", "Rules", "World", "Eric", "Fizzle" };
            int[][]  i_array = new int[][] {
                new int[] { 6, 10 },
                new int[] { 4 },
                new int[] { 8 },
                new int[] { 18, 13, 33 },
                new int[] { 100, 2 }
            };

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }
Ejemplo n.º 6
0
        public void RemoveMany()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            Assert.AreEqual(3, dict.RemoveMany("Eric", new int[] { 9, 1, 11 }));
            Assert.AreEqual(0, dict.RemoveMany("Rules", new int[] { }));
            Assert.AreEqual(2, dict.RemoveMany("The", new int[] { 4, 2, 11 }));
            Assert.AreEqual(0, dict.RemoveMany("Clapton", new int[] { 0, 1 }));
            Assert.AreEqual(0, dict.RemoveMany("foo", new int[] { 0, 1 }));

            string[] s_array = new string[] { "Clapton", "Rules", "The", "World" };
            int[][]  i_array = new int[][] {
                new int[] { 6, 10 },
                new int[] { 4 },
                new int[] { 1, 3, 5, 6 },
                new int[] { 8 }
            };

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }
Ejemplo n.º 7
0
        public void Remove2()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            Assert.IsTrue(dict.Remove(new KeyValuePair <string, ICollection <int> >("Eric", new int[] { 9, 1, 11 })));
            Assert.IsFalse(dict.Remove(new KeyValuePair <string, ICollection <int> >("Rules", new int[] { })));
            Assert.IsTrue(dict.Remove(new KeyValuePair <string, ICollection <int> >("The", new int[] { 4, 2, 11 })));
            Assert.IsFalse(dict.Remove(new KeyValuePair <string, ICollection <int> >("Clapton", new int[] { 0, 1 })));
            Assert.IsFalse(dict.Remove(new KeyValuePair <string, ICollection <int> >("foo", new int[] { 0, 1 })));

            string[] s_array = new string[] { "Clapton", "Rules", "The", "World" };
            int[][]  i_array = new int[][] {
                new int[] { 6, 10 },
                new int[] { 4 },
                new int[] { 1, 3, 5, 6 },
                new int[] { 8 }
            };

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }
Ejemplo n.º 8
0
        public void AddMany()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            dict.AddMany("Rules", AlgorithmsTests.EnumerableFromArray(new int[] { 9, -8, 18 }));
            dict.AddMany("World", AlgorithmsTests.EnumerableFromArray(new int[] { }));
            dict.AddMany("Bizzle", AlgorithmsTests.EnumerableFromArray(new int[] { 3, 2, 1 }));
            dict.AddMany("Dazzle", AlgorithmsTests.EnumerableFromArray(new int[] { }));

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

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }
Ejemplo n.º 9
0
        public void Remove1()
        {
            ReadWriteTestMultiDictionary <string, int> dict = CreateTestReadWriteDictionary();

            Assert.IsTrue(dict.Remove("Eric"));
            Assert.IsTrue(dict.Remove("Rules"));
            Assert.IsFalse(dict.Remove("Eric"));
            Assert.IsFalse(dict.Remove("foo"));
            Assert.IsTrue(dict.Remove("World", 8));
            Assert.IsTrue(dict.Remove("The", 2));
            Assert.IsTrue(dict.Remove("The", 6));
            Assert.IsFalse(dict.Remove("The", 6));
            Assert.IsFalse(dict.Remove("The", 11));

            string[] s_array = new string[] { "Clapton", "The" };
            int[][]  i_array = new int[][] {
                new int[] { 6, 10 },
                new int[] { 1, 3, 4, 5 }
            };

            CheckOrderedMultiDictionaryContents(dict, s_array, i_array, "foo", 113, null, null);
        }
Ejemplo n.º 10
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);
        }