Пример #1
0
        public void OfNullCollection_ShouldHaveZeroHashCode()
        {
            var firstCollection = (string[])null;
            var firstByValue    = new CollectionByValue <string>(firstCollection, StrictOptions);

            Assert.AreEqual(0, firstByValue.GetHashCode());
        }
Пример #2
0
        public bool Equals(CollectionByValue <T> other)
        {
            if (other is null)
            {
                return(false);
            }

            var inOrder = Options.InOrder || other.Options.InOrder;

            if (inOrder)
            {
                if (_collection is null)
                {
                    return(other._collection is null);
                }
                if (other._collection is null)
                {
                    return(false);
                }

                if (_collection.Count != other._collection.Count)
                {
                    return(false);
                }

                return(_collection.SequenceEqual(other._collection, Options.EqualityComparer));
            }
            else
            {
                return(MultiSetEqualityComparer.Equals(_collection, other._collection, Options.EqualityComparer));
            }
        }
Пример #3
0
        public void ToString_OfNullCollection_ShouldReturnTypeAndNullMark()
        {
            var byValue = new CollectionByValue <int>((int[])null, new Options <int>(true, null));

            var result = byValue.ToString();

            Assert.AreEqual("<null> of Int32", result);
        }
Пример #4
0
        public void ToString_OfEmptyCollection_ShouldReturnCountOfCollectionAndAllItems()
        {
            var byValue = new CollectionByValue <int>(new int[] { }, new Options <int>(true, null));

            var result = byValue.ToString();

            Assert.AreEqual("0:[]", result);
        }
Пример #5
0
        public void ToString_ShouldReturnCountOfCollectionAndAllItems()
        {
            var byValue = new CollectionByValue <string>(new[] { "qwe", "asd" }, StrictOptions);

            var result = byValue.ToString();

            Assert.AreEqual("2:[qwe,asd]", result);
        }
Пример #6
0
        public void WithNotStrictOrdering_OfShuffledCollections_ShouldBeEqual()
        {
            var firstCollection  = new[] { "1", "2" };
            var secondCollection = new[] { "2", "1" };
            var firstByValue     = new CollectionByValue <string>(firstCollection, NotStrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, NotStrictOptions);

            CollectionByValueAssert.AreEqual(firstByValue, secondByValue);
        }
Пример #7
0
        public void WithStrictOrdering_OfCollectionsWithSameItems_ShouldBeEqual()
        {
            var firstCollection  = new[] { "1", "2" };
            var secondCollection = new[] { "1", "2" };
            var firstByValue     = new CollectionByValue <string>(firstCollection, StrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, StrictOptions);

            CollectionByValueAssert.AreEqual(firstByValue, secondByValue);
        }
Пример #8
0
        public void OfCollectionsOfDifferentTypes_ShouldNotBeEqual()
        {
            var firstCollection  = new byte[] { 1, 2 };
            var secondCollection = new int[] { 1, 2 };
            var firstByValue     = new CollectionByValue <byte>(firstCollection, new Options <byte>(true, null));
            var secondByValue    = new CollectionByValue <int>(secondCollection, new Options <int>(true, null));

            CollectionByValueAssert.AreNotEqual(firstByValue, secondByValue);
        }
Пример #9
0
        public void OfEmptyCollection_ShouldNotBeEqualToOfNullCollection()
        {
            var firstCollection  = new string[] { };
            var secondCollection = (string[])null;
            var firstByValue     = new CollectionByValue <string>(firstCollection, NotStrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, NotStrictOptions);

            CollectionByValueAssert.AreNotEqual(firstByValue, secondByValue);
        }
Пример #10
0
        public void OfNullCollectionsOfDifferentTypes_ShouldNotBeEqual()
        {
            var firstCollection  = (string[])null;
            var secondCollection = (int[])null;
            var firstByValue     = new CollectionByValue <string>(firstCollection, StrictOptions);
            var secondByValue    = new CollectionByValue <int>(secondCollection, new Options <int>(true, null));

            CollectionByValueAssert.AreNotEqual(firstByValue, secondByValue);
        }
Пример #11
0
        public void OfSameCountCollectionsWithSameFirstItem_ShouldHaveSameHashCode()
        {
            var firstCollection  = new[] { "1" };
            var secondCollection = new[] { "1" };
            var firstByValue     = new CollectionByValue <string>(firstCollection, StrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, StrictOptions);

            Assert.AreEqual(firstByValue.GetHashCode(), secondByValue.GetHashCode());
        }
Пример #12
0
        public void OfCollectionsWithDifferentOrdering_WithShuffledItems_ShouldNotBeEqual()
        {
            var firstCollection  = new[] { "1", "2" };
            var secondCollection = new[] { "2", "1" };
            var firstByValue     = new CollectionByValue <string>(firstCollection, StrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, NotStrictOptions);

            CollectionByValueAssert.AreNotEqual(firstByValue, secondByValue);
        }
Пример #13
0
        public void OfNullCollections_ShouldBeEqual()
        {
            var firstCollection  = (string[])null;
            var secondCollection = (string[])null;
            var firstByValue     = new CollectionByValue <string>(firstCollection, StrictOptions);
            var secondByValue    = new CollectionByValue <string>(secondCollection, StrictOptions);

            CollectionByValueAssert.AreEqual(firstByValue, secondByValue);
        }
Пример #14
0
        public void WithCustomComparer_ShouldUseComparer([Values] bool strictOrdering)
        {
            var firstCollection  = new[] { "1", "2" };
            var secondCollection = new[] { "1", "222" };
            var comparer         = new AlwaysEqualsEqualityComparer <string>();
            var firstByValue     = new CollectionByValue <string>(firstCollection, new Options <string>(strictOrdering, comparer));
            var secondByValue    = new CollectionByValue <string>(secondCollection, new Options <string>(strictOrdering, comparer));

            CollectionByValueAssert.AreEqual(firstByValue, secondByValue);
        }
Пример #15
0
        public void OfCollectionWithNotComparableItems_ShouldNotThrowWhenGetHashCode([Values] bool strictOrdering)
        {
            var collection = new[]
            {
                new NotComparableClass(),
                new NotComparableClass()
            };

            var byValue = new CollectionByValue <NotComparableClass>(
                collection,
                new Options <NotComparableClass>(strictOrdering, null));

            Assert.DoesNotThrow(() => byValue.GetHashCode());
        }