예제 #1
0
        public void Add()
        {
            Set <string> set1 = new Set <string>(StringComparer.InvariantCultureIgnoreCase);
            bool         b;

            b = set1.Add("hello");
            Assert.IsFalse(b);
            b = set1.Add("foo");
            Assert.IsFalse(b);
            b = set1.Add("");
            Assert.IsFalse(b);
            b = set1.Add("HELLO");
            Assert.IsTrue(b);
            b = set1.Add("foo");
            Assert.IsTrue(b);
            b = set1.Add(null);
            Assert.IsFalse(b);
            b = set1.Add("Hello");
            Assert.IsTrue(b);
            b = set1.Add("Eric");
            Assert.IsFalse(b);
            b = set1.Add(null);
            Assert.IsTrue(b);

            InterfaceTests.TestReadWriteCollectionGeneric(set1, new string[] { null, "", "Eric", "foo", "Hello" }, false);
        }
예제 #2
0
        public void SerializeStrings()
        {
            Bag <string> d = new Bag <string>(StringComparer.InvariantCultureIgnoreCase);

            d.Add("foo");
            d.Add("world");
            d.Add("hello");
            d.Add("elvis");
            d.Add("ELVIS");
            d.Add(null);
            d.Add("Foo");
            d.AddMany(new string[] { "1", "2", "3", "4", "5", "6" });
            d.AddMany(new string[] { "7", "8", "9", "1", "2", "3" });

            Bag <string> result = (Bag <string>)InterfaceTests.SerializeRoundTrip(d);


            InterfaceTests.TestReadWriteCollectionGeneric(result,
                                                          new string[]
            {
                "1", "2", "3", "4", "5", "6", "elvis", "elvis", "hello", "foo", "foo",
                "WORLD", null, "7", "8", "9", "1", "2", "3"
            }, false,
                                                          StringComparer.InvariantCultureIgnoreCase.Equals);
        }
예제 #3
0
        public void Sum()
        {
            Bag <int> bagOdds   = new Bag <int>(new int[] { 1, 1, 1, 3, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 17, 17, 19 });
            Bag <int> 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.SumWith(bag2);
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 9, 11, 11, 13, 15, 17, 17, 19 }, false);

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

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

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

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

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

            bag1 = bagDigits.Clone();
            bag3 = bag1.Sum(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9 }, false);
        }
예제 #4
0
        public void RemoveMany()
        {
            Set <string> set1 = new Set <string>(StringComparer.InvariantCultureIgnoreCase);

            set1.Add("foo");
            set1.Add("Eric");
            set1.Add("Clapton");
            set1.Add(null);
            set1.Add("fudd");
            set1.Add("elmer");
            string[] s_array = { "FOO", "jasmine", "eric", null };
            int      count   = set1.RemoveMany(s_array);

            Assert.AreEqual(3, count);

            InterfaceTests.TestReadWriteCollectionGeneric(set1, new string[] { "Clapton", "elmer", "fudd" }, false);

            set1.Clear();
            set1.Add("foo");
            set1.Add("Eric");
            set1.Add("Clapton");
            set1.Add(null);
            set1.Add("fudd");
            count = set1.RemoveMany(set1);
            Assert.AreEqual(5, count);
            Assert.AreEqual(0, set1.Count);
        }
예제 #5
0
        public void Difference()
        {
            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 });

            // Algorithms work different depending on sizes, so try both ways.
            Set <int> set1 = setOdds.Clone();
            Set <int> set2 = setDigits.Clone();

            set1.DifferenceWith(set2);
            InterfaceTests.TestReadWriteCollectionGeneric(set1, new int[] { 11, 13, 15, 17, 19, 21, 23, 25 }, false);

            set1 = setOdds.Clone(); set2 = setDigits.Clone();
            set2.DifferenceWith(set1);
            InterfaceTests.TestReadWriteCollectionGeneric(set2, new int[] { 2, 4, 6, 8 }, false);

            set1 = setOdds.Clone(); set2 = setDigits.Clone();
            Set <int> set3 = set1.Difference(set2);

            InterfaceTests.TestReadWriteCollectionGeneric(set3, new int[] { 11, 13, 15, 17, 19, 21, 23, 25 }, false);

            set1 = setOdds.Clone(); set2 = setDigits.Clone();
            set3 = set2.Difference(set1);
            InterfaceTests.TestReadWriteCollectionGeneric(set3, new int[] { 2, 4, 6, 8 }, false);

            // Make sure intersection with itself works.
            set1 = setDigits.Clone();
            set1.DifferenceWith(set1);
            Assert.AreEqual(0, set1.Count);

            set1 = setDigits.Clone();
            set3 = set1.Difference(set1);
            Assert.AreEqual(0, set3.Count);
        }
