Esempio n. 1
0
        public Comparer(IEnumerable <string> itemsA, IEnumerable <string> itemsB)
        {
            var HashA = new HashSet <String>(itemsA);
            var HashB = new HashSet <String>(itemsB);

            foreach (var item in HashB)
            {
                if (HashA.Contains(item))
                {
                    BothAandB.Add(item);
                }
                else
                {
                    OnlyB.Add(item);
                }
            }

            foreach (var item in HashA)
            {
                if (!HashB.Contains(item))
                {
                    OnlyA.Add(item);
                }
            }

            OnlyAorB.AddRange(OnlyA);
            OnlyAorB.AddRange(OnlyB);


            OnlyA.Sort();
            OnlyB.Sort();
            OnlyAorB.Sort();
            BothAandB.Sort();
        }
        public void TryVenn()
        {
            var list1 = new[] { 4, 5, 6, 7, 1, 2, 3 };
            var list2 = new[] { 8, 9, 10, 6, 7 };

            var(OnlyA, AandB, OnlyB) = list1.Venn(list2);
            var AtAOnly = Enumerable.Range(1, 5);
            var AtAB    = Enumerable.Range(6, 2);
            var AtBOnly = Enumerable.Range(8, 3);

            Assert.IsTrue(OnlyA.ContentEquals(AtAOnly));
            Assert.IsTrue(AandB.ContentEquals(AtAB));
            Assert.IsTrue(OnlyB.ContentEquals(AtBOnly));
        }