Ejemplo n.º 1
0
        public static void GroupJoin_Unordered_NotPipelined(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            IntegerRangeSet     seen       = new IntegerRangeSet(0, leftCount);

            Assert.All(leftQuery.GroupJoin(rightQuery, x => x * KeyFactor, y => y, (x, y) => KeyValuePair.Create(x, y)).ToList(),
                       p =>
            {
                seen.Add(p.Key);
                if (p.Key < (rightCount + (KeyFactor - 1)) / KeyFactor)
                {
                    Assert.Equal(p.Key * KeyFactor, Assert.Single(p.Value));
                }
                else
                {
                    Assert.Empty(p.Value);
                }
            });
            seen.AssertComplete();
        }
Ejemplo n.º 2
0
        public static void GroupJoin_CustomComparator(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            int seenOuter = 0;

            Assert.All(leftQuery.GroupJoin(rightQuery, x => x, y => y % ElementFactor, (x, y) => KeyValuePair.Create(x, y), new ModularCongruenceComparer(KeyFactor)),
                       p =>
            {
                Assert.Equal(seenOuter++, p.Key);
                if (p.Key % KeyFactor < Math.Min(ElementFactor, rightCount))
                {
                    IntegerRangeSet seenInner = new IntegerRangeSet(0, (rightCount + (ElementFactor - 1) - p.Key % ElementFactor) / ElementFactor);
                    Assert.All(p.Value, y => { Assert.Equal(p.Key % KeyFactor, y % ElementFactor); seenInner.Add(y / ElementFactor); });
                    seenInner.AssertComplete();
                }
                else
                {
                    Assert.Empty(p.Value);
                }
            });
            Assert.Equal(leftCount, seenOuter);
        }
Ejemplo n.º 3
0
        public static void GroupJoin(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            int seen = 0;

            foreach (var p in leftQuery.GroupJoin(rightQuery, x => x * KeyFactor, y => y, (x, y) => KeyValuePair.Create(x, y)))
            {
                Assert.Equal(seen++, p.Key);
                if (p.Key < (rightCount + (KeyFactor - 1)) / KeyFactor)
                {
                    Assert.Equal(p.Key * KeyFactor, Assert.Single(p.Value));
                }
                else
                {
                    Assert.Empty(p.Value);
                }
            }
            Assert.Equal(leftCount, seen);
        }
Ejemplo n.º 4
0
        public static void Join(Labeled <ParallelQuery <int> > left, int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightCount);
            int seen = 0;

            foreach (var p in leftQuery.Join(rightQuery, x => x * KeyFactor, y => y, (x, y) => KeyValuePair.Create(x, y)))
            {
                Assert.Equal(seen++, p.Key);
                Assert.Equal(p.Key * KeyFactor, p.Value);
            }
            Assert.Equal(Math.Min(leftCount, (rightCount + (KeyFactor - 1)) / KeyFactor), seen);
        }
Ejemplo n.º 5
0
        // GroupJoin doesn't always return elements from the right in order.  See Issue #1155
        public static void GroupJoin_Multiple(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            int seenOuter = 0;

            Assert.All(leftQuery.GroupJoin(rightQuery, x => x, y => y / KeyFactor, (x, y) => KeyValuePair.Create(x, y)),
                       p =>
            {
                Assert.Equal(seenOuter++, p.Key);
                if (p.Key < (rightCount + (KeyFactor - 1)) / KeyFactor)
                {
                    IntegerRangeSet seenInner = new IntegerRangeSet(p.Key * KeyFactor, Math.Min(rightCount - p.Key * KeyFactor, KeyFactor));
                    Assert.All(p.Value, y => { Assert.Equal(p.Key, y / KeyFactor); seenInner.Add(y); });
                    seenInner.AssertComplete();
                }
                else
                {
                    Assert.Empty(p.Value);
                }
            });
            Assert.Equal(leftCount, seenOuter);
        }
Ejemplo n.º 6
0
        public static void Join_InnerJoin_Ordered(Labeled <ParallelQuery <int> > left, int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery   = left.Item;
            ParallelQuery <int> rightQuery  = UnorderedSources.Default(rightCount);
            ParallelQuery <int> middleQuery = ParallelEnumerable.Range(0, leftCount).AsOrdered();

            int seen = 0;

            Assert.All(leftQuery.Join(middleQuery.Join(rightQuery, x => x * KeyFactor / 2, y => y, (x, y) => KeyValuePair.Create(x, y)),
                                      z => z * 2, p => p.Key, (x, p) => KeyValuePair.Create(x, p)),
                       pOuter =>
            {
                KeyValuePair <int, int> pInner = pOuter.Value;
                Assert.Equal(seen++, pOuter.Key);
                Assert.Equal(pOuter.Key * 2, pInner.Key);
                Assert.Equal(pOuter.Key * KeyFactor, pInner.Value);
            });
            Assert.Equal(Math.Min((leftCount + 1) / 2, (rightCount + (KeyFactor - 1)) / KeyFactor), seen);
        }
Ejemplo n.º 7
0
        public static void Join_Unordered(int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightCount);
            IntegerRangeSet     seen       = new IntegerRangeSet(0, Math.Min(leftCount, (rightCount + (KeyFactor - 1)) / KeyFactor));

            foreach (var p in leftQuery.Join(rightQuery, x => x * KeyFactor, y => y, (x, y) => KeyValuePair.Create(x, y)))
            {
                Assert.Equal(p.Key * KeyFactor, p.Value);
                seen.Add(p.Key);
            }
            seen.AssertComplete();
        }
