Пример #1
0
        public void RemoveAt()
        {
            Deque <string> d = new Deque <string>();

            d.Insert(0, "a");
            d.Insert(1, "b");
            d.Insert(0, "c");
            d.Insert(2, "d");
            d.Insert(1, "e");
            d.Insert(4, "f");
            d.Insert(3, "g");
            d.Insert(2, "h");
            d.Insert(0, "i");
            d.Insert(2, "j");
            d.Insert(4, "k");
            d.RemoveAt(4);
            d.RemoveAt(3);
            d.RemoveAt(2);
            d.RemoveAt(5);
            d.RemoveAt(2);
            InterfaceTests.TestReadWriteListGeneric(d, new string[] { "i", "c", "a", "g", "f", "b" });

            d.Clear();
            d.AddToBack("f");
            d.AddToBack("g");
            d.AddToFront("e");
            d.AddToFront("d");
            d.AddToFront("c");
            d.AddToFront("b");
            d.AddToFront("a");
            d.RemoveAt(3);
            d.RemoveAt(4);
            d.RemoveAt(4);
            InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "b", "c", "e" });
        }
Пример #2
0
        public void Indexer()
        {
            Deque <string> d = new Deque <string>();

            d.AddToFront("c");
            d.AddToFront("b");
            d.AddToFront("a");
            d.AddToBack("d");
            d.AddToBack("e");
            d.AddToBack("f");
            Assert.AreEqual("b", d[1]);
            Assert.AreEqual("e", d[4]);
            d[1] = "q";
            d[4] = "r";
            Assert.AreEqual("q", d[1]);
            Assert.AreEqual("r", d[4]);
            InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "q", "c", "d", "r", "f" });
            d.Clear();

            d.AddToBack("a");
            d.AddToBack("b");
            d.AddToBack("c");
            d.AddToBack("d");
            Assert.AreEqual("b", d[1]);
            Assert.AreEqual("d", d[3]);
            d[1] = "q";
            d[3] = "r";
            Assert.AreEqual("q", d[1]);
            Assert.AreEqual("r", d[3]);
            InterfaceTests.TestReadWriteListGeneric(d, new string[] { "a", "q", "c", "r" });
        }
Пример #3
0
        public void Insert()
        {
            Deque <string> d = new Deque <string>();

            d.Insert(0, "a");
            d.Insert(1, "b");
            d.Insert(0, "c");
            d.Insert(2, "d");
            d.Insert(1, "e");
            d.Insert(4, "f");
            d.Insert(3, "g");
            d.Insert(2, "h");
            d.Insert(0, "i");
            d.Insert(2, "j");
            d.Insert(4, "k");
            d.Insert(3, "l");
            d.Insert(4, "m");
            d.Insert(2, "n");
            InterfaceTests.TestEnumerableElements(d, new string[] { "i", "c", "n", "j", "l", "m", "e", "k", "h", "a", "g", "d", "f", "b" });
            d.RemoveFromBack();
            d.RemoveFromBack();
            d.RemoveFromBack();
            d.RemoveFromBack();
            d.RemoveFromBack();
            d.Insert(4, "o");
            d.Insert(10, "p");
            InterfaceTests.TestEnumerableElements(d, new string[] { "i", "c", "n", "j", "o", "l", "m", "e", "k", "h", "p" });
            InterfaceTests.TestReadWriteListGeneric(d, new string[] { "i", "c", "n", "j", "o", "l", "m", "e", "k", "h", "p" });
        }
