Пример #1
0
        public void Equals_returns_true_for_two_collections_which_are_equal(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True);
        }
Пример #2
0
        public void Equals_returns_result_respecting_alternative_item_equality_comparer()
        {
            var sut = new BagEqualityComparer <string>(StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);

            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.True);
        }
Пример #3
0
        public void GetHashCode_returns_same_value_for_collections_respecting_alternative_item_equality_comparer()
        {
            var sut = new BagEqualityComparer <string>(StringComparer.InvariantCultureIgnoreCase, StringComparer.InvariantCultureIgnoreCase);

            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            var result1 = sut.GetHashCode(collectionOne);
            var result2 = sut.GetHashCode(collectionTwo);

            Assert.That(result1, Is.EqualTo(result2));
        }
Пример #4
0
        public void GetHashCode_does_not_pass_null_items_to_equality_comparer_hash_code_method(IEqualityComparer <string> comparer)
        {
            var sut = new BagEqualityComparer <string>(comparer);

            Mock.Get(comparer)
            .Setup(x => x.GetHashCode(It.IsAny <string>()))
            .Returns(1);
            var collection = new[] { "one", null, "three" };

            sut.GetHashCode(collection);

            Mock.Get(comparer)
            .Verify(x => x.GetHashCode(null), Times.Never);
        }
Пример #5
0
        public void Equals_returns_true_comparing_equivalent_object_collections_which_are_equatable_but_not_comparable(BagEqualityComparer <Pet> sut)
        {
            var coll1 = new[] { new Pet {
                                    Name = "A"
                                }, new Pet {
                                    Name = "B"
                                }, new Pet {
                                    Name = "C"
                                }, };
            var coll2 = new[] { new Pet {
                                    Name = "B"
                                }, new Pet {
                                    Name = "C"
                                }, new Pet {
                                    Name = "A"
                                }, };

            Assert.That(sut.Equals(coll1, coll2), Is.True);
        }
Пример #6
0
        public void Equals_returns_false_for_two_collections_which_have_different_elements(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.False);
        }
Пример #7
0
 public void Equals_returns_true_when_both_collecions_are_null(BagEqualityComparer <string> sut)
 {
     Assert.That(sut.Equals(null, null), Is.True);
 }
Пример #8
0
        public void Equals_returns_false_when_first_collecion_is_null(BagEqualityComparer <string> sut)
        {
            var collectionTwo = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(null, collectionTwo), Is.False);
        }
Пример #9
0
        public void Equals_returns_false_when_second_collecion_is_null(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, null), Is.False);
        }
Пример #10
0
        public void Equals_returns_true_for_reference_equal_collections(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };

            Assert.That(sut.Equals(collectionOne, collectionOne), Is.True);
        }
Пример #11
0
        public void Equals_returns_false_for_two_collections_which_are_equal_but_have_duplicates(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "two", "three", "two" };
            var collectionTwo = new[] { "one", "three", "one", "two" };

            Assert.That(sut.Equals(collectionOne, collectionTwo), Is.False);
        }
Пример #12
0
        public void GetHashCode_returns_different_value_for_two_collections_with_different_elements(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "two", "THREE" };

            var result1 = sut.GetHashCode(collectionOne);
            var result2 = sut.GetHashCode(collectionTwo);

            Assert.That(result1, Is.Not.EqualTo(result2));
        }
Пример #13
0
        public void GetHashCode_should_not_return_same_value_for_a_collection_with_an_even_count_of_item_differences(BagEqualityComparer <string> sut)
        {
            // Reproduces issue #1
            //
            // The item "two" appears three times in the first collection and once in the second,
            // thus the number of differences between the counts of that item's appearance is an even number: 2
            var collectionOne = new[] { "one", "two", "two", "three", "two" };
            var collectionTwo = new[] { "one", "three", "two" };

            var result1 = sut.GetHashCode(collectionOne);
            var result2 = sut.GetHashCode(collectionTwo);

            Assert.That(result1, Is.Not.EqualTo(result2));
        }
Пример #14
0
        public void GetHashCode_returns_same_value_for_two_collections_in_different_order(BagEqualityComparer <string> sut)
        {
            var collectionOne = new[] { "one", "two", "three" };
            var collectionTwo = new[] { "one", "three", "two" };

            var result1 = sut.GetHashCode(collectionOne);
            var result2 = sut.GetHashCode(collectionTwo);

            Assert.That(result1, Is.EqualTo(result2));
        }
Пример #15
0
        public void GetHashCode_returns_same_value_for_the_same_collection_hashed_twice(BagEqualityComparer <string> sut)
        {
            var collection = new[] { "one", "two", "three" };

            var result1 = sut.GetHashCode(collection);
            var result2 = sut.GetHashCode(collection);

            Assert.That(result1, Is.EqualTo(result2));
        }
Пример #16
0
 public void GetHashCode_throws_ane_for_null_collection(BagEqualityComparer <string> sut)
 {
     Assert.That(() => sut.GetHashCode(null), Throws.ArgumentNullException);
 }