Example #1
0
        public static void Main(string[] args)
        {
            HashedSet<string> students = new HashedSet<string>();
            students.Add("Pesho");
            students.Add("Pesho");
            students.Add("Gosho");
            students.Remove("Gosho");
            students.Add("Misho");
            students.Add("Ivan");
            Console.WriteLine("Student count: {0}", students.Count);

            HashedSet<string> users = new HashedSet<string>();
            users.Add("Mariq");
            users.Add("Pesho");
            users.Add("Misho");

            HashedSet<string> intersection = students.Intersect(users);
            Console.WriteLine("Intersection:");
            foreach (var name in intersection)
            {
                Console.WriteLine(name);
            }

            HashedSet<string> union = students.Union(users);
            Console.WriteLine("Union: ");
            foreach (var name in union)
            {
                Console.WriteLine(name);
            }
        }
        public static void Main()
        {
            var firstSet = new HashedSet<string>();
            var secondSet = new HashedSet<string>();

            firstSet.Add("Pesho");
            firstSet.Add("Gosho");
            firstSet.Add("Tosho");

            secondSet.Add("Ivan");
            secondSet.Add("Petkan");
            secondSet.Add("Dragan");

            Console.WriteLine(firstSet);
            Console.WriteLine(secondSet);

            Console.WriteLine(firstSet.Intersect(secondSet));
            Console.WriteLine(secondSet.Intersect(firstSet));

            Console.WriteLine(firstSet.Union(secondSet));
            Console.WriteLine(secondSet.Union(firstSet));

            firstSet.Remove("Pesho");
            firstSet.Remove("Tosho");
            Console.WriteLine(firstSet);

            Console.WriteLine(firstSet.Find("Tosho"));
            Console.WriteLine(firstSet.Find("Gosho"));

            Console.WriteLine(firstSet.Count);
        }
    public static void Main()
    {
        HashedSet<float> firstSet = new HashedSet<float>();
        firstSet.Add(1f);
        firstSet.Add(1.4f);
        firstSet.Add(1.7f);
        firstSet.Add(2f);
        firstSet.Add(2.2f);
        firstSet.Remove(1.7f);
        Console.WriteLine(firstSet.Find(1f));
        Console.WriteLine(firstSet.Count);

        HashedSet<float> secondSet = new HashedSet<float>();
        secondSet.Add(1f);
        secondSet.Add(2f);
        secondSet.Add(3f);
        secondSet.Add(5f);

        HashedSet<float> thirdSet = new HashedSet<float>();
        thirdSet.Add(1f);
        thirdSet.Add(2f);
        thirdSet.Add(3f);
        thirdSet.Add(5f);

        secondSet.Union(firstSet);
        thirdSet.Intersect(firstSet);
        firstSet.Clear();
    }
Example #4
0
        static void Main()
        {
            var set = new HashedSet<int>();

            set.Add(5);
            set.Add(3);
            set.Add(-4);
            set.Add(12);
            set.Add(0);
            set.Add(-50);
            set.Add(10);
            Console.WriteLine("Set contains 12 -> {0}", set.Find(12));
            Console.WriteLine("Set contains 13 -> {0}", set.Find(13));
            set.Remove(10);
            Console.WriteLine("Removed 10\nSet contains 10 -> {0}", set.Find(10));
            Console.WriteLine("Set contains {0} items", set.Count);
            Console.WriteLine("Set 1: {0}", set);

            var anotherSet = new HashedSet<int>();
            anotherSet.Add(-4);
            anotherSet.Add(15);
            anotherSet.Add(0);
            anotherSet.Add(-122);
            anotherSet.Add(35);
            Console.WriteLine("Set 2: {0}", anotherSet);

            set.Union(anotherSet);
            Console.WriteLine("Set after union: {0}", set);

            set.Intersect(anotherSet);
            Console.WriteLine("Set after intersect: {0}", set);

            set.Clear();
            Console.WriteLine("Set contains {0} items after clear", set.Count);
        }
Example #5
0
        public void Union_Test()
        {
            HashedSet<int> set = new HashedSet<int>();
            HashedSet<int> otherSet = new HashedSet<int>();

            set.Add(1);
            set.Add(2);
            set.Add(3);

            otherSet.Add(3);
            otherSet.Add(4);
            otherSet.Add(5);

            set.Union(otherSet);

            StringBuilder actual = new StringBuilder();
            foreach (var item in set)
            {
                actual.Append(item + " ");
            }

            string expected = "1 2 3 4 5 ";

            Assert.AreEqual(expected, actual.ToString());
        }
