Exemplo n.º 1
0
        public void HashSetWithBuiltInComparer_HashSetContainsNotUsed()
        {
            IEnumerable<string> input1 = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "a" };
            IEnumerable<string> input2 = new[] { "A" };

            Assert.Equal(Enumerable.Empty<string>(), input1.Intersect(input2));
            Assert.Equal(Enumerable.Empty<string>(), input1.Intersect(input2, null));
            Assert.Equal(Enumerable.Empty<string>(), input1.Intersect(input2, EqualityComparer<string>.Default));
            Assert.Equal(new[] { "a" }, input1.Intersect(input2, StringComparer.OrdinalIgnoreCase));

            Assert.Equal(Enumerable.Empty<string>(), input2.Intersect(input1));
            Assert.Equal(Enumerable.Empty<string>(), input2.Intersect(input1, null));
            Assert.Equal(Enumerable.Empty<string>(), input2.Intersect(input1, EqualityComparer<string>.Default));
            Assert.Equal(new[] { "A" }, input2.Intersect(input1, StringComparer.OrdinalIgnoreCase));
        }
Exemplo n.º 2
0
        public void should_get_sequences_intersection()
        {
            var firstSequence = new[] { 1, 2, 3 };
            var secondSequence = new[] { 4, 3, 5 };

            IEnumerable<int> intersection = firstSequence.Intersect(secondSequence);

            // please update variable value to fix the test.
            IEnumerable<int> expectedIntersection = new[] { 1, 2, 3 };

            Assert.Equal(expectedIntersection, intersection);
        }