Example #1
0
        public void RemoveAll_Collection_NotFound()
        {
            var collection = new Dictionary<int, int> { { 1, 1 }, { 3, 3 }, { 5, 3 } };
            Assert.IsFalse (collection.RemoveAll (kvp => kvp.Value == 2));

            Assert.AreEqual (3, collection.Count);
        }
Example #2
0
        public void RemoveAll_MultipleCollection()
        {
            var collection = new Dictionary<int, int> { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 2 }, { 5, 3 } };
            collection.RemoveAll (kvp => kvp.Value == 2);

            Assert.AreEqual (3, collection.Count);
            Assert.IsFalse (collection.ContainsValue (2), "Collection still contains removed items");
        }
Example #3
0
        public static IDictionary<string, int> GetPairAndTripleCounts( string text, Set<string> allowedGroups )
        {
            Dictionary<string, int> counts = new Dictionary<string, int>();
            text = text.Replace( "\r\n", "{}" );
            int length = text.Length;

            Action<int> meth =
                delegate( int groupSize )
                {
                    for ( int pos = 0; pos + groupSize - 1 < length; )
                    {
                        for ( int j = 1; j < groupSize; j++ )
                        {
                            if ( text[pos + j] == '{' )
                            {
                                pos++;
                            }
                        }
                        while ( pos < length && text[pos] == '{' )
                        {
                            while ( text[++pos] != '}' )
                                ;
                            pos++;
                        }

                        if ( pos + groupSize - 1 < length )
                        {
                            IncrementPairCount( text.Substring( pos, groupSize ), counts );
                        }
                        pos++;
                    }
                };

            meth( 2 );

            counts.RemoveAll( p => !allowedGroups.Contains( p ) );
            return counts;
        }