Exemplo n.º 1
0
        public static void Where_Unordered_NotPipelined(int count)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, (count + 1) / 2);

            Assert.All(UnorderedSources.Default(count).Where(x => x % 2 == 0).ToList(), x => seen.Add(x / 2));
            seen.AssertComplete();
        }
Exemplo n.º 2
0
        public static void GroupBy_Unordered_ElementSelector_ResultSelector(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query      = labeled.Item;
            IntegerRangeSet     groupsSeen = new IntegerRangeSet(0, Math.Min(count, GroupFactor));

            foreach (var group in query.GroupBy(x => x % GroupFactor, x => - x, (key, elements) => KeyValuePair.Create(key, elements)))
            {
                groupsSeen.Add(group.Key);
                int             expected     = 1 + (count - (group.Key + 1)) / GroupFactor;
                IntegerRangeSet elementsSeen = new IntegerRangeSet(1 - expected, expected);
                Assert.All(group.Value, x => { Assert.Equal(group.Key, -x % GroupFactor); elementsSeen.Add(x / GroupFactor); });
                elementsSeen.AssertComplete();
            }
            groupsSeen.AssertComplete();
        }
Exemplo n.º 3
0
        public static void Cast_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).Cast <int?>().ToList(), x => seen.Add((int)x));
            seen.AssertComplete();
        }
        public static void TakeWhile_Unordered_NotPipelined(int count, int take)
        {
            // For unordered collections, which elements (if any) are taken 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.
            IntegerRangeSet seen = new IntegerRangeSet(0, Math.Min(count, Math.Max(0, take)));

            Assert.All(UnorderedSources.Default(count).TakeWhile(x => x < take).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 5
0
        public static void SelectMany_Unordered_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)).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 6
0
        public static void Cast_Unordered_Valid_NotPipelined(int count)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, count);

            Assert.All(UnorderedSources.Default(count).Select(x => (object)x).Cast <int>().ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 7
0
        public static void GroupBy_Unordered_ElementSelector_ResultSelector(int count)
        {
            IntegerRangeSet groupsSeen = new IntegerRangeSet(0, Math.Min(count, GroupFactor));

            foreach (var group in UnorderedSources.Default(count).GroupBy(x => x % GroupFactor, x => - x, (key, elements) => KeyValuePair.Create(key, elements)))
            {
                groupsSeen.Add(group.Key);
                int             expected     = 1 + (count - (group.Key + 1)) / GroupFactor;
                IntegerRangeSet elementsSeen = new IntegerRangeSet(1 - expected, expected);
                Assert.All(group.Value, x => { Assert.Equal(group.Key, -x % GroupFactor); elementsSeen.Add(x / GroupFactor); });
                elementsSeen.AssertComplete();
            }
            groupsSeen.AssertComplete();
        }
        public static void SelectMany_Indexed_ResultSelector_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            Assert.All(operation.Item(0, DefaultSize, source.Item).SelectMany((x, index) => { indices.Add(index); return(new[] { 0, -1 }); }, (x, y) => y + -DefaultStart - 2 * x).ToList(), x => seen.Add(x));
            seen.AssertComplete();
            indices.AssertComplete();
        }
        public static void Take_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            int             count = 0;

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).Take(DefaultSize / 2).ToList(), x => { seen.Add(x); count++; });
            Assert.Equal(DefaultSize / 2, count);
        }
        public static void SelectMany_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);

            Assert.All(operation.Item(0, DefaultSize, source.Item).SelectMany(x => new[] { 0, -1 }.Select(y => y + -DefaultStart - 2 * x)).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
        public static void SelectMany_Indexed_ResultSelector_Unordered(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            foreach (int i in operation.Item(0, DefaultSize, source.Item).SelectMany((x, index) => { indices.Add(index); return(new[] { 0, -1 }); }, (x, y) => y + -DefaultStart - 2 * x))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
            indices.AssertComplete();
        }
        public static void Select_Index_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).Select((x, index) => { indices.Add(index); return(-x); }).ToList(), x => seen.Add(x));
            seen.AssertComplete();
            indices.AssertComplete();
        }
        public static void Select_Index_Unordered(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Select((x, index) => { indices.Add(index); return(-x); }))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
            indices.AssertComplete();
        }
        public static void Select_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).Select(x => - x).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 15
0
        public static void Except_Unordered_Distinct_NotPipelined(int leftCount, int rightStart, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightStart, rightCount);

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            int             expectedCount = Math.Max(0, leftCount - rightCount);
            IntegerRangeSet seen          = new IntegerRangeSet(leftCount - expectedCount, expectedCount);

            Assert.All(leftQuery.Except(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor),
                                        new ModularCongruenceComparer(DuplicateFactor * 2)).ToList(), x => seen.Add(x % (DuplicateFactor * 2)));
            seen.AssertComplete();
        }
        public static void ToArray_Unordered(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).ToArray(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 17
0
        public static void Distinct_Unordered_NotPipelined(int count, int uniqueCount)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, uniqueCount);

            Assert.All(UnorderedSources.Default(count).Distinct(new ModularCongruenceComparer(uniqueCount)).ToList(), x => seen.Add(x % uniqueCount));
            seen.AssertComplete();
        }
        public static void Where_Indexed_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize / 2);

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).Where((x, index) => x < DefaultStart + DefaultSize / 2).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 19
0
        public static void GroupBy_Unordered_ResultSelector_CustomComparator(int count)
        {
            IntegerRangeSet groupsSeen = new IntegerRangeSet(0, Math.Min(count, GroupFactor));

            foreach (var group in UnorderedSources.Default(count).GroupBy(x => x, (key, elements) => KeyValuePair.Create(key, elements), new ModularCongruenceComparer(GroupFactor)))
            {
                groupsSeen.Add(group.Key % GroupFactor);
                IntegerRangeSet elementsSeen = new IntegerRangeSet(0, 1 + (count - (group.Key % GroupFactor + 1)) / GroupFactor);
                Assert.All(group.Value, x => { Assert.Equal(group.Key % GroupFactor, x % GroupFactor); elementsSeen.Add(x / GroupFactor); });
                elementsSeen.AssertComplete();
            }
            groupsSeen.AssertComplete();
        }
        public static void DefaultIfEmpty_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, source.Item).DefaultIfEmpty().ToList(), x => seen.Add((int)x));
            seen.AssertComplete();
        }