Пример #4
0
        public void SerializeUnique()
        {
            UniqueStuff d = new UniqueStuff(), result = new UniqueStuff();

            d.objects = new InterfaceTests.Unique[] {
                new InterfaceTests.Unique("1"), new InterfaceTests.Unique("2"), new InterfaceTests.Unique("3"), new InterfaceTests.Unique("4"), new InterfaceTests.Unique("5"), new InterfaceTests.Unique("6"),
                new InterfaceTests.Unique("cool"), new InterfaceTests.Unique("elvis"), new InterfaceTests.Unique("hello"), new InterfaceTests.Unique("foo"), new InterfaceTests.Unique("world"), new InterfaceTests.Unique("elvis"), new InterfaceTests.Unique(null), null,
                new InterfaceTests.Unique("7"), new InterfaceTests.Unique("8"), new InterfaceTests.Unique("9"), new InterfaceTests.Unique("10"), new InterfaceTests.Unique("11"), new InterfaceTests.Unique("12")
            };
            d.deque = new Deque <InterfaceTests.Unique>();

            d.deque.AddToFront(d.objects[9]);
            d.deque.AddToBack(d.objects[10]);
            d.deque.AddToFront(d.objects[8]);
            d.deque.AddToBack(d.objects[11]);
            d.deque.AddToFront(d.objects[7]);
            d.deque.AddToBack(d.objects[12]);
            d.deque.AddToFront(d.objects[6]);
            d.deque.AddToBack(d.objects[13]);
            d.deque.AddManyToFront(new InterfaceTests.Unique[] { d.objects[0], d.objects[1], d.objects[2], d.objects[3], d.objects[4], d.objects[5] });
            d.deque.AddManyToBack(new InterfaceTests.Unique[] { d.objects[14], d.objects[15], d.objects[16], d.objects[17], d.objects[18], d.objects[19] });

            result = (UniqueStuff)InterfaceTests.SerializeRoundTrip(d);

            InterfaceTests.TestReadWriteListGeneric(result.deque, result.objects);

            for (int i = 0; i < result.objects.Length; ++i)
            {
                if (result.objects[i] != null)
                {
                    Assert.IsFalse(object.Equals(result.objects[i], d.objects[i]));
                }
            }
        }
Пример #5
0
        public void AsReadOnly()
        {
            int[] elements = new int[400];
            for (int i = 0; i < 400; ++i)
            {
                elements[i] = i;
            }

            ReadWriteTestCollection <int> coll1 = new ReadWriteTestCollection <int>(elements);
            ICollection <int>             coll2 = coll1.AsReadOnly();

            InterfaceTests.TestReadonlyCollectionGeneric(coll2, elements, true, null);

            coll1.Add(27);
            coll1.Add(199);

            elements = new int[402];
            coll2    = coll1.AsReadOnly();

            for (int i = 0; i < 400; ++i)
            {
                elements[i] = i;
            }

            elements[400] = 27;
            elements[401] = 199;

            InterfaceTests.TestReadonlyCollectionGeneric(coll2, elements, true, null);

            coll1 = new ReadWriteTestCollection <int>(new int[0]);
            coll2 = coll1.AsReadOnly();
            InterfaceTests.TestReadonlyCollectionGeneric(coll2, new int[0], true, null);
            coll1.Add(4);
            InterfaceTests.TestReadonlyCollectionGeneric(coll2, new int[] { 4 }, true, null);
        }
Пример #6
0
        public void ConvertAll()
        {
            int[] array = new int[400];
            for (int i = 0; i < array.Length; ++i)
            {
                array[i] = i;
            }
            ReadWriteTestCollection <int> coll1 = new ReadWriteTestCollection <int>(array);

            IEnumerable <string> result1 = coll1.ConvertAll(x => (x * 2).ToString());

            string[] expected = new string[400];
            for (int i = 0; i < 400; ++i)
            {
                expected[i] = (2 * i).ToString();
            }
            InterfaceTests.TestEnumerableElements(result1, expected);

            coll1   = new ReadWriteTestCollection <int>(new int[0]);
            result1 = coll1.ConvertAll(x => (x * 2).ToString());
            InterfaceTests.TestEnumerableElements(result1, new string[0]);

            ReadOnlyTestCollection <int> coll2 = new ReadOnlyTestCollection <int>(array);

            IEnumerable <string> result2 = coll2.ConvertAll(x => (x * 2).ToString());

            InterfaceTests.TestEnumerableElements(result2, expected);

            coll2   = new ReadOnlyTestCollection <int>(new int[0]);
            result2 = coll2.ConvertAll(x => (x * 2).ToString());
            InterfaceTests.TestEnumerableElements(result2, new string[0]);
        }
        public void ReadOnlyValueCollection()
        {
            ReadOnlyTestMultiDictionary <string, int> dict = CreateTestReadOnlyDictionary();
            ICollection <int> valueColl = dict["Eric"];

            InterfaceTests.TestReadonlyCollectionGeneric(valueColl, new int[] { 1, 9, 11 }, true, null);
        }
