public bool?Equal(object x, object y, ref Tolerance tolerance, ComparisonState state) { if (!(x is IDictionary) || !(y is IDictionary)) { return(null); } IDictionary xDictionary = (IDictionary)x; IDictionary yDictionary = (IDictionary)y; if (xDictionary.Count != yDictionary.Count) { return(false); } CollectionTally tally = new CollectionTally(_equalityComparer, xDictionary.Keys); tally.TryRemove(yDictionary.Keys); if ((tally.Result.MissingItems.Count > 0) || (tally.Result.ExtraItems.Count > 0)) { return(false); } foreach (object key in xDictionary.Keys) { if (!_equalityComparer.AreEqual(xDictionary[key], yDictionary[key], ref tolerance, state.PushComparison(x, y))) { return(false); } } return(true); }
public bool AreEqual <T1, T2>(T1 x, T2 y, ref Tolerance tolerance) { IDictionary xDictionary = (IDictionary)x; IDictionary yDictionary = (IDictionary)y; if (xDictionary.Count != yDictionary.Count) { return(false); } CollectionTally tally = new CollectionTally(_equalityComparer, xDictionary.Keys); tally.TryRemove(yDictionary.Keys); if ((tally.Result.MissingItems.Count > 0) || (tally.Result.ExtraItems.Count > 0)) { return(false); } foreach (object key in xDictionary.Keys) { if (!_equalityComparer.AreEqual(xDictionary[key], yDictionary[key], ref tolerance)) { return(false); } } return(true); }
public bool?Equal(object x, object y, ref Tolerance tolerance) { if (!(x is IDictionary) || !(y is IDictionary)) { return(null); } IDictionary xDictionary = (IDictionary)x; IDictionary yDictionary = (IDictionary)y; if (xDictionary.Count != yDictionary.Count) { return(false); } CollectionTally tally = new CollectionTally(_equalityComparer, xDictionary.Keys); if (!tally.TryRemove(yDictionary.Keys) || tally.Count > 0) { return(false); } foreach (object key in xDictionary.Keys) { if (!_equalityComparer.AreEqual(xDictionary[key], yDictionary[key], ref tolerance)) { return(false); } } return(true); }
public void TestSingularTryRemove() { List <string> strings = new List <string>(_testStrings); Assert.AreEqual(3, _collectionTally.Result.MissingItems.Count); Assert.AreEqual(0, _collectionTally.Result.ExtraItems.Count); _collectionTally.TryRemove((object)strings[0]); Assert.AreEqual(2, _collectionTally.Result.MissingItems.Count); Assert.AreEqual(0, _collectionTally.Result.ExtraItems.Count); _collectionTally.TryRemove((object)strings[1]); Assert.AreEqual(1, _collectionTally.Result.MissingItems.Count); Assert.AreEqual(0, _collectionTally.Result.ExtraItems.Count); _collectionTally.TryRemove((object)strings[2]); Assert.AreEqual(0, _collectionTally.Result.MissingItems.Count); Assert.AreEqual(0, _collectionTally.Result.ExtraItems.Count); }