Пример #1
0
        public void InheritedComparerTest()
        {
            Wrapper2a <int, int> o1 = new Wrapper2a <int, int>(0, 1);
            Wrapper2a <int, int> o2 = new Wrapper2a <int, int>(0, 2);
            AdvancedComparer <Wrapper2a <int, int> > comparer = AdvancedComparer <Wrapper2a <int, int> > .Default;

            Assert.IsNotNull(comparer);
            AssertEx.IsPatternMatch(comparer.Implementation.GetType().Name, "BaseComparerWrapper*");
            Assert.IsTrue(comparer.Equals(o2, o1));
            Assert.IsTrue(comparer.GetHashCode(o1) == comparer.GetHashCode(o2));
        }
Пример #2
0
        public void StringComparerTest()
        {
            string o1 = "1";
            string o2 = "2";
            AdvancedComparer <string> comparer = AdvancedComparer <string> .Default;

            Assert.IsNotNull(comparer);
            AssertEx.IsPatternMatch(comparer.Implementation.GetType().Name, "StringComparer*");
            Assert.IsFalse(comparer.Equals(o2, o1));
            Assert.IsFalse(comparer.GetHashCode(o1) == comparer.GetHashCode(o2));
            Assert.IsTrue(comparer.Equals("1", o1));
            Assert.IsTrue(comparer.Equals("2", o2));
        }
Пример #3
0
        public void Int32ComparerTest()
        {
            int              o1    = 1;
            int              o2    = 2;
            Func <int, int>  hash  = delegate(int item) { return(item.GetHashCode()); };
            long             a     = hash(o2);
            Func <long, int> hash1 = delegate(long item) { return(item.GetHashCode()); };
            long             a1    = hash1(o2);

            AdvancedComparer <int> comparer = AdvancedComparer <int> .Default;

            Assert.IsNotNull(comparer);
            AssertEx.IsPatternMatch(comparer.Implementation.GetType().Name, "Int32Comparer*");
            Assert.IsFalse(comparer.Equals(o2, o1));
            Assert.IsFalse(comparer.GetHashCode(o1) == comparer.GetHashCode(o2));
            Assert.IsTrue(comparer.Equals(1, o1));
            Assert.IsTrue(comparer.Equals(2, o2));
        }