public void SubstitutesCompareDefaultForNull()
        {
            IEqualityComparer <int> source = null;
            var comparer = source.EquateSequence();

            Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SequenceEqualityComparer <int>).Source);
        }
示例#2
0
 public void NullIsNotEqualToValue()
 {
     var comparer = EqualityCompare<int?>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.IsFalse(comparer.Equals(3, null));
     Assert.IsFalse(objectComparer.Equals(3, null));
 }
示例#3
0
 public void NullSequenceNotEqualToEmptySequence()
 {
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.IsFalse(comparer.Equals(null, new int[0]));
     Assert.IsFalse(objectComparer.Equals(null, new int[0]));
 }
示例#4
0
        public void SubstitutesCompareDefaultForNull()
        {
            IEqualityComparer <int> source = null;
            var comparer = source.SelectEquateFrom((Person p) => p.Priority);

            Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SelectEqualityComparer <Person, int>).Source);
        }
示例#5
0
        public ComparerEngine()
        {
            typeComparer = EqualityCompare <TypeDefinition> .EquateBy(t => t.FullName);

            fieldComparer = EqualityCompare <FieldDefinition> .EquateBy(f => f.FullName);

            methodComparer = EqualityCompare <MethodDefinition> .EquateBy(m => m.FullName);
        }
示例#6
0
        public void SubstitutesCompareDefaultForComparerDefault()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            var comparer = EqualityComparer <Person> .Default.ThenEquateBy(thenByComparer);

            Assert.AreSame(EqualityCompare <Person> .Default(), (comparer as CompoundEqualityComparer <Person>).Source);
        }
示例#7
0
 public void NullSequenceIsEqualToNullSequence()
 {
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.AreEqual(comparer.GetHashCode(null), comparer.GetHashCode(null));
     Assert.AreEqual(objectComparer.GetHashCode(null), objectComparer.GetHashCode(null));
     Assert.IsTrue(comparer.Equals(null, null));
     Assert.IsTrue(objectComparer.Equals(null, null));
 }
示例#8
0
        public void EqualValueTypesAreNotEqual()
        {
            var comparer = EqualityCompare <int> .Reference();

            var objectComparer = comparer as System.Collections.IEqualityComparer;
            var value          = 13;

            Assert.IsFalse(comparer.Equals(value, value));
            Assert.IsFalse(objectComparer.Equals(value, value));
        }
示例#9
0
        public void NullIsNotEqualToValue()
        {
            var comparer = EqualityCompare <object> .Reference();

            var objectComparer = comparer as System.Collections.IEqualityComparer;
            var obj            = new object();

            Assert.IsFalse(comparer.Equals(obj, null));
            Assert.IsFalse(objectComparer.Equals(obj, null));
        }
示例#10
0
文件: Key.cs 项目: Dmdv/Comparers
        public void OrderByWithNullPassesNullThrough()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => 0, allowNulls : true);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(JackAbrams, null));
            Assert.IsTrue(objectComparer.Equals(JackAbrams, null));
            Assert.AreEqual(comparer.GetHashCode(JackAbrams), comparer.GetHashCode(null));
            Assert.AreEqual(objectComparer.GetHashCode(JackAbrams), objectComparer.GetHashCode(null));
        }
示例#11
0
        public void ThenByIsOnlyAppliedAsTieBreaker()
        {
            IEqualityComparer <Person> thenByComparer = new AnonymousEqualityComparer <Person>
            {
                Equals = (x, y) => { Assert.Fail(); return(false); },
            };
            var comparer = EqualityCompare <Person> .Default().ThenEquateBy(thenByComparer);

            Assert.IsFalse(comparer.Equals(AbeAbrams, CaseyJohnson));
            Assert.IsFalse(comparer.Equals(CaseyJohnson, AbeAbrams));
        }
示例#12
0
        public void ComparesNullElementsAsEqual()
        {
            var comparer = EqualityCompare <int?> .Null();

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(null, null));
            Assert.IsTrue(objectComparer.Equals(null, null));
            Assert.AreEqual(comparer.GetHashCode(null), comparer.GetHashCode(null));
            Assert.AreEqual(objectComparer.GetHashCode(null), objectComparer.GetHashCode(null));
        }