Пример #8
0
        public void Union()
        {
            var bagOdds   = new Bag <int>(new int[] { 1, 1, 1, 3, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 17, 17, 19 });
            var bagDigits = new Bag <int>(new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9 });

            // Algorithms work different depending on sizes, so try both ways.
            Bag <int> bag1 = bagOdds.Clone();
            Bag <int> bag2 = bagDigits.Clone();

            bag1.UnionWith(bag2);
            InterfaceTests.TestReadWriteCollectionGeneric(bag1,
                                                          new int[]
            {
                1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 11, 11, 13, 15,
                17, 17, 19
            }, false);

            bag1 = bagOdds.Clone();
            bag2 = bagDigits.Clone();
            bag2.UnionWith(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag2,
                                                          new int[]
            {
                1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 11, 11, 13, 15,
                17, 17, 19
            }, false);

            bag1 = bagOdds.Clone();
            bag2 = bagDigits.Clone();
            Bag <int> bag3 = bag1.Union(bag2);

            InterfaceTests.TestReadWriteCollectionGeneric(bag3,
                                                          new int[]
            {
                1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 11, 11, 13, 15,
                17, 17, 19
            }, false);

            bag1 = bagOdds.Clone();
            bag2 = bagDigits.Clone();
            bag3 = bag2.Union(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3,
                                                          new int[]
            {
                1, 1, 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9, 11, 11, 13, 15,
                17, 17, 19
            }, false);

            // Make sure intersection with itself works.
            bag1 = bagDigits.Clone();
            bag1.UnionWith(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9 },
                                                          false);

            bag1 = bagDigits.Clone();
            bag3 = bag1.Union(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9 },
                                                          false);
        }
Пример #9
0
        public void SerializeUnique()
        {
            var d  = new UniqueStuff();
            var u1 = new InterfaceTests.Unique("cool");
            var u2 = new InterfaceTests.Unique("elvis");

            d.objects = new InterfaceTests.Unique[]
            {
                new InterfaceTests.Unique("1"),
                new InterfaceTests.Unique("2"),
                new InterfaceTests.Unique("3"),
                new InterfaceTests.Unique("4"),
                new InterfaceTests.Unique("5"),
                new InterfaceTests.Unique("6"),
                u1,
                u2,
                new InterfaceTests.Unique("hello"),
                new InterfaceTests.Unique("foo"),
                new InterfaceTests.Unique("world"),
                u2,
                new InterfaceTests.Unique(null),
                null,
                new InterfaceTests.Unique("7"),
                new InterfaceTests.Unique("8"),
                new InterfaceTests.Unique("9"),
                u1,
                u2,
                new InterfaceTests.Unique("3")
            };

            d.bag = new Bag <InterfaceTests.Unique>
            {
                d.objects[9],
                d.objects[10],
                d.objects[8],
                d.objects[11],
                d.objects[7],
                d.objects[12],
                d.objects[6],
                d.objects[13]
            };

            d.bag.AddMany(new InterfaceTests.Unique[]
                          { d.objects[0], d.objects[1], d.objects[2], d.objects[3], d.objects[4], d.objects[5] });
            d.bag.AddMany(new InterfaceTests.Unique[]
                          { d.objects[14], d.objects[15], d.objects[16], d.objects[17], d.objects[18], d.objects[19] });

            UniqueStuff result = (UniqueStuff)InterfaceTests.SerializeRoundTrip(d);

            InterfaceTests.TestReadWriteCollectionGeneric(result.bag, result.objects, false);

            for (var i = 0; i < result.objects.Length; ++i)
            {
                if (result.objects[i] != null)
                {
                    Assert.IsFalse(Equals(result.objects[i], d.objects[i]));
                }
            }
        }
Пример #10
0
        public void FindAll()
        {
            Bag <double> bag1 = new Bag <double>(new double[] { 4.5, 187.4, 1.2, 7.6, -7.6, -0.04, 1.2, 1.78, 10.11, 187.4 });

            double[] expected = { -7.6, 7.6, 10.11, 187.4, 187.4 };

            InterfaceTests.TestEnumerableElementsAnyOrder(bag1.FindAll(delegate(double d) { return(Math.Abs(d) > 5); }), expected);
        }
