public void SubstitutesCompareDefaultForNull() { IEqualityComparer <int> source = null; var comparer = source.EquateSequence(); Assert.AreSame(EqualityCompare <int> .Default(), (comparer as SequenceEqualityComparer <int>).Source); }
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)); }
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])); }
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); }
public ComparerEngine() { typeComparer = EqualityCompare <TypeDefinition> .EquateBy(t => t.FullName); fieldComparer = EqualityCompare <FieldDefinition> .EquateBy(f => f.FullName); methodComparer = EqualityCompare <MethodDefinition> .EquateBy(m => m.FullName); }
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); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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)); }
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(); }
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); }
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)); }
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)); }
public Assert_SetEquals(IEnumerable <T> expected, EqualityCompare <T> valuesComparer) : base(expected, x => x, valuesComparer) { }
static TestRun() { DefaultComparer = EqualityCompare <TestRun> .EquateBy(t => t.Id); }