Beispiel #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.");
            }
Beispiel #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());
 }
 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());
 }
 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());
 }
        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());
        }
Beispiel #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());
        }
Beispiel #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());
        }
Beispiel #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);
        }
Beispiel #15
0
 public override int GetHashCode() => _union.GetHashCode();
Beispiel #16
0
        public void T3HashCode_IsBasedOnT3Value()
        {
            var a = new Union <int, string, Colors>(Colors.Blue);

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

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

            AreEqual(a.GetHashCode(), 2.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());
 }
Beispiel #20
0
        public void T2HashCode_IsBasedOnT2Value()
        {
            var a = new Union <int, string, Colors, Animals>("party");

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

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