public void EqualityFactory_GetComparer_Compare() { var expected = 1234; var cmp = EqualityFactory.GetComparer <Example>((a, b) => expected); var actual = cmp.Compare(new Example(), new Example()); Assert.AreEqual(expected, actual); }
public void EqualityFactory_GetEquitable_IEquatable_Equals() { var expected = true; var cmp = EqualityFactory.GetEquitable <Example>((a) => expected); var actual = (cmp as IEquatable <Example>).Equals(new Example()); Assert.AreNotEqual(0, actual); }
public void EqualityFactory_GetComparable_CompareTo() { var expectedHash = 4321; var cmp = EqualityFactory.GetComparable <Example>((a) => expectedHash); var actual = cmp.CompareTo(new Example()); Assert.AreEqual(expectedHash, actual); }
public void EqualityFactory_GetEqualityComparer_Equals_GetHashCode() { var expectedHash = 4321; var expectedBool = true; var cmp = EqualityFactory.GetEqualityComparer <Example>((a, b) => expectedBool, (a) => expectedHash); var actualBool = cmp.Equals(new Example(), new Example()); var actual = (cmp as IEqualityComparer <Example>).GetHashCode(new Example()); Assert.AreEqual(expectedBool, actualBool); }
public void GetComparer_isEquality() { var comparer = EqualityFactory.GetComparer <string>((s1, s2) => String.Compare(s1, s2, StringComparison.Ordinal)); var otherComparer = comparer as IEqualityComparer <string>; Assert.IsNotNull(otherComparer); var result = otherComparer.GetHashCode("Test"); Assert.AreEqual("Test".GetHashCode(), result); }
public void EqualityFactory_GetEquitable_GetHashCode_NoHashCodeCallback() { var expected = true; var cmp = EqualityFactory.GetEquitable <Example>((a) => expected); try { var actual = (cmp as IEqualityComparer <Example>).GetHashCode(new Example()); Assert.Fail("expected exception This method is not implemented for this instance."); } catch (Exception e) { Assert.AreEqual("This method is not implemented for this instance.", e.Message); } }
public void Works_with_number_and_sum_factories_and_1_then_2_then_3_as_data_source() { var factoryProviders = GetFactoryProvidersSource( new DefaultFactoryProvider<NumberFactory>(), new DefaultFactoryProvider<SumFactory>()); var dataSource = GetDataSource(1, 2, 3); var factory = new EqualityFactory { FactoryProvidersSource = factoryProviders, DataSource = dataSource, StackSize = 5 }; var enumerator = factory.GetEnumerator(); Assert(enumerator, "(2=(1+1))"); Assert(enumerator, "(3=(1+2))"); Assert(enumerator, "(3=(1+(1+1)))"); IsFalse(enumerator.MoveNext()); }
public void GetEqualityComparer_GivenEquals_GetHashCode() { var personComparer = EqualityFactory.GetEqualityComparer <Person>( (p1, p2) => p1.FirstName == p2.FirstName && p1.LastName == p2.LastName, p => string.Concat(p.FirstName, p.LastName).ToLowerInvariant().GetHashCode()); var characters = new HashSet <Person>(personComparer) { new Person { FirstName = "Bette", LastName = "Johnson" }, new Person { FirstName = "Elmer", LastName = "Pickle" }, new Person { FirstName = "Fred", LastName = "Smith" }, new Person { FirstName = "Barney", LastName = "Rhinestone" }, new Person { FirstName = "Wilma", LastName = "Green" }, new Person { FirstName = "Billy", LastName = "Thompson" }, new Person { FirstName = "Daisy", LastName = "Anderson" } }; //Add returns true if an element is added, false if it's already there. var addSamePersonAgain = characters.Add(new Person { FirstName = "Elmer", LastName = "Pickle" }); Assert.IsFalse(addSamePersonAgain); }
public void GetComparer_StringComparer() { var characterNames = new List <string> { "Bette", "Elmer", "Fred", "Barney", "Wilma", "Billy", "Daisy" }; characterNames.Sort(EqualityFactory.GetComparer <string>((v1, v2) => string.Compare(v1, v2, StringComparison.OrdinalIgnoreCase))); Assert.AreEqual("Barney", characterNames[0]); Assert.AreEqual("Bette", characterNames[1]); Assert.AreEqual("Billy", characterNames[2]); Assert.AreEqual("Daisy", characterNames[3]); Assert.AreEqual("Elmer", characterNames[4]); Assert.AreEqual("Fred", characterNames[5]); Assert.AreEqual("Wilma", characterNames[6]); }
#pragma warning disable S1541 // Methods and properties should not be too complex public bool Equals(IPluginConstructor x, IPluginConstructor y) #pragma warning restore S1541 // Methods and properties should not be too complex { if (x == null && y == null) { return(true); } if (x == null || y == null) { return(false); } var methodsAreEqual = Equals(x.ID, y.ID) && string.Equals(x.ConstructorName, y.ConstructorName) && string.Equals(x.ReturnObject, y.ReturnObject) && Equals(x.IsExistingObject, y.IsExistingObject) && CommonEqualityOps.CollectionEquals(x.Inputs, y.Inputs, EqualityFactory.GetEqualityComparer <IConstructorParameter>( (parameter, constructorParameter) => string.Equals(parameter.Name, constructorParameter.Name) && string.Equals(parameter.Value, constructorParameter.Value) && Equals(parameter.EmptyToNull, constructorParameter.EmptyToNull) && Equals(parameter.Dev2ReturnType, constructorParameter.Dev2ReturnType), parameter => 1)); return(methodsAreEqual); }
public bool Equals(IDataSourceShape other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } var collectionEquals = CommonEqualityOps.CollectionEquals(Paths, other.Paths, EqualityFactory.GetEqualityComparer <IPath>(EqualsMethod, GetHashCodeMethod)); return(collectionEquals); }