示例#13
0
文件: Key.cs 项目: Dmdv/Comparers
        public void OrderBySortsNullsAsNotEqualToValues()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => p.LastName);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsFalse(comparer.Equals(JackAbrams, null));
            Assert.IsFalse(objectComparer.Equals(JackAbrams, null));
            Assert.IsFalse(comparer.Equals(JackAbrams, Jacknull));
            Assert.IsFalse(objectComparer.Equals(JackAbrams, Jacknull));
        }
示例#14
0
        public void IdenticalObjectsAreEqual()
        {
            var comparer = EqualityCompare <object> .Reference();

            var objectComparer = comparer as System.Collections.IEqualityComparer;
            var obj            = new object();

            Assert.AreEqual(comparer.GetHashCode(obj), objectComparer.GetHashCode(obj));
            Assert.IsTrue(comparer.Equals(obj, obj));
            Assert.IsTrue(objectComparer.Equals(obj, obj));
        }
示例#15
0
        public void UsesReferenceEqualityComparerForSequences()
        {
            var threeA   = new[] { 3 };
            var threeB   = new[] { 3 };
            var comparer = EqualityCompare <int[]> .Reference();

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsFalse(comparer.Equals(threeA, threeB));
            Assert.IsFalse(objectComparer.Equals(threeA, threeB));
        }
示例#16
0
文件: Key.cs 项目: Dmdv/Comparers
        public void ThenByUsesKeyComparer()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => p.LastName).ThenEquateBy(p => p.FirstName, StringComparer.InvariantCultureIgnoreCase);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(JackAbrams, jackAbrams));
            Assert.IsTrue(objectComparer.Equals(JackAbrams, jackAbrams));
            Assert.AreEqual(comparer.GetHashCode(JackAbrams), comparer.GetHashCode(jackAbrams));
            Assert.AreEqual(objectComparer.GetHashCode(JackAbrams), objectComparer.GetHashCode(jackAbrams));
            Assert.IsFalse(comparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsFalse(objectComparer.Equals(AbeAbrams, JackAbrams));
        }
示例#17
0
文件: Key.cs 项目: Dmdv/Comparers
        public void OrderByComparesByKey()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => p.LastName);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsTrue(objectComparer.Equals(AbeAbrams, JackAbrams));
            Assert.AreEqual(comparer.GetHashCode(AbeAbrams), comparer.GetHashCode(JackAbrams));
            Assert.AreEqual(objectComparer.GetHashCode(AbeAbrams), objectComparer.GetHashCode(JackAbrams));
            Assert.IsFalse(comparer.Equals(AbeAbrams, CaseyJohnson));
            Assert.IsFalse(objectComparer.Equals(AbeAbrams, CaseyJohnson));
        }
示例#18
0
        public void ThenByIsAppliedAsTieBreaker()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            IEqualityComparer <Person> defaultComparer = EqualityCompare <Person> .Default();

            IEqualityComparer <Person> fullComparer = defaultComparer.ThenEquateBy(thenByComparer);

            Assert.IsTrue(defaultComparer.Equals(AbeAbrams, WilliamAbrams));
            Assert.AreEqual(defaultComparer.GetHashCode(AbeAbrams), defaultComparer.GetHashCode(WilliamAbrams));
            Assert.IsFalse(thenByComparer.Equals(AbeAbrams, WilliamAbrams));
            Assert.IsFalse(fullComparer.Equals(AbeAbrams, WilliamAbrams));
        }