Пример #11
0
        public void AddMany()
        {
            Deque <string> deque1 = new Deque <string>(new string[] { "A", "B", "C", "D" });

            deque1.AddManyToFront(new string[] { "Q", "R", "S" });
            deque1.AddManyToBack(new string[] { "L", "M", "N", "O" });
            InterfaceTests.TestReadWriteListGeneric(deque1, new string[] { "Q", "R", "S", "A", "B", "C", "D", "L", "M", "N", "O" });
        }
Пример #12
0
        public void FindAll()
        {
            var bag1 = new Bag <double>(new[] { 4.5, 187.4, 1.2, 7.6, -7.6, -0.04, 1.2, 1.78, 10.11, 187.4 });

            double[] expected = { -7.6, 7.6, 10.11, 187.4, 187.4 };

            InterfaceTests.TestEnumerableElementsAnyOrder(bag1.FindAll(d => Math.Abs(d) > 5), expected);
        }
        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));
        }
Пример #14
0
 public void Serialize()
 {
     Triple<int, string, string> p1 = new Triple<int, string,string>(-12, "hello", "world");
     Triple<string, string, double> p2 = new Triple<string, string, double>("hi", "elvis", 11);
     Triple<int, string,string> s1 = (Triple<int, string,string>)InterfaceTests.SerializeRoundTrip(p1);
     Triple<string, string, double> s2 = (Triple<string, string, double>)InterfaceTests.SerializeRoundTrip(p2);
     Assert.AreEqual(p1, s1);
     Assert.AreEqual(p2, s2);
 }
Пример #15
0
        public void Initialize()
        {
            List <int> list = new List <int>(new int[] { 12, 3, 9, 8, 9 });
            Set <int>  set1 = new Set <int>(list);
            Set <int>  set2 = new Set <int>(list, new ModularComparer(6));

            InterfaceTests.TestReadWriteCollectionGeneric(set1, new int[] { 3, 8, 9, 12 }, false);
            InterfaceTests.TestReadWriteCollectionGeneric(set2, new int[] { 9, 8, 12 }, false);
        }
Пример #16
0
        public void ReadWriteCollection()
        {
            string[] s = { "Hello", "Goodbye", "Eric", "Clapton", "Rules" };

            ReadWriteTestCollection <string> coll = new ReadWriteTestCollection <string>(s);

            InterfaceTests.TestCollection <string>((ICollection)coll, s, true);
            InterfaceTests.TestReadWriteCollectionGeneric <string>((ICollection <string>)coll, s, true);
        }
Пример #17
0
        public void AsReadOnly()
        {
            string[] s_array = { "Eric", "Clapton", null, "The", "World" };
            int[]    i_array = { 1, 5, 6, 5, 19 };

            ReadWriteTestDictionary <string, int> dict1 = new ReadWriteTestDictionary <string, int>(s_array, i_array);
            IDictionary <string, int>             dict2 = dict1.AsReadOnly();

            InterfaceTests.TestReadOnlyDictionaryGeneric <string, int>(dict2, s_array, i_array, "foo", true, null, null, null);
        }
Пример #18
0
        public void Serialize()
        {
            var p1 = new Pair <int, string>(-12, "hello");
            var p2 = new Pair <string, double>("hi", 11);
            var s1 = (Pair <int, string>)InterfaceTests.SerializeRoundTrip(p1);
            var s2 = (Pair <string, double>)InterfaceTests.SerializeRoundTrip(p2);

            Assert.AreEqual(p1, s1);
            Assert.AreEqual(p2, s2);
        }
