Example #1
0
        private static void AssertMatches <K, T>(IEnumerable <K> keys, IEnumerable <T> elements, System.Linq.ILookup <K, T> lookup)
        {
            Assert.NotNull(lookup);
            Assert.NotNull(keys);
            Assert.NotNull(elements);

            int num = 0;

            using (IEnumerator <K> keyEnumerator = keys.GetEnumerator())
                using (IEnumerator <T> elEnumerator = elements.GetEnumerator())
                {
                    while (keyEnumerator.MoveNext())
                    {
                        Assert.True(lookup.Contains(keyEnumerator.Current));

                        foreach (T e in lookup[keyEnumerator.Current])
                        {
                            Assert.True(elEnumerator.MoveNext());
                            Assert.Equal(e, elEnumerator.Current);
                        }
                        ++num;
                    }
                    Assert.False(elEnumerator.MoveNext());
                }
            Assert.Equal(num, lookup.Count);
        }
Example #2
0
            // Helper function to verify that all elements in dictionary are matched (Order Preserving)
            public static int MatchAll <K, T>(IEnumerable <K> key, IEnumerable <T> element, System.Linq.ILookup <K, T> lookup)
            {
                int num = 0;

                if ((lookup == null) && (key == null) && (element == null))
                {
                    return(0);
                }
                using (IEnumerator <K> k1 = key.GetEnumerator())
                    using (IEnumerator <T> e1 = element.GetEnumerator())
                    {
                        while (k1.MoveNext())
                        {
                            if (!lookup.Contains(k1.Current))
                            {
                                return(1);
                            }

                            foreach (T e in lookup[k1.Current])
                            {
                                e1.MoveNext();
                                if (!Equals(e, e1.Current))
                                {
                                    return(1);
                                }
                            }
                            num = num + 1;
                        }
                    }
                if (lookup.Count != num)
                {
                    return(1);
                }
                return(0);
            }
Example #3
0
            // The following helper verification function will be used when the PLINQ team runs these tests
            // This is a non-order preserving verification function
#if PLINQ
            public static int MatchAll <K, T>(IEnumerable <K> key, IEnumerable <T> element, System.Linq.ILookup <K, T> lookup)
            {
                int num = 0;

                if ((lookup == null) && (key == null) && (element == null))
                {
                    return(0);
                }

                if ((lookup == null) || (key == null && element == null))
                {
                    Console.WriteLine("expected key : {0}", key == null ? "null" : key.Count().ToString());
                    Console.WriteLine("expected element : {0}", element == null ? "null" : element.Count().ToString());
                    Console.WriteLine("actual lookup: {0}", lookup == null ? "null" : lookup.Count().ToString());
                    return(1);
                }

                try
                {
                    List <T> expectedResults = new List <T>(element);

                    using (IEnumerator <K> k1 = key.GetEnumerator())
                        using (IEnumerator <T> e1 = element.GetEnumerator())
                        {
                            while (k1.MoveNext())
                            {
                                if (!lookup.Contains(k1.Current))
                                {
                                    return(1);
                                }

                                foreach (T e in lookup[k1.Current])
                                {
                                    if (!expectedResults.Contains(e))
                                    {
                                        return(1);
                                    }
                                    expectedResults.Remove(e);
                                }
                                num = num + 1;
                            }
                        }

                    if (expectedResults.Count != 0)
                    {
                        return(1);
                    }
                    if (lookup.Count != num)
                    {
                        return(1);
                    }
                    return(0);
                }
                catch (AggregateException ae)
                {
                    var innerExceptions = ae.Flatten().InnerExceptions;
                    if (innerExceptions.Where(ex => ex != null).Select(ex => ex.GetType()).Distinct().Count() == 1)
                    {
                        throw innerExceptions.First();
                    }
                    else
                    {
                        Console.WriteLine(ae);
                    }
                    return(1);
                }
            }