コード例 #1
0
        public void Equals_SameTypeSameSequence_ReturnsTrue()
        {
            var comparer = new TypeArrayComparer();
            Type[] firstArray = new[] { typeof(string), typeof(int) };
            Type[] secondArray = new[] { typeof(string), typeof(int) };

            Assert.True(comparer.Equals(firstArray, secondArray));
        }
コード例 #2
0
        public void Equals_UnidenticalArrays_ReturnsFalse()
        {
            var comparer = new TypeArrayComparer();
            Type[] firstArray = new[] { typeof(string) };
            Type[] secondArray = new[] { typeof(int) };

            Assert.False(comparer.Equals(firstArray, secondArray));
        }
コード例 #3
0
        public void Equals_SameTypeSameSequence_ReturnsTrue()
        {
            var comparer = new TypeArrayComparer();

            Type[] firstArray  = new[] { typeof(string), typeof(int) };
            Type[] secondArray = new[] { typeof(string), typeof(int) };

            Assert.IsTrue(comparer.Equals(firstArray, secondArray));
        }
コード例 #4
0
        public void Equals_UnidenticalArrays_ReturnsFalse()
        {
            var comparer = new TypeArrayComparer();

            Type[] firstArray  = new[] { typeof(string) };
            Type[] secondArray = new[] { typeof(int) };

            Assert.IsFalse(comparer.Equals(firstArray, secondArray));
        }
コード例 #5
0
        public void EqualsTest()
        {
            TypeArrayComparer target = new TypeArrayComparer();

            Type[] x    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] xRef = x;
            Type[] y    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] z    = new Type[] { typeof(OperatingSystem), typeof(Buffer), typeof(WeakReference) };

            Assert.IsTrue(target.Equals(x, xRef), "reference of a Type[] should be equal to another reference to the same Type[]");
            Assert.IsTrue(target.Equals(x, y), "Two arrays with the same elements, should be equal.");
            Assert.IsFalse(target.Equals(y, z), "Two arrays with different elements should be different.");
            Assert.IsFalse(target.Equals(x, z), "Two arrays with different elements should be different.");
        }
コード例 #6
0
        public void GetHashCodeTest()
        {
            TypeArrayComparer target = new TypeArrayComparer();

            Type[] x    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] xRef = x;
            Type[] y    = new Type[] { typeof(string), typeof(Buffer), typeof(WeakReference) };
            Type[] z    = new Type[] { typeof(OperatingSystem), typeof(Buffer), typeof(WeakReference) };

            int xHashCode    = target.GetHashCode(x);
            int xRefHashCode = target.GetHashCode(xRef);
            int yHashCode    = target.GetHashCode(y);
            int zHashCode    = target.GetHashCode(z);

            Console.Out.WriteLine("HashCodes:\n\tx:{0}  xRef:{1}  y:{2}  z:{3}", xHashCode, xRefHashCode, yHashCode, zHashCode);
            Assert.AreEqual(xHashCode, xRefHashCode, "reference of a Type[] should be equal to another reference to the same Type[]");
            Assert.AreEqual(target.GetHashCode(x), yHashCode, "Two arrays with the same elements, should be equal.");
            Assert.AreNotEqual(target.GetHashCode(y), target.GetHashCode(z), "Two arrays with different elements should be different.");
            Assert.AreNotEqual(target.GetHashCode(x), zHashCode, "Two arrays with different elements should be different.");
        }