Пример #1
0
        public void Detects_cycle_in_struct()
        {
            var one = new CycledStruct {
                FirstObject = new CycledStructObject()
            };

            one.FirstObject.SecondStruct = one;

            var other = new CycledStruct {
                FirstObject = new CycledStructObject()
            };

            other.FirstObject.SecondStruct = other;

            using (new AssertionScope()) {
                ComparerStruct.Equals(one, other).Should().BeTrue();
                ComparerStruct.GetHashCode(one).Should().Be(ComparerStruct.GetHashCode(other));
            }
        }
        public void Detects_cycle_on_second_member()
        {
            var one = new CycledStruct {
                SecondObject = new CycledStructObject()
            };

            one.SecondObject.FirstStruct = one;

            /*
             *    v1
             *   /  \
             *  N    1
             *     /  \
             *    v1   vX
             *   / |   | \
             *  N  1   N  N
             */

            var other = new CycledStruct {
                SecondObject = new CycledStructObject()
            };

            /*
             *    v2
             *   /  \
             *  N    2
             *     /  \
             *    v2   VY
             *   / |   | \
             *  N  N   N  N
             */

            var expected = CycledStruct.Comparer.Compare(one, other);
            var actual   = ComparerStruct.Compare(one, other);

            using (new AssertionScope()) {
                expected.Should().Be(1);
                actual.Should().Be(expected);
            }
        }
        public void Detects_cycle_in_struct()
        {
            var one = new CycledStruct {
                FirstObject = new CycledStructObject()
            };

            one.FirstObject.SecondStruct = one;

            var other = new CycledStruct {
                FirstObject = new CycledStructObject()
            };

            other.FirstObject.SecondStruct = other;

            var expected = CycledStruct.Comparer.Compare(one, other);
            var actual   = ComparerStruct.Compare(one, other);

            using (new AssertionScope()) {
                expected.Should().Be(0);
                actual.Should().Be(expected);
            }
        }
Пример #4
0
        public void Detects_cycle_on_second_member()
        {
            var one = new CycledStruct {
                SecondObject = new CycledStructObject()
            };

            one.SecondObject.FirstStruct = one;

            /*
             *    v1
             *   /  \
             *  N    1
             *     /  \
             *    v1   vX
             *   / |   | \
             *  N  1   N  N
             */

            var other = new CycledStruct {
                SecondObject = new CycledStructObject()
            };

            /*
             *    v2
             *   /  \
             *  N    2
             *     /  \
             *    v2   VY
             *   / |   | \
             *  N  N   N  N
             */

            using (new AssertionScope()) {
                ComparerStruct.Equals(one, other).Should().BeFalse();
                ComparerStruct.GetHashCode(one).Should().Be(193377063);
                ComparerStruct.GetHashCode(other).Should().Be(193376997);
            }
        }