Esempio n. 1
0
        public void Equality_on_array_of_nullables_works()
        {
            var x = new EnumSmall?[] { EnumSmall.First, null };
            var y = new EnumSmall?[] { EnumSmall.First, EnumSmall.One };

            var referenceComparer = new CollectionEqualityComparer <EnumSmall?>(new NullableEqualityComparer <EnumSmall>());
            var expectedHashX     = referenceComparer.GetHashCode(x);
            var expectedHashY     = referenceComparer.GetHashCode(y);
            var expectedEquals    = referenceComparer.Equals(x, y);

            var comparer = ComparerBuilder.Default.GetEqualityComparer <EnumSmall?[]>();

            var hashX  = comparer.GetHashCode(x);
            var hashY  = comparer.GetHashCode(y);
            var equals = comparer.Equals(x, y);

            using (new AssertionScope()) {
                comparer.Equals(x, x).Should().BeTrue();
                referenceComparer.Equals(y, y).Should().BeTrue();
                comparer.Equals(null, null).Should().BeTrue();
                equals.Should().Be(expectedEquals);
                hashX.Should().Be(expectedHashX);
                hashY.Should().Be(expectedHashY);
            }
        }
Esempio n. 2
0
        public void Enumerable_structs_with_nullables_are_comparable()
        {
            var referenceComparer = new CollectionEqualityComparer <ComparableStruct <int?>?>(new NullableEqualityComparer <ComparableStruct <int?> >(new ComparableStructEqualityComparer <int?>()));
            var comparer          = ComparerBuilder.Default.GetEqualityComparer <EnumerableStruct <ComparableStruct <int?>?> >();

            Helper.Parallel(() => {
                var x = _fixture.Create <EnumerableStruct <ComparableStruct <int?>?> >();
                var y = _fixture.Create <EnumerableStruct <ComparableStruct <int?>?> >();

                var expectedHashX  = referenceComparer.GetHashCode(x);
                var expectedHashY  = referenceComparer.GetHashCode(y);
                var expectedEquals = referenceComparer.Equals(x, y);

                var equals = comparer.Equals(x, y);
                var hashX  = comparer.GetHashCode(x);
                var hashY  = comparer.GetHashCode(y);

                using (new AssertionScope()) {
                    comparer.Equals(x, x).Should().BeTrue();
                    equals.Should().Be(expectedEquals);
                    hashX.Should().Be(expectedHashX);
                    hashY.Should().Be(expectedHashY);
                }
            });
        }
        public void Should_use_delayed_comparison()
        {
            var x = _fixture.CreateMany <SampleEqualityStruct <EnumSmall?>?>().ToArray();
            var y = _fixture.CreateMany <SampleEqualityStruct <EnumSmall?>?>().ToArray();

            var referenceComparer = new CollectionEqualityComparer <SampleEqualityStruct <EnumSmall?>?>(
                new NullableEqualityComparer <SampleEqualityStruct <EnumSmall?> >());

            var comparer = new ComparerBuilder().GetEqualityComparer <object>();

            var expectedHashX = referenceComparer.GetHashCode(x);
            var expectedHashY = referenceComparer.GetHashCode(y);
            var actualHashX   = comparer.GetHashCode(x);
            var actualHashY   = comparer.GetHashCode(y);
            var expected      = referenceComparer.Equals(x, y);
            var actual        = comparer.Equals(x, y);

            using (new AssertionScope()) {
                actualHashX.Should().Be(expectedHashX);
                actualHashY.Should().Be(expectedHashY);
                actual.Should().Be(expected);
            }
        }