Example #6
0
        static void Main()
        {
            HashedSet<string> myBestFriends = new HashedSet<string>();

            myBestFriends.Add("Ivan");
            myBestFriends.Add("Daniel");
            myBestFriends.Add("Cecilia");

            Console.WriteLine(myBestFriends.Count);

            myBestFriends.Remove("Cecilia");
            Console.WriteLine(myBestFriends.Count);

            HashedSet<string> yourBestFriends = new HashedSet<string>();

            yourBestFriends.Add("Petar");
            yourBestFriends.Add("Daniel");
            yourBestFriends.Add("Monika");

            HashedSet<string> allBestFriends = myBestFriends.Union(yourBestFriends);

            Console.WriteLine("All best friends: ");
            foreach (var item in allBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }

            HashedSet<string> mutualBestFriends = myBestFriends.Intersect(yourBestFriends);

            Console.WriteLine("Mutual best friends: ");
            foreach (var item in mutualBestFriends.setOfData)
            {
                Console.WriteLine("{0}", item.Value);
            }
        }
        public void UnionExpectedToWorkProperly()
        {
            var firstSet = new HashedSet <string>();

            for (int i = 1; i <= 10; i++)
            {
                firstSet.Add("test" + i);
            }

            var secondSet = new HashedSet <string>();

            for (int i = 5; i <= 15; i++)
            {
                secondSet.Add("test" + i);
            }

            firstSet.Union(secondSet);

            Assert.AreEqual(15, firstSet.Count);

            for (int i = 1; i <= 15; i++)
            {
                Assert.IsTrue(firstSet.Find("test" + i));
            }
        }
Example #8
0
        public void UnionShouldWorkCorrectlyOnValidInput()
        {
            var set1 = new HashedSet <int>();

            set1.Add(5);
            set1.Add(3);

            var set2 = new HashedSet <int>();

            set2.Add(5);
            set2.Add(4);

            var expectedResultElements = new List <int>()
            {
                3, 4, 5
            };

            set1.Union(set2);

            foreach (var value in set1)
            {
                expectedResultElements.Remove(value);
            }

            Assert.AreEqual(0, expectedResultElements.Count);
        }
Example #9
0
        public static void Main()
        {
            var set = new HashedSet <int>();

            for (int i = 1; i < 11; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    set.Add(i);
                }
            }

            System.Console.WriteLine(set);
            System.Console.WriteLine(set.Count);

            var otherSet = new HashedSet <int>();

            for (int i = 5; i < 16; i++)
            {
                otherSet.Add(i);
            }

            System.Console.WriteLine(otherSet);
            System.Console.WriteLine(otherSet.Count);
            System.Console.WriteLine(set.IntersectsWith(otherSet));
            System.Console.WriteLine(set.Union(otherSet));
        }