Exemplo n.º 21
0
        public static void OfType_Unordered_SomeValid_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item;
            IntegerRangeSet     seen  = new IntegerRangeSet(count / 2, (count + 1) / 2);

            Assert.All(query.Select(x => x >= count / 2 ? (object)x : x.ToString()).OfType <int>().ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 22
0
        public static void Intersect_Unordered_Distinct_NotPipelined(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            IntegerRangeSet seen = new IntegerRangeSet(0, Math.Min(leftCount, rightCount));

            Assert.All(leftQuery.Intersect(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor), new ModularCongruenceComparer(DuplicateFactor * 2)).ToList(), x => seen.Add(x % (DuplicateFactor * 2)));
            seen.AssertComplete();
        }
Exemplo n.º 23
0
        public static void Distinct_Unordered_NotPipelined(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query = labeled.Item;
            IntegerRangeSet     seen  = new IntegerRangeSet(0, count);

            Assert.All(query.Distinct(new ModularCongruenceComparer(count)).ToList(), x => seen.Add(x % count));
            seen.AssertComplete();
        }
Exemplo n.º 24
0
        public static void DefaultIfEmpty_Unordered_NotEmpty_NotPipelined(int count)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, count);

            Assert.All(UnorderedSources.Default(count).DefaultIfEmpty().ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 25
0
        public static void GroupBy_Unordered_ResultSelector_CustomComparator(Labeled <ParallelQuery <int> > labeled, int count)
        {
            ParallelQuery <int> query      = labeled.Item;
            IntegerRangeSet     groupsSeen = new IntegerRangeSet(0, Math.Min(count, GroupFactor));

            foreach (var group in query.GroupBy(x => x, (key, elements) => KeyValuePair.Create(key, elements), new ModularCongruenceComparer(GroupFactor)))
            {
                groupsSeen.Add(group.Key % GroupFactor);
                IntegerRangeSet elementsSeen = new IntegerRangeSet(0, 1 + (count - (group.Key % GroupFactor + 1)) / GroupFactor);
                Assert.All(group.Value, x => { Assert.Equal(group.Key % GroupFactor, x % GroupFactor); elementsSeen.Add(x / GroupFactor); });
                elementsSeen.AssertComplete();
            }
            groupsSeen.AssertComplete();
        }
        public static void GroupJoin_Unordered_CustomComparator(int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightCount);
            IntegerRangeSet     seenOuter  = new IntegerRangeSet(0, leftCount);

            Assert.All(leftQuery.GroupJoin(rightQuery, x => x, y => y % ElementFactor, (x, y) => KeyValuePair.Create(x, y), new ModularCongruenceComparer(KeyFactor)),
                       p =>
            {
                seenOuter.Add(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);
                }
            });
            seenOuter.AssertComplete();
        }
Exemplo n.º 27
0
        public static void SkipWhile_Indexed_Unordered_NotPipelined(int count, int skip)
        {
            // For unordered collections, which elements (if any) are skipped 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.
            IntegerRangeSet seen = new IntegerRangeSet(Math.Max(skip, 0), Math.Min(count, Math.Max(0, count - skip)));

            Assert.All(UnorderedSources.Default(count).SkipWhile((x, index) => index < skip), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 28
0
        public static void Concat_Unordered_NotPipelined(int leftCount, int rightCount)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, leftCount + rightCount);

            Assert.All(UnorderedSources.Default(leftCount).Concat(UnorderedSources.Default(leftCount, rightCount)).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 29
0
        public static void SequenceEqual_SharedRight_Cancellation(Labeled <ParallelQuery <int> > left, Labeled <ParallelQuery <int> > right, int count)
        {
            IntegerRangeSet         seen = new IntegerRangeSet(0, count);
            CancellationTokenSource cs   = new CancellationTokenSource();

            Assert.Throws <OperationCanceledException>(() => left.Item.Except(ParallelEnumerable.Range(0, count).Select(x => { cs.Cancel(); seen.Add(x); return(x); }))
                                                       .SequenceEqual(right.Item.WithCancellation(cs.Token)));
            // Canceled query means some elements should not be seen.
            Assert.False(seen.All(x => x.Value));
        }
Exemplo n.º 30
0
        public static void Where_Indexed_Unordered_NotPipelined(int count)
        {
            IntegerRangeSet seen = new IntegerRangeSet(0, count);

            Assert.All(UnorderedSources.Default(count).Where((x, index) => x == index).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }