Пример #1
0
            public void EqualInstancesHaveEqualHashCode()
            {
                var u1 = new Union <int, string, byte, decimal, bool, char, long>(1);
                var u2 = new Union <int, string, byte, decimal, bool, char, long>(1);

                Assert.That(u1.GetHashCode(), Is.EqualTo(u2.GetHashCode()), "Equal instances did not have the same hash code.");
            }
Пример #2
0
            public void DifferentCasesHaveDifferentHashCodes()
            {
                var u1 = new Union <int, string, byte, decimal, bool, char, long>(1);
                var u2 = new Union <int, string, byte, decimal, bool, char, long>((byte)1);

                Assert.That(u1.GetHashCode(), Is.Not.EqualTo(u2.GetHashCode()), "Non-equal instances had the same hash code.");
            }
 public void SameT3Values_AreEqualAndHaveSameHashCode()
 {
     var a = new Union<int, string, Colors>(Colors.Blue);
     var b = new Union<int, string, Colors>(Colors.Blue);
     IsTrue(a.Equals(b));
     IsTrue(a == b);
     AreEqual(a.GetHashCode(), b.GetHashCode());
 }
Пример #4
0
 public void DifferentValues_AreNotEqualAndHaveDifferentHashCodes()
 {
     var a = new Union<int, string>(0);
     var b = new Union<int, string>("1234");
     IsFalse(a.Equals(b));
     IsTrue(a != b);
     AreNotEqual(a.GetHashCode(), b.GetHashCode());
 }
Пример #5
0
 public void SameT2Values_AreEqualAndHaveSameHashCode()
 {
     var a = new Union<int, string>("1234");
     var b = new Union<int, string>("1234");
     IsTrue(a.Equals(b));
     IsTrue(a == b);
     AreEqual(a.GetHashCode(), b.GetHashCode());
 }
 public void SameT4Values_AreEqualAndHaveSameHashCode()
 {
     var a = new Union<int, string, Colors, Animals>(Animals.Cat);
     var b = new Union<int, string, Colors, Animals>(Animals.Cat);
     IsTrue(a.Equals(b));
     IsTrue(a == b);
     AreEqual(a.GetHashCode(), b.GetHashCode());
 }
 public void DifferentT1T3Values_AreNotEqualAndHaveDifferentHashCodes()
 {
     var a = new Union<int, string, Colors>(0);
     var b = new Union<int, string, Colors>(Colors.Green);
     IsFalse(a.Equals(b));
     IsTrue(a != b);
     AreNotEqual(a.GetHashCode(), b.GetHashCode());
 }
Пример #8
0
        public void SameT2Values_AreEqualAndHaveSameHashCode()
        {
            var a = new Union <int, string>("1234");
            var b = new Union <int, string>("1234");

            IsTrue(a.Equals(b));
            IsTrue(a == b);
            AreEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void DifferentT1T2Values_AreNotEqualAndHaveDifferentHashCodes()
        {
            var a = new Union <int, string, Colors, Animals>(2);
            var b = new Union <int, string, Colors, Animals>("1234");

            IsFalse(a.Equals(b));
            IsTrue(a != b);
            AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void DifferentT3T4Values_AreNotEqualAndHaveDifferentHashCodes()
        {
            var a = new Union <int, string, Colors, Animals>(Colors.Red);
            var b = new Union <int, string, Colors, Animals>(Animals.Cow);

            IsFalse(a.Equals(b));
            IsTrue(a != b);
            AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
        public void SameT4Values_AreEqualAndHaveSameHashCode()
        {
            var a = new Union <int, string, Colors, Animals>(Animals.Cat);
            var b = new Union <int, string, Colors, Animals>(Animals.Cat);

            IsTrue(a.Equals(b));
            IsTrue(a == b);
            AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Пример #12
0
        public void SameT3Values_AreEqualAndHaveSameHashCode()
        {
            var a = new Union <int, string, Colors>(Colors.Blue);
            var b = new Union <int, string, Colors>(Colors.Blue);

            IsTrue(a.Equals(b));
            IsTrue(a == b);
            AreEqual(a.GetHashCode(), b.GetHashCode());
        }
Пример #13
0
        public void DifferentT2T3Values_AreNotEqualAndHaveDifferentHashCodes()
        {
            var a = new Union <int, string, Colors>("xyz");
            var b = new Union <int, string, Colors>(Colors.Green);

            IsFalse(a.Equals(b));
            IsTrue(a != b);
            AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
Пример #14
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ruleCase_ == RuleOneofCase.MaxNumVersions)
            {
                hash ^= MaxNumVersions.GetHashCode();
            }
            if (ruleCase_ == RuleOneofCase.MaxAge)
            {
                hash ^= MaxAge.GetHashCode();
            }
            if (ruleCase_ == RuleOneofCase.Intersection)
            {
                hash ^= Intersection.GetHashCode();
            }
            if (ruleCase_ == RuleOneofCase.Union)
            {
                hash ^= Union.GetHashCode();
            }
            return(hash);
        }
Пример #15
0
 public override int GetHashCode() => _union.GetHashCode();
Пример #16
0
        public void T3HashCode_IsBasedOnT3Value()
        {
            var a = new Union <int, string, Colors>(Colors.Blue);

            AreEqual(a.GetHashCode(), Colors.Blue.GetHashCode());
        }
Пример #17
0
        public void T2HashCode_IsBasedOnT2Value()
        {
            var a = new Union <int, string, Colors>("cow");

            AreEqual(a.GetHashCode(), "cow".GetHashCode());
        }
Пример #18
0
        public void T1HashCode_IsBasedOnT1Value()
        {
            var a = new Union <int, string, Colors>(2);

            AreEqual(a.GetHashCode(), 2.GetHashCode());
        }
Пример #19
0
 public void DifferentT3T4Values_AreNotEqualAndHaveDifferentHashCodes()
 {
     var a = new Union<int, string, Colors, Animals>(Colors.Red);
     var b = new Union<int, string, Colors, Animals>(Animals.Cow);
     IsFalse(a.Equals(b));
     IsTrue(a != b);
     AreNotEqual(a.GetHashCode(), b.GetHashCode());
 }
Пример #20
0
        public void T2HashCode_IsBasedOnT2Value()
        {
            var a = new Union <int, string, Colors, Animals>("party");

            AreEqual(a.GetHashCode(), "party".GetHashCode());
        }
Пример #21
0
        public void T4HashCode_IsBasedOnT4Value()
        {
            var a = new Union <int, string, Colors, Animals>(Animals.Cow);

            AreEqual(a.GetHashCode(), Animals.Cow.GetHashCode());
        }