Ejemplo n.º 8
0
 protected override ParallelQuery <KeyValuePair <int, int> > Join(ParallelQuery <int> left, ParallelQuery <int> right)
 {
     return(ReorderLeft(left).Join(right, x => x, y => y % KeyFactor, (x, y) => KeyValuePair.Create(x, y)).Distinct());
 }
Ejemplo n.º 9
0
 protected override ParallelQuery <KeyValuePair <int, int> > Join(ParallelQuery <int> left, ParallelQuery <int> right)
 {
     return(ReorderLeft(left).Join(right, x => x, y => y, (x, y) => KeyValuePair.Create(x, y), new ModularCongruenceComparer(KeyFactor)).Distinct());
 }
Ejemplo n.º 10
0
        public static void Join_Unordered_Multiple(int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightCount);
            IntegerRangeSet     seenOuter  = new IntegerRangeSet(0, Math.Min(leftCount, (rightCount + (KeyFactor - 1)) / KeyFactor));
            IntegerRangeSet     seenInner  = new IntegerRangeSet(0, Math.Min(leftCount * KeyFactor, rightCount));

            Assert.All(leftQuery.Join(rightQuery, x => x, y => y / KeyFactor, (x, y) => KeyValuePair.Create(x, y)),
                       p =>
            {
                Assert.Equal(p.Key, p.Value / KeyFactor);
                seenInner.Add(p.Value);
                if (p.Value % KeyFactor == 0)
                {
                    seenOuter.Add(p.Key);
                }
            });
            seenOuter.AssertComplete();
            seenInner.AssertComplete();
        }
Ejemplo n.º 11
0
        public static void Join_Multiple(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            int seen = 0;

            Assert.All(leftQuery.Join(rightQuery, x => x, y => y / KeyFactor, (x, y) => KeyValuePair.Create(x, y)),
                       p =>
            {
                Assert.Equal(p.Key, p.Value / KeyFactor);
                Assert.Equal(seen++, p.Value);
            });
            Assert.Equal(Math.Min(leftCount * KeyFactor, rightCount), seen);
        }
Ejemplo n.º 12
0
        public static void SelectMany_Indexed_ResultSelector_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion)
        {
            ParallelQuery <int> query = labeled.Item;
            Func <int, int, IEnumerable <int> > expand = expander.Item;
            int seen = 0;

            Assert.All(query.SelectMany((x, index) => expand(x, expansion).Select(y => KeyValuePair.Create(index, y)), (original, expanded) => KeyValuePair.Create(original, expanded)).ToList(),
                       pOuter =>
            {
                var pInner = pOuter.Value;
                Assert.Equal(pOuter.Key, pInner.Key);
                Assert.Equal(seen++, pInner.Value);
                Assert.Equal(pOuter.Key, pInner.Value / expansion);
            });
            Assert.Equal(count * expansion, seen);
        }
Ejemplo n.º 13
0
        public static void SelectMany_Indexed_Unordered_ResultSelector_NotPipelined(int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion)
        {
            // For unordered collections, which element is at which index isn't actually guaranteed, but an effect of the implementation.
            // If this test starts failing it should be updated, and possibly mentioned in release notes.
            Func <int, int, IEnumerable <int> > expand = expander.Item;
            IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion);

            Assert.All(UnorderedSources.Default(count).SelectMany((x, index) => expand(x, expansion).Select(y => KeyValuePair.Create(index, y)), (original, expanded) => KeyValuePair.Create(original, expanded)).ToList(),
                       pOuter =>
            {
                var pInner = pOuter.Value;
                Assert.Equal(pOuter.Key, pInner.Key);
                seen.Add(pInner.Value);
                Assert.Equal(pOuter.Key, pInner.Value / expansion);
            });
            seen.AssertComplete();
        }
Ejemplo n.º 14
0
        public static void SelectMany_Indexed(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion)
        {
            ParallelQuery <int> query = labeled.Item;
            Func <int, int, IEnumerable <int> > expand = expander.Item;
            int seen = 0;

            foreach (var pIndex in query.SelectMany((x, index) => expand(x, expansion).Select(y => KeyValuePair.Create(index, y))))
            {
                Assert.Equal(seen++, pIndex.Value);
                Assert.Equal(pIndex.Key, pIndex.Value / expansion);
            }
            Assert.Equal(count * expansion, seen);
        }
Ejemplo n.º 15
0
        public static void SelectMany_ResultSelector(Labeled <ParallelQuery <int> > labeled, int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion)
        {
            ParallelQuery <int> query = labeled.Item;
            Func <int, int, IEnumerable <int> > expand = expander.Item;
            int seen = 0;

            foreach (var p in query.SelectMany(x => expand(x, expansion), (original, expanded) => KeyValuePair.Create(original, expanded)))
            {
                Assert.Equal(seen++, p.Value);
                Assert.Equal(p.Key, p.Value / expansion);
            }
            Assert.Equal(count * expansion, seen);
        }
Ejemplo n.º 16
0
        public static void SelectMany_Unordered_ResultSelector_NotPipelined(int count, Labeled <Func <int, int, IEnumerable <int> > > expander, int expansion)
        {
            Func <int, int, IEnumerable <int> > expand = expander.Item;
            IntegerRangeSet seen = new IntegerRangeSet(0, count * expansion);

            Assert.All(UnorderedSources.Default(count).SelectMany(x => expand(x, expansion), (original, expanded) => KeyValuePair.Create(original, expanded)).ToList(),
                       p =>
            {
                seen.Add(p.Value);
                Assert.Equal(p.Key, p.Value / expansion);
            });
            seen.AssertComplete();
        }