示例#19
0
文件: Key.cs 项目: Dmdv/Comparers
        public void ThenBySortsByKey()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => p.LastName).ThenEquateBy(p => p.FirstName);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(JackAbrams, JackAbrams2));
            Assert.IsTrue(objectComparer.Equals(JackAbrams, JackAbrams2));
            Assert.AreEqual(comparer.GetHashCode(JackAbrams), comparer.GetHashCode(JackAbrams2));
            Assert.AreEqual(objectComparer.GetHashCode(JackAbrams), objectComparer.GetHashCode(JackAbrams2));
            Assert.IsFalse(comparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsFalse(objectComparer.Equals(AbeAbrams, JackAbrams));
        }
示例#20
0
 public void UsesSequenceEqualityComparerForSequences()
 {
     var threeA = new[] { 3 };
     var threeB = new[] { 3 };
     var five = new[] { 5 };
     var comparer = EqualityCompare<int[]>.Default();
     var objectComparer = comparer as System.Collections.IEqualityComparer;
     Assert.AreEqual(comparer.GetHashCode(threeA), comparer.GetHashCode(threeB));
     Assert.AreEqual(objectComparer.GetHashCode(threeA), objectComparer.GetHashCode(threeB));
     Assert.IsTrue(comparer.Equals(threeA, threeB));
     Assert.IsTrue(objectComparer.Equals(threeA, threeB));
     Assert.IsFalse(comparer.Equals(threeB, five));
     Assert.IsFalse(objectComparer.Equals(threeB, five));
 }
示例#21
0
        public void ThenByUsesComparer()
        {
            IEqualityComparer <Person> thenByComparer = EqualityCompare <string> .Default().SelectEquateFrom((Person p) => p.FirstName);

            var comparer = EqualityCompare <Person> .Default().ThenEquateBy(thenByComparer);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsFalse(comparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsFalse(objectComparer.Equals(AbeAbrams, JackAbrams));
            Assert.IsTrue(comparer.Equals(JackAbrams, JackAbrams2));
            Assert.IsTrue(objectComparer.Equals(JackAbrams, JackAbrams2));
            Assert.AreEqual(comparer.GetHashCode(JackAbrams), comparer.GetHashCode(JackAbrams2));
            Assert.AreEqual(objectComparer.GetHashCode(JackAbrams), objectComparer.GetHashCode(JackAbrams2));
        }
示例#22
0
文件: Key.cs 项目: Dmdv/Comparers
        public void OrderByWithNullThenByHandlesNull()
        {
            var comparer = EqualityCompare <Person> .EquateBy(p => p == null, allowNulls : true).ThenEquateBy(p => p.LastName).ThenEquateBy(p =>
            {
                Assert.Fail();
                return(0);
            });

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(null, null));
            Assert.IsTrue(objectComparer.Equals(null, null));
            Assert.AreEqual(comparer.GetHashCode(null), comparer.GetHashCode(null));
            Assert.AreEqual(objectComparer.GetHashCode(null), objectComparer.GetHashCode(null));
        }
示例#23
0
文件: Key.cs 项目: Dmdv/Comparers
        public void OrderByUsesKeyComparer()
        {
            var keyComparer = StringComparer.InvariantCultureIgnoreCase;
            var comparer    = EqualityCompare <Person> .EquateBy(p => p.LastName, keyComparer);

            var objectComparer = comparer as System.Collections.IEqualityComparer;

            Assert.IsTrue(comparer.Equals(AbeAbrams, Williamabrams));
            Assert.IsTrue(objectComparer.Equals(AbeAbrams, Williamabrams));
            Assert.AreEqual(comparer.GetHashCode(AbeAbrams), comparer.GetHashCode(Williamabrams));
            Assert.AreEqual(objectComparer.GetHashCode(AbeAbrams), objectComparer.GetHashCode(Williamabrams));
            Assert.IsFalse(comparer.Equals(Williamabrams, CaseyJohnson));
            Assert.IsFalse(objectComparer.Equals(Williamabrams, CaseyJohnson));
            Assert.AreEqual(keyComparer.GetHashCode(Williamabrams.LastName) == keyComparer.GetHashCode(CaseyJohnson.LastName),
                            comparer.GetHashCode(Williamabrams) == comparer.GetHashCode(CaseyJohnson));
        }
