CollectionTally counts (tallies) the number of occurences of each object in one or more enumerations.
Example #1
0
        /// <summary>
        /// Test whether the actual collection is a subset of
        /// the expected collection provided.
        /// </summary>
        /// <param name="actual"></param>
        /// <returns></returns>
        protected override bool Matches(IEnumerable actual)
        {
            CollectionTally tally = Tally(_expected);

            tally.TryRemove(actual);

            return(tally.Result.ExtraItems.Count == 0);
        }
Example #2
0
        protected override bool doMatch(IEnumerable actual)
        {
            if (expected is ICollection && actual is ICollection && ((ICollection)actual).Count != ((ICollection)expected).Count)
            {
                return(false);
            }
            CollectionTally collectionTally = Tally(expected);

            return(collectionTally.TryRemove(actual) && collectionTally.Count == 0);
        }
        protected override bool Matches(IEnumerable actual)
        {
            // Create tally from 'actual' collection, and remove '_expected'.
            // ExtraItems from tally would be missing items for '_expected' collection.
            CollectionTally tally = Tally(actual);

            tally.TryRemove(_expected);

            _missingItems = tally.Result.ExtraItems;

            return(_missingItems.Count == 0);
        }
Example #4
0
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="actual"></param>
        /// <returns></returns>
        protected override bool Matches(IEnumerable actual)
        {
            CollectionTally ct = Tally(_expected);

            ct.TryRemove(actual);

            //Store the CollectionTallyResult so the comparison between the two collections
            //is only performed once.
            _tallyResult = ct.Result;

            return((_tallyResult.ExtraItems.Count == 0) && (_tallyResult.MissingItems.Count == 0));
        }
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="actual"></param>
        /// <returns></returns>
        protected override bool doMatch(IEnumerable actual)
        {
            // This is just an optimization
            if (expected is ICollection && actual is ICollection)
            {
                if (((ICollection)actual).Count != ((ICollection)expected).Count)
                {
                    return(false);
                }
            }

            CollectionTally tally = Tally(expected);

            return(tally.TryRemove(actual) && tally.Count == 0);
        }
Example #6
0
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="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));
        }
        private bool DictionariesEqual(IDictionary x, IDictionary y, ref Tolerance tolerance)
        {
            if (x.Count != y.Count)
            {
                return(false);
            }
            CollectionTally collectionTally = new CollectionTally(this, x.Keys);

            if (!collectionTally.TryRemove(y.Keys) || collectionTally.Count > 0)
            {
                return(false);
            }
            foreach (object key in x.Keys)
            {
                if (!AreEqual(x[key], y[key], ref tolerance))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #8
0
        private bool DictionariesEqual(IDictionary expected, IDictionary actual, ref Tolerance tolerance)
        {
            if (expected.Count != actual.Count)
            {
                return(false);
            }

            CollectionTally tally = new CollectionTally(this, expected.Keys);

            if (!tally.TryRemove(actual.Keys) || tally.Count > 0)
            {
                return(false);
            }

            foreach (object key in expected.Keys)
            {
                if (!ObjectsEqual(expected[key], actual[key], ref tolerance))
                {
                    return(false);
                }
            }

            return(true);
        }
        private bool DictionariesEqual(IDictionary x, IDictionary y)
        {
            if (x.Count != y.Count)
            {
                return(false);
            }

            CollectionTally tally = new CollectionTally(this, x.Keys);

            if (!tally.TryRemove(y.Keys) || tally.Count > 0)
            {
                return(false);
            }

            foreach (object key in x.Keys)
            {
                if (!ObjectsEqual(x[key], y[key]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #10
0
        /// <summary>
        /// Test whether two collections are equivalent
        /// </summary>
        /// <param name="actual"></param>
        /// <returns></returns>
        protected override bool doMatch(IEnumerable actual)
        {
			// This is just an optimization
			if( expected is ICollection && actual is ICollection )
				if( ((ICollection)actual).Count != ((ICollection)expected).Count )
					return false;

			CollectionTally tally = new CollectionTally( expected );
			return tally.CanRemove( actual ) && tally.AllCountsEqualTo( 0 );
        }
        private bool DictionariesEqual(IDictionary x, IDictionary y, ref Tolerance tolerance)
        {
            if (x.Count != y.Count)
                return false;
 
            CollectionTally tally = new CollectionTally(this, x.Keys);
            if (!tally.TryRemove(y.Keys) || tally.Count > 0)
                return false;

            foreach (object key in x.Keys)
                if (!AreEqual(x[key], y[key], ref tolerance))
                    return false;
 
            return true;
        }