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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="actual">The actual.</param>
        /// <returns></returns>
        protected override bool doMatch(ICollection actual)
        {
            // This is just an optimization
            if (_expected is ICollection)
            {
                if (actual.Count != ((ICollection)_expected).Count)
                {
                    return(false);
                }
            }

            CollectionTally tally = new CollectionTally(_expected);

            return(tally.CanRemove(actual) && tally.AllCountsEqualTo(0));
        }
 public void TestSetup()
 {
     _collectionTally = new CollectionTally(new NUnitEqualityComparer(), _testStrings);
 }
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="actual">The actual.</param>
        /// <returns></returns>
        protected override bool doMatch( ICollection actual )
        {
            // This is just an optimization
            if ( _expected is ICollection )
            {
                if ( actual.Count != ( (ICollection) _expected ).Count )
                {
                    return false;
                }
            }

            CollectionTally tally = new CollectionTally( _expected );
            return tally.CanRemove( actual ) && tally.AllCountsEqualTo( 0 );
        }