示例#24
0
        public override void OnClick(Node source, Vector2 mousePosition)
        {
            NodeIf node = source as NodeIf;

            NodeEditorUtility.AddNewNode(graph.editorData, null, null, mousePositionOnCanvas, (NodeValidation n) => {
                var action    = new EqualityCompare();
                action.target = new MultipurposeMember(node.condition);
                action.value  = new MemberData(true);
                n.Validation.AddBlock(action, EventActionData.EventType.Event);
                n.onTrue     = node.onTrue;
                n.onFalse    = node.onFalse;
                n.onFinished = node.onFinished;
                n.editorRect = node.editorRect;
                RefactorUtility.RetargetNode(node, n);
            });
            NodeEditorUtility.RemoveNode(graph.editorData, node);
            graph.Refresh();
        }
示例#25
0
        public static Condition onAddEqualityComparer(MemberData member)
        {
            EqualityCompare cond = new EqualityCompare();

            cond.target = new MultipurposeMember()
            {
                target = member
            };
            MemberDataUtility.UpdateMultipurposeMember(cond.target);
            if (member.type != null && ReflectionUtils.CanCreateInstance(member.type))
            {
                cond.value = new MemberData(ReflectionUtils.CreateInstance(member.type));
            }
            else
            {
                cond.value = new MemberData(null, MemberData.TargetType.Values);
            }
            return(cond);
        }
示例#26
0
        public void IsEquivalentToEqualityComparerDefault()
        {
            var a = 3;
            var b = 3;
            var c = 5;

            var defaultComparer = EqualityCompare<int>.Default();
            var netDefaultComparer = EqualityComparer<int>.Default;
            var defaultObjectComparer = defaultComparer as System.Collections.IEqualityComparer;
            Assert.AreEqual(netDefaultComparer.GetHashCode(a), defaultComparer.GetHashCode(a));
            Assert.AreEqual(defaultComparer.GetHashCode(a), defaultObjectComparer.GetHashCode(a));
            Assert.AreEqual(netDefaultComparer.GetHashCode(b), defaultComparer.GetHashCode(b));
            Assert.AreEqual(defaultComparer.GetHashCode(b), defaultObjectComparer.GetHashCode(b));
            Assert.AreEqual(netDefaultComparer.GetHashCode(c), defaultComparer.GetHashCode(c));
            Assert.AreEqual(defaultComparer.GetHashCode(c), defaultObjectComparer.GetHashCode(c));
            Assert.AreEqual(netDefaultComparer.GetHashCode(7) == netDefaultComparer.GetHashCode(13), defaultComparer.GetHashCode(7) == defaultComparer.GetHashCode(13));
            Assert.AreEqual(defaultComparer.GetHashCode(7) == defaultComparer.GetHashCode(13), defaultObjectComparer.GetHashCode(7) == defaultObjectComparer.GetHashCode(13));
            Assert.AreEqual(netDefaultComparer.Equals(a, b), defaultComparer.Equals(a, b));
            Assert.AreEqual(defaultComparer.Equals(a, b), defaultObjectComparer.Equals(a, b));
            Assert.AreEqual(netDefaultComparer.Equals(a, c), defaultComparer.Equals(a, c));
            Assert.AreEqual(defaultComparer.Equals(a, c), defaultObjectComparer.Equals(a, c));
        }
示例#27
0
 public Assert_SetEquals(IDictionary <T, T> expected, EqualityCompare <T> valuesComparer)
     : base(expected, x => x, valuesComparer)
 {
 }
 public void NullIsNotEqualToEmpty()
 {
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(null, Enumerable.Empty <int>()));
     Assert.IsFalse(EqualityCompare <int> .Default().EquateSequence().Equals(Enumerable.Empty <int>(), null));
 }
示例#29
0
 public Assert_SetEquals(IEnumerable <T> expected, EqualityCompare <T> valuesComparer)
     : base(expected, x => x, valuesComparer)
 {
 }
 static TestRun()
 {
     DefaultComparer = EqualityCompare <TestRun> .EquateBy(t => t.Id);
 }