예제 #6
0
        public void Difference()
        {
            Bag <int> bagOdds = new Bag <int>(new int[] { 1, 1, 1, 3, 3, 3, 5, 7, 7, 9, 11, 11, 13, 15, 17, 17, 19 });
            Bag <int> bagDigits = new Bag <int>(new int[] { 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 8, 9 });
            Bag <int> bag1, bag2, bag3;

            // Algorithms work different depending on sizes, so try both ways.
            bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone();
            bag1.DifferenceWith(bag2);
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new int[] { 1, 1, 11, 11, 13, 15, 17, 17, 19 }, false);

            bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone();
            bag2.DifferenceWith(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag2, new int[] { 2, 2, 4, 5, 6, 7, 7, 7, 7, 8 }, false);

            bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone();
            bag3 = bag1.Difference(bag2);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 1, 1, 11, 11, 13, 15, 17, 17, 19 }, false);

            bag1 = bagOdds.Clone(); bag2 = bagDigits.Clone();
            bag3 = bag2.Difference(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { 2, 2, 4, 5, 6, 7, 7, 7, 7, 8 }, false);

            // Make sure intersection with itself works.
            bag1 = bagDigits.Clone();
            bag1.DifferenceWith(bag1);
            Assert.AreEqual(0, bag1.Count);

            bag1 = bagDigits.Clone();
            bag3 = bag1.Difference(bag1);
            Assert.AreEqual(0, bag3.Count);
        }
예제 #7
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.set = new Set <InterfaceTests.Unique>();

            d.set.Add(d.objects[9]);
            d.set.Add(d.objects[10]);
            d.set.Add(d.objects[8]);
            d.set.Add(d.objects[11]);
            d.set.Add(d.objects[7]);
            d.set.Add(d.objects[12]);
            d.set.Add(d.objects[6]);
            d.set.Add(d.objects[13]);
            d.set.AddMany(new InterfaceTests.Unique[] { d.objects[0], d.objects[1], d.objects[2], d.objects[3], d.objects[4], d.objects[5] });
            d.set.AddMany(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.TestReadWriteCollectionGeneric(result.set, result.objects, false);

            for (int i = 0; i < result.objects.Length; ++i)
            {
                if (result.objects[i] != null)
                {
                    Assert.IsFalse(object.Equals(result.objects[i], d.objects[i]));
                }
            }
        }
예제 #8
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]));
                }
            }
        }
        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));
        }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
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);
        }
예제 #16
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);
        }
예제 #17
0
        public void CustomIComparer()
        {
            IEqualityComparer <int> myComparer = new ModularComparer(5);

            Bag <int> bag1 = new Bag <int>(myComparer);

            bag1.Add(3);
            bag1.Add(8);
            bag1.Add(12);
            bag1.Add(9);
            bag1.Add(13);
            bag1.Add(17);
            InterfaceTests.TestReadWriteCollectionGeneric <int>(bag1, new int[] { 3, 3, 3, 9, 12, 12 }, false);
        }
예제 #18
0
        public void ChangeNumberOfCopies()
        {
            Bag <string> bag1 = new Bag <string>(
                new string[] { "foo", null, "FOO", "Eric", "eric", "bar", null, "foO", "ERIC", "eric", null },
                StringComparer.InvariantCultureIgnoreCase);

            bag1.ChangeNumberOfCopies("Foo", 7);
            bag1.ChangeNumberOfCopies(null, 0);
            bag1.ChangeNumberOfCopies("eRIC", 0);
            bag1.ChangeNumberOfCopies("silly", 2);
            bag1.ChangeNumberOfCopies("BAR", 1);

            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new string[] { "foo", "foo", "foo", "foo", "foo", "foo", "foo", "bar", "silly", "silly" }, false);
        }
