예제 #1
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);
        }
예제 #2
0
        public void Add()
        {
            ISet <string> set1 = new Set <string>(StringComparer.InvariantCultureIgnoreCase);
            bool          b;

            b = set1.Add("hello");
            Assert.IsTrue(b);
            b = set1.Add("foo");
            Assert.IsTrue(b);
            b = set1.Add("");
            Assert.IsTrue(b);
            b = set1.Add("HELLO");
            Assert.IsFalse(b);
            b = set1.Add("foo");
            Assert.IsFalse(b);
            b = set1.Add("Hello");
            Assert.IsFalse(b);
            b = set1.Add("Eric");
            Assert.IsTrue(b);
            InterfaceTests.TestCollectionGeneric(set1, new string[] { "", "Eric", "foo", "hello" }, false, null);
        }
예제 #3
0
        public void SymmetricExcept()
        {
            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.SymmetricExceptWith(set2);
            InterfaceTests.TestCollectionGeneric(set1, new int[] { 2, 4, 6, 8, 11, 13, 15, 17, 19, 21, 23, 25 }, false, null);

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

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

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

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

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

            // Make sure intersection with itself works.
            set1 = new Set <int>(setDigits);
            set1.SymmetricExceptWith(set1);
            Assert.AreEqual(0, set1.Count);

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

            Assert.AreEqual(0, set3.Count);
        }