public void EnumComparerTest()
        {
            AdvancedComparer <Direction> comparer = AdvancedComparer <Direction> .System;

            Assert.IsNotNull(comparer);
            Assert.AreEqual("EnumComparer`2", comparer.Implementation.GetType().Name);
            Assert.Greater(comparer.Compare(Direction.Positive, Direction.Negative), 0);
            Assert.Greater(comparer.Compare(Direction.Positive, Direction.None), 0);
            Assert.Less(comparer.Compare(Direction.Negative, Direction.Positive), 0);
            Assert.Less(comparer.Compare(Direction.Negative, Direction.None), 0);
            Assert.AreEqual(comparer.Compare(Direction.Positive, Direction.Positive), 0);
            Assert.AreEqual(comparer.Compare(Direction.None, Direction.None), 0);
            Assert.AreEqual(comparer.Compare(Direction.Negative, Direction.Negative), 0);

            Assert.IsTrue(comparer.Equals(comparer.ValueRangeInfo.MaxValue, Direction.Positive));
            Assert.IsTrue(comparer.Equals(comparer.ValueRangeInfo.MinValue, Direction.Negative));
            Assert.IsFalse(comparer.Equals(Direction.Positive, Direction.Negative));

            Assert.AreEqual(comparer.GetNearestValue(Direction.Negative, Direction.Negative), Direction.Negative);
            Assert.AreEqual(comparer.GetNearestValue(Direction.Negative, Direction.Positive), Direction.None);
            Assert.AreEqual(comparer.GetNearestValue(Direction.Positive, Direction.Negative), Direction.None);
            Assert.AreEqual(comparer.GetNearestValue(Direction.Positive, Direction.Positive), Direction.Positive);
            Assert.AreEqual(comparer.GetNearestValue(Direction.None, Direction.Negative), Direction.Negative);
            Assert.AreEqual(comparer.GetNearestValue(Direction.None, Direction.Positive), Direction.Positive);
            Assert.IsFalse(comparer.ValueRangeInfo.HasDeltaValue);
        }
Exemple #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));
        }
        private void CheckComparisons(Xtensive.Tuples.Tuple x, Xtensive.Tuples.Tuple y, int expectedResult)
        {
            expectedResult = Normalize(expectedResult);
            bool boolResult = expectedResult == 0;

            Assert.AreEqual(boolResult, x.Equals(y));
            Assert.AreEqual(boolResult, equalityComparer.Equals(x, y));
            Assert.AreEqual(boolResult, advancedComparer.Equals(x, y));

            // Reverse
            expectedResult *= -1;
            Assert.AreEqual(boolResult, equalityComparer.Equals(y, x));
            Assert.AreEqual(boolResult, y.Equals(x));
            Assert.AreEqual(boolResult, advancedComparer.Equals(y, x));
        }
Exemple #4
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));
        }
 private bool CheckIfEquals <T>(AdvancedComparer <T> comparer, T x, T y)
 {
     // Tuple is no longer implementation of IComparable
     // so need to use Equals
     if (x is Tuple)
     {
         return(comparer.Equals(x, y));
     }
     return(comparer.Compare(x, y) == 0);
 }
Exemple #6
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));
        }