Пример #19
0
        public void RandomInsertDeleteRange()
        {
            const int ITER = 2000, LOOP = 15;
            Random    rand = new Random(13);

            for (int loop = 0; loop < LOOP; ++loop)
            {
                Deque <int> deque = new Deque <int>();
                List <int>  list  = new List <int>();
                for (int iter = 0; iter < ITER; ++iter)
                {
                    //Console.Write("Loop {0}, Iteration {1}: ", loop, iter);
                    if (rand.Next(100) < 45)
                    {
                        // remove a range.
                        if (list.Count > 0)
                        {
                            int index = rand.Next(list.Count);
                            int count = rand.Next(list.Count - index);
                            //Console.WriteLine("RemoveAt({0}, {1})", index, count);
                            list.RemoveRange(index, count);
                            deque.RemoveRange(index, count);
                        }
                    }
                    else
                    {
                        // Add an range.
                        int   index = rand.Next(list.Count + 1);
                        int   count = rand.Next(10);
                        int[] items = new int[count];
                        for (int i = 0; i < count; ++i)
                        {
                            items[i] = rand.Next(1000);
                        }

                        /*Console.Write("Insert({0}, {{", index);
                         * for (int i = 0; i < count; ++i) {
                         *  if (i > 0)
                         *      Console.Write(", ");
                         *  Console.Write(items[i]);
                         * }
                         * Console.WriteLine("})"); */

                        IEnumerable <int> e = (rand.Next(2) == 0) ? AlgorithmsTests.EnumerableFromArray(items) : items;
                        list.InsertRange(index, e);
                        deque.InsertRange(index, e);
                    }

                    //deque.Print();
                    CheckListAndDeque(list, deque);
                }

                InterfaceTests.TestReadWriteList(deque, list.ToArray());
            }
        }
Пример #20
0
        public void CustomIComparer()
        {
            IEqualityComparer <int> myComparer = new ModularComparer(5);

            var bag1 = new Bag <int>(myComparer)
            {
                3, 8, 12, 9, 13, 17
            };

            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 3, 3, 3, 9, 12, 12 }, false);
        }
Пример #21
0
        public void GenericICollectionInterface()
        {
            string[]     s_array = { "Foo", "Eric", "Clapton", "hello", "goodbye", "C#", "Java" };
            Set <string> set1    = new Set <string>();

            foreach (string s in s_array)
            {
                set1.Add(s);
            }
            Array.Sort(s_array);
            InterfaceTests.TestReadWriteCollectionGeneric(set1, s_array, false);
        }
Пример #22
0
        public void Capacity()
        {
            Deque <int> deque1 = new Deque <int>();

            Assert.AreEqual(0, deque1.Capacity);
            deque1.Add(4);
            Assert.AreEqual(7, deque1.Capacity);
            for (int i = 0; i < 100; ++i)
            {
                deque1.Add(i);
            }
            Assert.AreEqual(127, deque1.Capacity);

            deque1.Clear();
            Assert.AreEqual(0, deque1.Capacity);
            deque1.Capacity = 4;
            Assert.AreEqual(4, deque1.Capacity);
            for (int i = 0; i < 12; ++i)
            {
                deque1.Add(i);
            }
            Assert.AreEqual(19, deque1.Capacity);
            deque1.Capacity = 12;
            Assert.AreEqual(deque1.Capacity, 12);
            InterfaceTests.TestReadWriteListGeneric(deque1, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 });

            deque1.Clear();
            for (int i = 0; i < 12; ++i)
            {
                deque1.Add(i);
            }
            try {
                deque1.Capacity = 11;
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }
            try {
                deque1.Capacity = -1;
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }
            try {
                deque1.Capacity = int.MaxValue;
                Assert.Fail("should throw");
            }
            catch (Exception e) {
                Assert.IsTrue(e is ArgumentOutOfRangeException);
            }
        }