Example #10
0
        public void Union_Test()
        {
            HashedSet <int> set      = new HashedSet <int>();
            HashedSet <int> otherSet = new HashedSet <int>();

            set.Add(1);
            set.Add(2);
            set.Add(3);

            otherSet.Add(3);
            otherSet.Add(4);
            otherSet.Add(5);

            set.Union(otherSet);

            StringBuilder actual = new StringBuilder();

            foreach (var item in set)
            {
                actual.Append(item + " ");
            }

            string expected = "1 2 3 4 5 ";

            Assert.AreEqual(expected, actual.ToString());
        }
        static void Main()
        {
            var mySet = new HashedSet<string>();
            mySet.Add("string");
            mySet.Add("str");
            //mySet.Add(null);
            mySet.Add("strength");
            mySet.Add("string");

            //var strength = mySet.Find("strength");
            //Console.WriteLine(strength);

            //var isStringRemoved = mySet.Remove("string");
            //Console.WriteLine(isStringRemoved);

            var mySecondSet = new HashedSet<string>();
            mySecondSet.Add("strength");
            mySecondSet.Add("dexterity");
            mySecondSet.Add("intelligence");

            mySet.Union(mySecondSet);
            //mySet.Intersect(mySecondSet);
            foreach (var item in mySet)
            {
                Console.WriteLine(item);
            }
        }
        public void HashedSetUnionTestSameElementsInBoth()
        {
            HashedSet<int> firstSet = new HashedSet<int>();
            int firstSetLength = 5;
            for (int i = 0; i < firstSetLength; i++)
            {
                firstSet.Add(i);
            }

            HashedSet<int> secondSet = new HashedSet<int>();
            int secondSetLength = 5;
            for (int i = 0; i < secondSetLength; i++)
            {
                secondSet.Add(i);
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect set count!");
            Assert.AreEqual(secondSetLength, secondSet.Count, "Incorrect set count!");

            firstSet.Union(secondSet);

            for (int i = 0; i < firstSetLength; i++)
            {
                Assert.IsTrue(firstSet.Contains(i), "Incorrect union!");
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect amount of elements after union");
        }
Example #13
0
        public static void Main()
        {
            var set = new HashedSet<int>();

            for (int i = 1; i < 11; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    set.Add(i);
                }
            }

            System.Console.WriteLine(set);
            System.Console.WriteLine(set.Count);

            var otherSet = new HashedSet<int>();

            for (int i = 5; i < 16; i++)
            {
                otherSet.Add(i);
            }

            System.Console.WriteLine(otherSet);
            System.Console.WriteLine(otherSet.Count);
            System.Console.WriteLine(set.IntersectsWith(otherSet));
            System.Console.WriteLine(set.Union(otherSet));
        }
Example #14
0
        public void HashedSetUnionTestSameElementsInBoth()
        {
            HashedSet <int> firstSet       = new HashedSet <int>();
            int             firstSetLength = 5;

            for (int i = 0; i < firstSetLength; i++)
            {
                firstSet.Add(i);
            }

            HashedSet <int> secondSet       = new HashedSet <int>();
            int             secondSetLength = 5;

            for (int i = 0; i < secondSetLength; i++)
            {
                secondSet.Add(i);
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect set count!");
            Assert.AreEqual(secondSetLength, secondSet.Count, "Incorrect set count!");

            firstSet.Union(secondSet);

            for (int i = 0; i < firstSetLength; i++)
            {
                Assert.IsTrue(firstSet.Contains(i), "Incorrect union!");
            }

            Assert.AreEqual(firstSetLength, firstSet.Count, "Incorrect amount of elements after union");
        }
Example #15
0
        public void UnionShouldThrowOnInvalidInput()
        {
            var set1 = new HashedSet <int>();

            set1.Add(5);
            set1.Add(3);

            set1.Union(null);
        }
Example #16
0
        public void TestUnionMethodWithIntegersButEmptySets()
        {
            HashedSet <int> first  = new HashedSet <int>();
            HashedSet <int> second = new HashedSet <int>();

            first.Union(second);

            Assert.AreEqual(0, first.Count);
        }
        public void ShouldReturnCorrectUnion()
        {
            var set = new HashedSet<int>();
            set.Add(1);
            set.Add(2);
            var otherSet = new HashedSet<int>();
            otherSet.Add(2);
            otherSet.Add(3);

            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, set.Union(otherSet));
        }
Example #18
0
        public void ShouldReturnCorrectUnion()
        {
            var set = new HashedSet <int>();

            set.Add(1);
            set.Add(2);
            var otherSet = new HashedSet <int>();

            otherSet.Add(2);
            otherSet.Add(3);

            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, set.Union(otherSet));
        }
        public void UnionTest()
        {
            // Assemble
            var hs1 = new HashedSet(new long[] { 1, 2, 3, 4, 5, 6, 7 });
            var hs2 = new HashedSet(new long[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
            // Act
            var actual = hs1.Union(hs2);

            // Assert
            var expected = new UnionSet(hs1, hs2);

            Assert.AreEqual(expected, actual);
        }
Example #20
0
    static void Main(string[] args)
    {
        HashedSet <int> testHashSet = new HashedSet <int>(2);

        Console.WriteLine("Current HashSet count: {0}", testHashSet.Count);

        testHashSet.Add(1);
        testHashSet.Add(2);
        testHashSet.Add(2);
        testHashSet.Add(2);
        testHashSet.Add(3);
        testHashSet.Add(4);
        testHashSet.Add(5);
        testHashSet.Add(6);

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("Current HashSet content:");
        PrintHashSet(testHashSet);

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("Current HashSet count: {0}", testHashSet.Count);

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("Check if value 1 exist in the HashSet: {0}", testHashSet.Find(1));

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("Check if value 11 exist in the HashSet: {0}", testHashSet.Find(11));

        testHashSet.Remove(5);
        Console.WriteLine(new String('*', 30));
        Console.WriteLine("HashSet content after removing 5:");
        PrintHashSet(testHashSet);

        HashedSet <int> testHashSet2 = new HashedSet <int>(2);

        testHashSet2.Add(1);
        testHashSet2.Add(2);
        testHashSet2.Add(12);

        HashedSet <int> testHashSetUnion = testHashSet.Union(testHashSet2);

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("HashSet union with HashSet [1, 2, 12]:");
        PrintHashSet(testHashSetUnion);

        HashedSet <int> testHashSetIntersection = testHashSet.Intersection(testHashSet2);

        Console.WriteLine(new String('*', 30));
        Console.WriteLine("HashSet intersection with HashSet [1, 2, 12]:");
        PrintHashSet(testHashSetIntersection);
    }
Example #21
0
        public static void Main(string[] args)
        {
            var hashedSet1 = new HashedSet<string>();

            for (int i = 0; i < 4; i++)
            {
                hashedSet1.Add("pesho" + i);
            }

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("First hashed set:");
            foreach (var item in hashedSet1)
            {
                 Console.WriteLine(item);
            }

            var hashedSet2 = new HashedSet<string>();

            for (int i = 2; i < 6; i++)
            {
                hashedSet2.Add("pesho" + i);
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nSecond hashed set:");
            foreach (var item in hashedSet2)
            {
                Console.WriteLine(item);
            }


            var intersected = hashedSet1.Intersect(hashedSet2);

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("\nIntersected:");
            foreach (var item in intersected)
            {
                Console.WriteLine(item);
            }

            var unioned = hashedSet1.Union(hashedSet2);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nUnioned:");
            foreach (var item in unioned)
            {
                Console.WriteLine(item);
            }
        }
Example #22
0
        public static void Main()
        {
            HashedSet<string> hashedSet = new HashedSet<string>();
            for (int i = 0; i < 5; i++)
            {
                hashedSet.Add("item " + i);
            }

            var set = new List<string> { "item 3", "item 5" };
            var unionSet = hashedSet.Union(set);
            var intersectSet = hashedSet.Intersect(set);

            Console.WriteLine("Union: {0}", string.Join(", ", unionSet));
            Console.WriteLine("Intersect: {0}", string.Join(", ", intersectSet));
        }
Example #23
0
        public virtual void HybridUnionOperator()
        {
            ISet b = new HashedSet();
            ISet a = CreateInstance() as ISet;

            a.Add("one");
            b.Add("two");
            ISet c = a.Union(b);

            Assert.AreEqual(2, c.Count);
            Assert.IsTrue(c.Contains("one") && c.Contains("two"));

            ISet d = b.Union(a);

            Assert.AreEqual(2, d.Count);
            Assert.IsTrue(d.Contains("one") && d.Contains("two"));
        }
Example #24
0
    static void Main()
    {
        HashedSet <string> mySet = new HashedSet <string>();

        mySet.Add("Gogo");
        mySet.Add("Mimi");
        mySet.Add("Tosho");
        mySet.Add("Pesho");
        mySet.Add("Vankata");

        HashedSet <string> otherSet = new HashedSet <string>();

        otherSet.Add("Tosho");
        otherSet.Add("Pesho");
        otherSet.Add("Moni");

        Console.WriteLine(mySet.Find("Gogo"));
        Console.WriteLine(mySet.Find("Gogo2"));

        mySet.Remove("Gogo");

        var union     = mySet.Union(otherSet);
        var intersect = mySet.Intersect(otherSet);

        Console.WriteLine(mySet.Count());


        Console.WriteLine("\nMySet");
        foreach (var item in mySet)
        {
            Console.WriteLine(item.ToString());
        }

        Console.WriteLine("\nUnion");
        foreach (var item in union)
        {
            Console.WriteLine(item.ToString());
        }

        Console.WriteLine("\nIntersect");
        foreach (var item in intersect)
        {
            Console.WriteLine(item.ToString());
        }
    }
        static void Main()
        {
            HashedSet <int> hSet = new HashedSet <int>();

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(5);

            Console.WriteLine(hSet.Find(45));
            Console.WriteLine(hSet.Find(15));
            hSet.Remove(5);
            Console.WriteLine(hSet.Find(5));

            hSet.Clear();

            Console.WriteLine(hSet.Count);

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(25);
            hSet.Add(35);

            HashedSet <int> hSetTwo = new HashedSet <int>();

            hSetTwo.Add(4);
            hSetTwo.Add(24);
            hSetTwo.Add(25);
            hSetTwo.Add(35);

            var newIntersectedSet = hSet.Intersect(hSetTwo);

            foreach (var item in newIntersectedSet.Keys)
            {
                Console.WriteLine(item);
            }

            var newUnitedSet = hSet.Union(hSetTwo);

            foreach (var item in newUnitedSet.Keys)
            {
                Console.WriteLine(item);
            }
        }
 internal static void Main()
 {
     HashedSet<int> test = new HashedSet<int>();
     HashedSet<int> other = new HashedSet<int>();
     test.Add(1);
     test.Add(2);
     test.Add(3);
     test.Add(4);
     test.Add(5);
     test.Add(6);
     other.Add(4);
     other.Add(5);
     other.Add(6);
     other.Add(7);
     other.Add(8);
     Console.WriteLine("Initial hash set:");
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("After removal of 3:");
     test.Remove(3);
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Is 1 found? {0}", test.Find(1));
     Console.WriteLine("Is 3 found? {0}", test.Find(3));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("First hash set:");
     Console.WriteLine(string.Join(", ", test));
     Console.WriteLine("Member count: {0}", test.Count);
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Second hash set:");
     Console.WriteLine(string.Join(", ", other));
     Console.WriteLine("Member count: {0}", other.Count);
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Intersect of the first and second:");
     Console.WriteLine(string.Join(", ", test.Intersect(other)));
     Console.WriteLine("--------------------------------------------------------------");
     Console.WriteLine("Union of the first and second:");
     Console.WriteLine(string.Join(", ", test.Union(other)));
     Console.WriteLine("--------------------------------------------------------------");
     test.Clear();
     Console.WriteLine("First hash set after clear:");
     Console.WriteLine(string.Join(", ", test));
 }
        static void Main()
        {
            HashedSet<int> hSet = new HashedSet<int>();

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(5);

            Console.WriteLine(hSet.Find(45));
            Console.WriteLine(hSet.Find(15));
            hSet.Remove(5);
            Console.WriteLine(hSet.Find(5));

            hSet.Clear();

            Console.WriteLine(hSet.Count);

            hSet.Add(5);
            hSet.Add(15);
            hSet.Add(25);
            hSet.Add(35);

            HashedSet<int> hSetTwo = new HashedSet<int>();
            hSetTwo.Add(4);
            hSetTwo.Add(24);
            hSetTwo.Add(25);
            hSetTwo.Add(35);

            var newIntersectedSet = hSet.Intersect(hSetTwo);

            foreach (var item in newIntersectedSet.Keys)
            {
                Console.WriteLine(item);
            }

            var newUnitedSet = hSet.Union(hSetTwo);

            foreach (var item in newUnitedSet.Keys)
            {
                Console.WriteLine(item);
            }
        }
    /* Task 5: 
     * Implement the data structure "set" in a class HashedSet<T> using your class HashTable<K,T>
     * to hold the elements. Implement all standard set operations like Add(T), Find(T), Remove(T),
     * Count, Clear(), union and intersect.
     */

    static void Main(string[] args)
    {
        var setOne = new HashedSet<int>();

        for (int i = 0; i < 50; i++)
        {
            setOne.Add(i);
        }

        Console.WriteLine(setOne.Count());

        for (int i = 25; i < 50; i++)
        {
            setOne.Remove(i);
        }

        Console.WriteLine(setOne.Count());

        var setTwo = new HashedSet<int>();

        setTwo.Add(100);
        setTwo.Add(101);
        setTwo.Add(102);
        setTwo.Add(103);
        setTwo.Add(104);
        setTwo.Add(105);

        //Saving all results from Union
        setOne = setOne.Union(setTwo);
        Console.WriteLine(setOne.Count());

        setTwo.Clear();
        for (int i = 10; i < 25; i++)
        {
            setTwo.Add(i);
        }

        //Saving only the intersect Results
        setOne = setOne.Intersect(setTwo);
        Console.WriteLine(setOne.Count());
    }
        static void Main(string[] args)
        {
            var set = new HashedSet<int>();
            set.Add(1);
            set.Add(1);
            set.Add(1);
            set.Add(1);
            Console.WriteLine(set.Count);
            set.Add(2);
            set.Add(3);
            set.Add(4);
            set.Add(10);

            var otherSet = new HashedSet<int>();
            otherSet.Add(1);
            otherSet.Add(2);
            otherSet.Add(190);

            Console.WriteLine(string.Join(",",set.Union(otherSet)));
            Console.WriteLine(string.Join(",", set.Intersect(otherSet)));
        }
Example #30
0
        static void Main(string[] args)
        {
            HashedSet<int> hashedSet = new HashedSet<int>();
            for (int i = 0; i < 10; i++)
            {
                hashedSet.Add(i);
            }
            Console.WriteLine("First hashedset -> {0}", string.Join(" ", hashedSet.Values));

            HashedSet<int> otherHashedSet = new HashedSet<int>();
            for (int i = 5; i < 15; i++)
            {
                otherHashedSet.Add(i);
            }
            Console.WriteLine("Second hashedset -> {0}", string.Join(" ", otherHashedSet.Values));

            var unionSet = hashedSet.Union(otherHashedSet);
            Console.WriteLine("After union -> {0}", string.Join(" ", unionSet.Values));

            var intersectSet = hashedSet.Intersect(otherHashedSet);
            Console.WriteLine("After intersect -> {0}", string.Join(" ", intersectSet.Values));
        }
Example #31
0
        static void Main(string[] args)
        {
            var set = new HashedSet<int>(new[] { 1, 2, 3, 4, 5 });
            Console.WriteLine("Set: {0}", set);

            // Add
            set.Add(6);
            Console.WriteLine("Add '6' -> {0}", set);

            // Add existing
            set.Add(6);
            Console.WriteLine("Add '6' -> {0}", set);

            // Find
            Console.WriteLine("Find '0': {0}", set.Find(0));
            Console.WriteLine("Find '6': {0}", set.Find(6));

            // Remove
            set.Remove(3);
            Console.WriteLine("Remove '3' -> {0}", set);

            // Count
            Console.WriteLine("Number of elements: {0}", set.Count);

            // Union
            var collection = new[] { 3, 7 };
            set.Union(collection);
            Console.WriteLine("Union with [{0}] -> {1}", string.Join(", ", collection), set);

            // Intersection
            collection = new[] { 5, 6, 7, 8, 9 };
            set.Intersect(collection);
            Console.WriteLine("Intersection with [{0}] -> {1}", string.Join(", ", collection), set);

            // Clear
            set.Clear();
            Console.WriteLine("Clear set...");
            Console.WriteLine("Number of elements: {0}", set.Count);
        }
Example #32
0
        public void UnionExpectedToWorkProperly()
        {
            var firstSet = new HashedSet<string>();
            for (int i = 1; i <= 10; i++)
            {
                firstSet.Add("test" + i);
            }

            var secondSet = new HashedSet<string>();
            for (int i = 5; i <= 15; i++)
            {
                secondSet.Add("test" + i);
            }

            firstSet.Union(secondSet);

            Assert.AreEqual(15, firstSet.Count);

            for (int i = 1; i <= 15; i++)
            {
                Assert.IsTrue(firstSet.Find("test" + i));
            }
        }
Example #33
0
        public void TestUnionMethodWithIntegers()
        {
            HashedSet <int> odds = new HashedSet <int>();

            odds.Add(1);
            odds.Add(3);
            odds.Add(5);

            HashedSet <int> evens = new HashedSet <int>();

            evens.Add(2);
            evens.Add(4);
            evens.Add(6);

            odds.Union(evens);

            Assert.AreEqual(6, odds.Count);

            for (int i = 1; i < odds.Count; i++)
            {
                int result = odds.Find(i);
                Assert.AreEqual(i, result);
            }
        }
        public void TestUnionShouldProperlyWork()
        {
            var set1 = new HashedSet<string>();
            set1.Add("Pesho");
            var set2 = new HashedSet<string>();
            set2.Add("Gosho");

            var result = set1.Union(set2);
            Assert.AreEqual(2, result.Count);
        }