public void ClassNullableIntFieldsAffectEquality()
 {
     var object1 = new SampleClass { NullableField = null };
     var object2 = new SampleClass { NullableField = 1 };
     PAssert.That(() => !FieldwiseEquality.AreEqual(object1, object2));
     PAssert.That(() => FieldwiseEquality.AreEqual(new SampleClass { NullableField = 3 }, new SampleClass { NullableField = 3 }));
 }
 public void ClassStructFieldsAffectHash()
 {
     var object1 = new SampleClass { PlainStruct = new CustomStruct { Bla = 1 } };
     var object2 = new SampleClass { PlainStruct = new CustomStruct { Bla = 2 } };
     var object3A = new SampleClass { PlainStruct = new CustomStruct { Bla = 3 } };
     var object3B = new SampleClass { PlainStruct = new CustomStruct { Bla = 3 } };
     PAssert.That(() => FieldwiseHasher.Hash(object1) != FieldwiseHasher.Hash(object2));
     PAssert.That(() => FieldwiseHasher.Hash(object3A) == FieldwiseHasher.Hash(object3B));
 }
 public void ClassStructFieldsAffectEquality()
 {
     var object1 = new SampleClass { PlainStruct = new CustomStruct { Bla = 1 } };
     var object2 = new SampleClass { PlainStruct = new CustomStruct { Bla = 2 } };
     var object3A = new SampleClass { PlainStruct = new CustomStruct { Bla = 3 } };
     var object3B = new SampleClass { PlainStruct = new CustomStruct { Bla = 3 } };
     PAssert.That(() => !FieldwiseEquality.AreEqual(object1, object2));
     PAssert.That(() => FieldwiseEquality.AreEqual(object3A, object3B));
 }
        public void IdenticallyValuedClassesHaveEqualHashCodeAndAreEqual()
        // ReSharper disable once EqualExpressionComparison
        {
            var objA = new SampleClass {
                AnEnum = SampleEnum.P, NullableField = 4, PlainStruct = { Bla = 2 }
            };
            var objB = new SampleClass {
                AnEnum = SampleEnum.P, NullableField = 4, PlainStruct = { Bla = 2 }
            };

            PAssert.That(() => objA != objB && eqClass.Equals(objA, objB) && eqClass.GetHashCode(objA) == eqClass.GetHashCode(objB));
        }
        public void TypeDoesNotAffectRuntimeEquality()
        {
            var sampleClass = new SampleClass {
                AnEnum = SampleEnum.Q
            };
            var sampleSubClass = new SampleSubClass {
                AnEnum = SampleEnum.Q
            };

            //This is really pretty unwanted behavior
            PAssert.That(() => FieldwiseEquality.AreEqual(sampleClass, sampleSubClass));
        }
        public void ClassNullableIntFieldsAffectEquality()
        {
            var object1 = new SampleClass {
                NullableField = null
            };
            var object2 = new SampleClass {
                NullableField = 1
            };

            PAssert.That(() => !FieldwiseEquality.AreEqual(object1, object2));
            PAssert.That(() => FieldwiseEquality.AreEqual(new SampleClass {
                NullableField = 3
            }, new SampleClass {
                NullableField = 3
            }));
        }
Beispiel #7
0
        public void ClassNullableStructFieldsAffectHash()
        {
            var object1 = new SampleClass {
                NullableStruct = null
            };
            var object2 = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 2
                }
            };
            var object3A = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 3
                }
            };
            var object3B = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 3
                }
            };

            PAssert.That(() => FieldwiseHasher.Hash(object1) != FieldwiseHasher.Hash(object2));
            PAssert.That(() => FieldwiseHasher.Hash(object3A) == FieldwiseHasher.Hash(object3B));
        }
        public void ClassNullableStructFieldsAffectEquality()
        {
            var object1 = new SampleClass {
                NullableStruct = null
            };
            var object2 = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 2
                }
            };
            var object3A = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 3
                }
            };
            var object3B = new SampleClass {
                NullableStruct = new CustomStruct {
                    Bla = 3
                }
            };

            PAssert.That(() => !FieldwiseEquality.AreEqual(object1, object2));
            PAssert.That(() => FieldwiseEquality.AreEqual(object3A, object3B));
        }
        public void TypeDoesNotAffectRuntimeEquality()
        {
            var sampleClass = new SampleClass { AnEnum = SampleEnum.Q };
            var sampleSubClass = new SampleSubClass { AnEnum = SampleEnum.Q };

            //This is really pretty unwanted behavior
            PAssert.That(() => FieldwiseEquality.AreEqual(sampleClass, sampleSubClass));
        }