예제 #19
0
        public void RemoveAll()
        {
            Set <double> set1 = new Set <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });

            set1.RemoveAll(d => Math.Abs(d) > 5);
            InterfaceTests.TestReadWriteCollectionGeneric(set1, new double[] { -0.04, 1.2, 1.78, 4.5 }, false);

            set1 = new Set <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });
            set1.RemoveAll(d => d == 0);
            InterfaceTests.TestReadWriteCollectionGeneric(set1, new double[] { -7.6, -0.04, 1.2, 1.78, 4.5, 7.6, 10.11, 187.4 }, false);

            set1 = new Set <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });
            set1.RemoveAll(d => d < 200);
            Assert.AreEqual(0, set1.Count);
        }
예제 #20
0
        public void RemoveAll()
        {
            ReadWriteTestCollection <double> coll1 = new ReadWriteTestCollection <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });

            coll1.RemoveAll(delegate(double d) { return(Math.Abs(d) > 5); });
            InterfaceTests.TestReadWriteCollectionGeneric(coll1, new double[] { 4.5, 1.2, -0.04, 1.78 }, true, null);

            coll1 = new ReadWriteTestCollection <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });
            coll1.RemoveAll(delegate(double d) { return(d == 0); });
            InterfaceTests.TestReadWriteCollectionGeneric(coll1, new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 }, true, null);

            coll1 = new ReadWriteTestCollection <double>(new double[] { 4.5, 1.2, 7.6, -0.04, -7.6, 1.78, 10.11, 187.4 });
            coll1.RemoveAll(delegate(double d) { return(d < 200); });
            Assert.AreEqual(0, coll1.Count);
        }
예제 #21
0
        public void RemoveAll()
        {
            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 });

            bag1.RemoveAll(delegate(double d) { return(Math.Abs(d) > 5); });
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new double[] { -0.04, 1.2, 1.2, 1.78, 4.5 }, false);

            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 });
            bag1.RemoveAll(delegate(double d) { return(d == 0); });
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new double[] { -7.6, -0.04, 1.2, 1.2, 1.78, 4.5, 7.6, 10.11, 187.4, 187.4 }, false);

            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 });
            bag1.RemoveAll(delegate(double d) { return(d < 200); });
            Assert.AreEqual(0, bag1.Count);
        }
예제 #22
0
        public void CustomIComparer()
        {
            Set <int> set1 = new Set <int>(new ModularComparer(5));

            bool b = set1.Add(4); Assert.IsFalse(b);

            b = set1.Add(11); Assert.IsFalse(b);
            b = set1.Add(9); Assert.IsTrue(b);
            b = set1.Add(15); Assert.IsFalse(b);

            Assert.IsTrue(set1.Contains(25));
            Assert.IsTrue(set1.Contains(26));
            Assert.IsFalse(set1.Contains(27));

            InterfaceTests.TestReadWriteCollectionGeneric(set1, new int[] { 11, 9, 15 }, false);
        }
예제 #23
0
        public void Add()
        {
            Bag <string> bag1 = new Bag <string>(StringComparer.InvariantCultureIgnoreCase);

            bag1.Add("Hello");
            bag1.Add("foo");
            bag1.Add("");
            bag1.Add("HELLO");
            bag1.Add("foo");
            bag1.Add(null);
            bag1.Add("hello");
            bag1.Add("Eric");
            bag1.Add(null);

            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new string[] { null, null, "", "Eric", "foo", "foo", "Hello", "Hello", "Hello" }, false);
        }
예제 #24
0
        public void SerializeStrings()
        {
            Set <string> d = new Set <string>();

            d.Add("foo");
            d.Add("world");
            d.Add("hello");
            d.Add("elvis");
            d.Add("elvis");
            d.Add(null);
            d.Add("cool");
            d.AddMany(new string[] { "1", "2", "3", "4", "5", "6" });
            d.AddMany(new string[] { "7", "8", "9", "10", "11", "12" });

            Set <string> result = (Set <string>)InterfaceTests.SerializeRoundTrip(d);

            InterfaceTests.TestReadWriteCollectionGeneric((ICollection <string>)result, new string[] { "1", "2", "3", "4", "5", "6", "cool", "elvis", "hello", "foo", "world", null, "7", "8", "9", "10", "11", "12" }, false);
        }