Пример #23
0
        public void Initialize()
        {
            Deque <string> deque1 = new Deque <string>(new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" });

            InterfaceTests.TestReadWriteListGeneric(deque1, new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" });
            Deque <string> deque2 = new Deque <string>(new string[] {});

            InterfaceTests.TestReadWriteListGeneric(deque2, new string[] {});
            Deque <string> deque3 = new Deque <string>();

            InterfaceTests.TestReadWriteListGeneric(deque3, new string[] {});
        }
Пример #24
0
        public void AddMany()
        {
            Set <string> set1 = new Set <string>(StringComparer.InvariantCultureIgnoreCase);

            set1.Add("foo");
            set1.Add("Eric");
            set1.Add("Clapton");
            string[] s_array = { "FOO", "x", "elmer", "fudd", "Clapton", null };
            set1.AddMany(s_array);

            InterfaceTests.TestReadWriteCollectionGeneric(set1, new string[] { null, "Clapton", "elmer", "Eric", "FOO", "fudd", "x" }, false);
        }
Пример #25
0
        public void ReadWriteDictionary()
        {
            string[] s_array = { "Eric", "Clapton", "Rules", "The", "World" };
            int[]    i_array = { 1, 5, 6, 5, 19 };

            ReadWriteTestDictionary <string, int> dict = new ReadWriteTestDictionary <string, int>(s_array, i_array);

            InterfaceTests.TestReadWriteDictionary <string, int>(dict, s_array, i_array, "foo", true, "ReadOnlyTestDictionary");
            InterfaceTests.TestReadWriteDictionary <string, int>(dict, s_array, i_array, "foo", false, "ReadOnlyTestDictionary");
            InterfaceTests.TestReadWriteDictionaryGeneric <string, int>(dict, s_array, i_array, "foo", true, "ReadOnlyTestDictionary", null, null);
            InterfaceTests.TestReadWriteDictionaryGeneric <string, int>(dict, s_array, i_array, "foo", false, "ReadOnlyTestDictionary", null, null);
        }
Пример #26
0
        public void ICollectionInterface()
        {
            string[]     s_array = { "Foo", "Eric", "Clapton", "hello", "goodbye", "C#" };
            Set <string> set1    = new Set <string>();

            foreach (string s in s_array)
            {
                set1.Add(s);
            }

            Array.Sort(s_array);
            InterfaceTests.TestCollection((ICollection)set1, s_array, false);
        }
Пример #27
0
        public void ICollectionInterface()
        {
            string[] s_array = { "Foo", "hello", "Eric", null, "Clapton", "hello", "goodbye", "C#", null };
            var      bag1    = new Bag <string>();

            foreach (var s in s_array)
            {
                bag1.Add(s);
            }

            Array.Sort(s_array);
            InterfaceTests.TestCollection(bag1, s_array, false);
        }
Пример #28
0
        public void GenericICollectionInterface()
        {
            string[]     s_array = { "Foo", "hello", "Eric", null, "Clapton", "hello", "goodbye", "C#", null };
            Bag <string> bag1    = new Bag <string>();

            foreach (string s in s_array)
            {
                bag1.Add(s);
            }

            Array.Sort(s_array);
            InterfaceTests.TestReadWriteCollectionGeneric <string>((ICollection <string>)bag1, s_array, false);
        }
Пример #29
0
        public void CheckList()
        {
            string[] s = { "Hello", "Goodbye", "Eric", "Clapton", "Rules" };

            List <string> coll = new List <string>(s);

            InterfaceTests.TestCollection <string>((ICollection)coll, s, true);
            InterfaceTests.TestReadWriteCollectionGeneric <string>((ICollection <string>)coll, s, true);

            IList <string> ro = new List <string>(s).AsReadOnly();

            InterfaceTests.TestReadonlyCollectionGeneric <string>(ro, s, true, null);
        }
Пример #30
0
        public void Union()
        {
            Set <int> setOdds = new Set <int>(new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 });
            Set <int> setDigits = new Set <int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            Set <int> set1, set2, set3;

            // Algorithms work different depending on sizes, so try both ways.
            set1 = new Set <int>(setOdds);
            set2 = new Set <int>(setDigits);
            set1.UnionWith(set2);
            InterfaceTests.TestCollectionGeneric(set1,
                                                 new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 },
                                                 false,
                                                 null);

            set1 = new Set <int>(setOdds);
            set2 = new Set <int>(setDigits);
            set2.UnionWith(set1);
            InterfaceTests.TestCollectionGeneric(set2,
                                                 new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 },
                                                 false,
                                                 null);

            set1 = new Set <int>(setOdds);
            set2 = new Set <int>(setDigits);
            set3 = Set <int> .Union(set1, set2);

            InterfaceTests.TestCollectionGeneric(set3,
                                                 new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 },
                                                 false,
                                                 null);

            set1 = new Set <int>(setOdds);
            set2 = new Set <int>(setDigits);
            set3 = Set <int> .Union(set2, set1);

            InterfaceTests.TestCollectionGeneric(set3,
                                                 new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 },
                                                 false,
                                                 null);

            // Make sure intersection with itself works.
            set1 = new Set <int>(setDigits);
            set1.UnionWith(set1);
            InterfaceTests.TestCollectionGeneric(set1, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false, null);

            set1 = new Set <int>(setDigits);
            set3 = Set <int> .Union(set1, set1);

            InterfaceTests.TestCollectionGeneric(set3, new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, false, null);
        }