public virtual void TestGroup()
        {
            string[]             input    = new string[] { "0 ab", "0 bb", "0 cc", "1 dd", "2 dd", "2 kj", "3 kj", "3 kk" };
            int[]                counts   = new int[] { 3, 1, 2, 2 };
            IComparator <string> fieldOne = IComparer.Comparing(null);
            int index = 0;
            int group = 0;

            foreach (IEnumerable <string> set in Iterables.Group(Arrays.AsList(input), fieldOne))
            {
                string sharedKey = null;
                int    thisCount = 0;
                foreach (string line in set)
                {
                    string thisKey = line.Split(" ")[0];
                    if (sharedKey == null)
                    {
                        sharedKey = thisKey;
                    }
                    else
                    {
                        NUnit.Framework.Assert.AreEqual(sharedKey, thisKey, "Wrong key");
                    }
                    NUnit.Framework.Assert.AreEqual(line, input[index++], "Wrong input line");
                    thisCount++;
                }
                NUnit.Framework.Assert.AreEqual(counts[group++], thisCount, "Wrong number of items in this iterator");
            }
            NUnit.Framework.Assert.AreEqual(input.Length, index, "Didn't get all inputs");
            NUnit.Framework.Assert.AreEqual(counts.Length, group, "Wrong number of groups");
        }
        // TODO: make prettyLog work in the situation of loops in the object graph
        /// <summary><inheritDoc/></summary>
        public virtual void PrettyLog(Redwood.RedwoodChannels channels, string description)
        {
            Redwood.StartTrack(description);
            // sort keys by class name
            IList <Type> sortedKeys = new List <Type>(this.KeySet());

            sortedKeys.Sort(IComparer.Comparing(null));
            // log key/value pairs
            foreach (Type key in sortedKeys)
            {
                string keyName = key.GetCanonicalName().Replace("class ", string.Empty);
                object value   = this.Get(key);
                if (PrettyLogger.Dispatchable(value))
                {
                    PrettyLogger.Log(channels, keyName, value);
                }
                else
                {
                    channels.Logf("%s = %s", keyName, value);
                }
            }
            Redwood.EndTrack(description);
        }
Esempio n. 3
0
 /// <summary>
 /// A
 /// <c>Comparator</c>
 /// that compares objects by comparing their
 /// <c>String</c>
 /// representations, as determined by invoking
 /// <c>toString()</c>
 /// on the objects in question.
 /// </summary>
 public static IComparer GetStringRepresentationComparator()
 {
     return(IComparer.Comparing(null));
 }