예제 #25
0
        public void AddMany()
        {
            Bag <string> bag1 = new Bag <string>(StringComparer.InvariantCultureIgnoreCase);

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

            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new string[] { null, "Clapton", "Clapton", "elmer", "Eric", "foo", "foo", "fudd", "x" }, false);

            bag1.Clear();
            bag1.Add("foo");
            bag1.Add("Eric");
            bag1.AddMany(bag1);
            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new string[] { "Eric", "Eric", "foo", "foo" }, false);
        }
예제 #26
0
        public void Add()
        {
            var bag1 = new Bag <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                "Hello",
                "foo",
                "",
                "HELLO",
                "foo",
                null,
                "hello",
                "Eric",
                null
            };

            InterfaceTests.TestReadWriteCollectionGeneric(bag1,
                                                          new[] { null, null, "", "Eric", "foo", "foo", "Hello", "Hello", "Hello" },
                                                          false);
        }
예제 #27
0
        public void Clone()
        {
            Set <int> set1 = new Set <int>(new int[] { 1, 7, 9, 11, 13, 15, -17, 19, -21 });

            Set <int> set2 = set1.Clone();
            Set <int> set3 = (Set <int>)((ICloneable)set1).Clone();

            Assert.IsFalse(set2 == set1);
            Assert.IsFalse(set3 == set1);

            // Modify set1, make sure set2, set3 don't change.
            set1.Remove(9);
            set1.Remove(-17);
            set1.Add(8);

            InterfaceTests.TestReadWriteCollectionGeneric(set2, new int[] { -21, -17, 1, 7, 9, 11, 13, 15, 19 }, false);
            InterfaceTests.TestReadWriteCollectionGeneric(set3, new int[] { -21, -17, 1, 7, 9, 11, 13, 15, 19 }, false);

            set1 = new Set <int>();
            set2 = set1.Clone();
            Assert.IsFalse(set2 == set1);
            Assert.IsTrue(set1.Count == 0 && set2.Count == 0);
        }
예제 #28
0
        public void Clone()
        {
            Bag <int> bag1 = new Bag <int>(new int[] { 1, 7, 9, 11, 7, 13, 15, -17, 19, -21, 1 });

            Bag <int> bag2 = bag1.Clone();
            Bag <int> bag3 = (Bag <int>)((ICloneable)bag1).Clone();

            Assert.IsFalse(bag2 == bag1);
            Assert.IsFalse(bag3 == bag1);

            // Modify bag1, make sure bag2, bag3 don't change.
            bag1.Remove(9);
            bag1.Remove(-17);
            bag1.Add(8);

            InterfaceTests.TestReadWriteCollectionGeneric(bag2, new int[] { -21, -17, 1, 1, 7, 7, 9, 11, 13, 15, 19 }, false);
            InterfaceTests.TestReadWriteCollectionGeneric(bag3, new int[] { -21, -17, 1, 1, 7, 7, 9, 11, 13, 15, 19 }, false);

            bag1 = new Bag <int>();
            bag2 = bag1.Clone();
            Assert.IsFalse(bag2 == bag1);
            Assert.IsTrue(bag1.Count == 0 && bag2.Count == 0);
        }
예제 #29
0
        public void RemoveMany()
        {
            var bag1 = new Bag <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                "foo", "Eric", "Clapton", null, "Foo", "fudd", "elmer"
            };

            string[] s_array = { "FOO", "jasmine", "eric", null };
            int      count   = bag1.RemoveMany(s_array);

            Assert.AreEqual(3, count);

            InterfaceTests.TestReadWriteCollectionGeneric(bag1, new[] { "Clapton", "elmer", "foo", "fudd" }, false);

            bag1.Clear();
            bag1.Add("foo");
            bag1.Add("Eric");
            bag1.Add("Clapton");
            bag1.Add(null);
            bag1.Add("Foo");
            count = bag1.RemoveMany(bag1);
            Assert.AreEqual(5, count);
            Assert.AreEqual(0, bag1.Count);
        }