Пример #1
0
            public void ShouldReturnTrue_WhenGivenNulls()
            {
                // Arrange
                var sut = new MultiSetComparer <int>();

                // Act
                bool result = sut.Equals(null, null);

                // Assert
                Assert.True(result);
            }
Пример #2
0
            public void ShouldReturnFalse_WhenGivenCollectionAndNull()
            {
                // Arrange
                var set0 = new int[0];
                var sut  = new MultiSetComparer <int>();

                // Act
                bool result = sut.Equals(set0, null);

                // Assert
                Assert.False(result);
            }
Пример #3
0
            public void ShouldReturnTrue_WhenGivenEmptyCollections()
            {
                // Arrange
                var set0 = new int[0];
                var set1 = new List <int>();
                var sut  = new MultiSetComparer <int>();

                // Act
                bool result = sut.Equals(set0, set1);

                // Assert
                Assert.True(result);
            }
Пример #4
0
            public void ShouldUseGivenComparerForComparisons()
            {
                // Arrange
                var set0 = new[] { "B", "D", "g", "g", "A", "C", "E", "e", "E" };
                var set1 = new[] { "b", "d", "G", "G", "A", "C", "e", "e", "e" };
                var sut  = new MultiSetComparer <string>(StringComparer.OrdinalIgnoreCase);

                // Act
                bool result = sut.Equals(set0, set1);

                // Assert
                Assert.True(result);
            }
Пример #5
0
            public void ShouldHaveSameHashCode_WhenGivenEquivalentCollectionsAccordingToGivenComparer()
            {
                // Arrange
                var c1       = new[] { "A", "B", "C" };
                var c2       = new[] { "a", "b", "c" };
                var comparer = new MultiSetComparer <String>(StringComparer.OrdinalIgnoreCase);

                // Act
                int h1 = comparer.GetHashCode(c1);
                int h2 = comparer.GetHashCode(c2);

                // Assert
                Assert.Equal(h1, h2);
            }
Пример #6
0
        /// <inheritdoc />
        public bool Equals(IEnumerable <T> x, IEnumerable <T> y)
        {
            if (x == null)
            {
                return(y == null);
            }

            if (y == null)
            {
                return(false);
            }

            if (Object.ReferenceEquals(x, y))
            {
                return(true);
            }

            if (MultiSetComparer <T> .HaveMismatchingCounts(x, y))
            {
                return(false);
            }

            return(!HaveMismatchedElement(x, y));
        }