public void UnsequenceEqual_CustomComparerNotEquals_False(int[] first, int[] second) { // Arrange var comparer = ComparerFactory.CreateEqualityComparer((x, y) => x == y, (int x) => x.GetHashCode()); // Act var result = first.UnsequenceEqual(second, comparer); // Assert Assert.That(result, Is.False); }
public void EqualityComparer_CustomEqualityComparer_Equal() { // Arrange var customEqualityComparer = ComparerFactory.CreateEqualityComparer <int>((i, j) => i == j, i => i); var collection = GetEmptyExtensible(customEqualityComparer); // Act var equalityComparer = collection.EqualityComparer; // Assert Assert.That(equalityComparer, Is.SameAs(customEqualityComparer)); }
public void Constructor_EqualityComparer_EqualsGivenEqualityComparer() { // Arrange var customEqualityComparer = ComparerFactory.CreateEqualityComparer <int>((i, j) => i == j, i => i); // Act var list = new ArrayList <int>(equalityComparer: customEqualityComparer); var equalityComparer = list.EqualityComparer; // Assert Assert.That(equalityComparer, Is.SameAs(customEqualityComparer)); }
public void UnsequenceEqual_EqualHashCodesNotEquals_False(int[] first, int[] second) { // Arrange Func <int, int, bool> equals = (x, y) => x == y; Func <int, int> getEqualHashCode = x => 0; var comparer = ComparerFactory.CreateEqualityComparer(equals, getEqualHashCode); // Act var result = first.UnsequenceEqual(second, comparer); // Assert Assert.That(result, Is.False); }
public void UnsequenceEqual_IntialComparer_True(string[] first, string[] second, bool expectedResult) { // Arrange Func <string, string> firstLetterOrEmpty = s => string.IsNullOrEmpty(s) ? string.Empty : s.Substring(0, 1); Func <string, string, bool> equals = (x, y) => firstLetterOrEmpty(x).Equals(firstLetterOrEmpty(y)); Func <string, int> getHashCode = x => firstLetterOrEmpty(x).GetHashCode(); var comparer = ComparerFactory.CreateEqualityComparer(equals, getHashCode); // Act var result = first.UnsequenceEqual(second, comparer); // Assert Assert.That(result, Is.EqualTo(expectedResult)); }
public static SCG.IEqualityComparer <KeyValuePair <TKey, TValue> > KeyEqualityComparer <TKey, TValue>() => ComparerFactory.CreateEqualityComparer <KeyValuePair <TKey, TValue> >((x, y) => x.Key.Equals(y.Key), x => x.Key.GetHashCode());
public static SCG.IEqualityComparer <T> CreateStructComparer <T>() => ComparerFactory.CreateEqualityComparer <T>(StructEquals, type => type.GetHashCode());