예제 #1
0
        public static void ToLookup_CustomComparator(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query  = labeled.Item;
            IntegerRangeSet     seen   = new IntegerRangeSet(0, count);
            ILookup <int, int>  lookup = query.ToLookup(x => x * 2, new ModularCongruenceComparer(count * 2));

            Assert.All(lookup,
                       group => { seen.Add(group.Key / 2); Assert.Equal(group.Key, Assert.Single(group) * 2); });
            seen.AssertComplete();
            Assert.Empty(lookup[-1]);
        }
예제 #2
0
        public static void ToLookup_ElementSelector(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query  = labeled.Item;
            IntegerRangeSet     seen   = new IntegerRangeSet(0, count);
            ILookup <int, int>  lookup = query.ToLookup(x => x, y => y * 2);

            Assert.All(lookup,
                       group => { seen.Add(group.Key); Assert.Equal(group.Key * 2, Assert.Single(group)); });
            seen.AssertComplete();
            Assert.Empty(lookup[-1]);
        }
예제 #3
0
        public static void ToLookup_DuplicateKeys_ElementSelector(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query     = labeled.Item;
            IntegerRangeSet     seenOuter = new IntegerRangeSet(0, Math.Min(count, 2));
            ILookup <int, int>  lookup    = query.ToLookup(x => x % 2, y => - y);

            Assert.All(lookup,
                       group =>
            {
                seenOuter.Add(group.Key);
                IntegerRangeSet seenInner = new IntegerRangeSet(0, (count + ((1 + group.Key) % 2)) / 2);
                Assert.All(group, y => { Assert.Equal(group.Key, -y % 2); seenInner.Add(-y / 2); });
                seenInner.AssertComplete();
            });
            seenOuter.AssertComplete();
            Assert.Empty(lookup[-1]);
        }
예제 #4
0
        public static void ToLookup_DuplicateKeys_CustomComparator(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query     = labeled.Item;
            IntegerRangeSet     seenOuter = new IntegerRangeSet(0, Math.Min(count, 2));
            ILookup <int, int>  lookup    = query.ToLookup(x => x, new ModularCongruenceComparer(2));

            Assert.All(lookup,
                       group =>
            {
                seenOuter.Add(group.Key % 2);
                IntegerRangeSet seenInner = new IntegerRangeSet(0, (count + ((1 + group.Key) % 2)) / 2);
                Assert.All(group, y => { Assert.Equal(group.Key % 2, y % 2); seenInner.Add(y / 2); });
                seenInner.AssertComplete();
            });
            seenOuter.AssertComplete();
            if (count < 2)
            {
                Assert.Empty(lookup[-1]);
            }
        }