public static void First_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            if (operation.ToString().Contains("Concat-Left"))
            {
                // The vast majority of the time, the operation returns a result instead of failing.
                // Sufficient cores on a test machine may make the optimizer start enumerating the results.
                int?result    = null;
                var exception = Record.Exception(() => { result = operation.Item(DefaultStart, DefaultSize, source.Item).First(); });
                if (result.HasValue)
                {
                    Assert.Null(exception);
                    Assert.InRange(result.Value, DefaultStart, DefaultStart + DefaultSize);
                }
                else
                {
                    Assert.NotNull(exception);
                    var ae = Assert.IsType <AggregateException>(exception);
                    Assert.All(ae.InnerExceptions, e => Assert.IsType <DeliberateTestException>(e));
                }
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First());
            }

            AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First(x => false));
        }
 public static void Aggregate_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
 {
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate((x, y) => x));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y, r => r));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (a, x) => a + x, (l, r) => l + r, r => r));
     AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(() => 0, (a, x) => a + x, (l, r) => l + r, r => r));
 }
        public static void Zip_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet     seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <int> query = operation.Item(0, DefaultSize, DefaultSource)
                                        .Zip(operation.Item(DefaultStart, DefaultSize, DefaultSource), (x, y) => y);

            Assert.All(query.ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
        public static void Intersect_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet     seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <int> query = operation.Item(DefaultStart - DefaultSize / 2, DefaultSize + DefaultSize / 2, DefaultSource)
                                        .Intersect(operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, DefaultSource));

            Assert.All(query.ToList(), x => seen.Add((int)x));
            seen.AssertComplete();
        }
        public static void Concat_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(
                operation.Item(DefaultStart, DefaultSize / 2, DefaultSource)
                .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, DefaultSource)).ToList(),
                x => seen.Add(x)
                );
            seen.AssertComplete();
        }
        public static void Concat_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            foreach (int i in operation.Item(DefaultStart, DefaultSize / 2, DefaultSource)
                     .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, DefaultSource)))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
        public static void Intersect_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet     seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <int> query = operation.Item(DefaultStart - DefaultSize / 2, DefaultSize + DefaultSize / 2, DefaultSource)
                                        .Intersect(operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, DefaultSource));

            foreach (int i in query)
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
        public static void Zip_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet     seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <int> query = operation.Item(DefaultStart, DefaultSize, DefaultSource)
                                        .Zip(operation.Item(0, DefaultSize, DefaultSource), (x, y) => x);

            foreach (int i in query)
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
        public static void Join_Unordered_NotPipelined(Labeled <Operation> source, Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <KeyValuePair <int, int> > query = operation.Item(DefaultStart / GroupFactor, DefaultSize / GroupFactor, source.Item)
                                                             .Join(operation.Item(DefaultStart, DefaultSize, source.Item), x => x, y => y / GroupFactor, (x, y) => new KeyValuePair <int, int>(x, y));

            foreach (KeyValuePair <int, int> p in query.ToList())
            {
                Assert.Equal(p.Key, p.Value / GroupFactor);
                seen.Add(p.Value);
            }
            seen.AssertComplete();
        }
        public static void GroupJoin_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seenKey = new IntegerRangeSet(DefaultStart / GroupFactor, DefaultSize / GroupFactor);

            foreach (KeyValuePair <int, IEnumerable <int> > group in operation.Item(DefaultStart / GroupFactor, DefaultSize / GroupFactor, DefaultSource)
                     .GroupJoin(operation.Item(DefaultStart, DefaultSize, DefaultSource), x => x, y => y / GroupFactor, (k, g) => new KeyValuePair <int, IEnumerable <int> >(k, g)).ToList())
            {
                Assert.True(seenKey.Add(group.Key));
                IntegerRangeSet seenElement = new IntegerRangeSet(group.Key * GroupFactor, GroupFactor);
                Assert.All(group.Value, x => seenElement.Add(x));
                seenElement.AssertComplete();
            }
            seenKey.AssertComplete();
        }
        public static void First_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            // Concat seems able to return the first element when the left query does not fail ("first" query).
            // This test might be flaky in the case that it decides to run the right query too...
            if (operation.ToString().Contains("Concat-Left"))
            {
                Assert.InRange(operation.Item(DefaultStart, DefaultSize, source.Item).First(), DefaultStart, DefaultStart + DefaultSize);
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First());
            }

            AssertThrows.Wrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First(x => false));
        }
Exemplo n.º 12
0
        public static void Select_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).Select(x => - x).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 13
0
        public static void ToArray_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).ToArray(), x => seen.Add(x));
            seen.AssertComplete();
        }
        public static void GetEnumerator_AggregateException(Labeled <Operation> source, Labeled <Operation> operation)
        {
            IEnumerator <int> enumerator = operation.Item(DefaultStart, DefaultSize, source.Item).GetEnumerator();

            // Spin until concat hits
            // Union-Left needs to spin more than once rarely.
            if (operation.ToString().StartsWith("Concat") || operation.ToString().StartsWith("Union-Left:ParallelEnumerable"))
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => { while (enumerator.MoveNext())
                                                                       {
                                                                           ;
                                                                       }
                                                               });
            }
            else
            {
                AssertThrows.Wrapped <DeliberateTestException>(() => enumerator.MoveNext());
            }

            if (operation.ToString().StartsWith("OrderBy") || operation.ToString().StartsWith("ThenBy"))
            {
                Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext());
            }
            else
            {
                Assert.False(enumerator.MoveNext());
            }
        }
Exemplo n.º 15
0
        public static void Where_Indexed_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize / 2);

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).Where((x, index) => x < DefaultStart + DefaultSize / 2).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 16
0
        public static void DefaultIfEmpty_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).DefaultIfEmpty().ToList(), x => seen.Add((int)x));
            seen.AssertComplete();
        }
Exemplo n.º 17
0
        public static void SelectMany_ResultSelector_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);

            Assert.All(operation.Item(0, DefaultSize, DefaultSource).SelectMany(x => new[] { 0, -1 }, (x, y) => y + -DefaultStart - 2 * x).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
Exemplo n.º 18
0
        public static void Take_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            int             count = 0;

            Assert.All(operation.Item(DefaultStart, DefaultSize, DefaultSource).Take(DefaultSize / 2).ToList(), x => { seen.Add(x); count++; });
            Assert.Equal(DefaultSize / 2, count);
        }
Exemplo n.º 19
0
        public static void SelectMany_Indexed_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            Assert.All(operation.Item(0, DefaultSize, DefaultSource).SelectMany((x, index) => { indices.Add(index); return(new[] { 0, -1 }.Select(y => y + -DefaultStart - 2 * x)); }).ToList(), x => seen.Add(x));
            seen.AssertComplete();
            indices.AssertComplete();
        }
Exemplo n.º 20
0
        public static void Where_Indexed_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize / 2);

            foreach (int i in operation.Item(DefaultStart, DefaultSize, DefaultSource).Where((x, index) => x < DefaultStart + DefaultSize / 2))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
Exemplo n.º 21
0
        public static void Select_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);

            foreach (int i in operation.Item(DefaultStart, DefaultSize, DefaultSource).Select(x => - x))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
Exemplo n.º 22
0
        public static void SelectMany_ResultSelector_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2);

            foreach (int i in operation.Item(0, DefaultSize, DefaultSource).SelectMany(x => new[] { 0, -1 }, (x, y) => y + -DefaultStart - 2 * x))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
Exemplo n.º 23
0
        public static void DefaultIfEmpty_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            foreach (int i in operation.Item(DefaultStart, DefaultSize, DefaultSource).DefaultIfEmpty())
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
Exemplo n.º 24
0
        [MemberData(nameof(WithExecutionModeQueryData), new int[] { 1, 4 })] // DOP of 1 to verify sequential and 4 to verify parallel
        public static void WithExecutionMode(
            Labeled <ParallelQuery <int> > labeled,
            int requestedDop, int expectedDop,
            Labeled <Action <UsedTaskTracker, ParallelQuery <int> > > operation,
            ParallelExecutionMode mode)
        {
            UsedTaskTracker tracker = new UsedTaskTracker();

            operation.Item(tracker, labeled.Item.WithDegreeOfParallelism(requestedDop).WithExecutionMode(mode));
            Assert.Equal(expectedDop, tracker.UniqueTasksCount);
        }
Exemplo n.º 25
0
        public static void Cast_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize);

            foreach (int?i in operation.Item(DefaultStart, DefaultSize, DefaultSource).Cast <int?>())
            {
                Assert.True(i.HasValue);
                seen.Add(i.Value);
            }
            seen.AssertComplete();
        }
Exemplo n.º 26
0
        public static void Distinct_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet     seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            ParallelQuery <int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, DefaultSource).Select(x => x / 2).Distinct();

            foreach (int i in query)
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
Exemplo n.º 27
0
        public static void Select_Index_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen    = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize);
            IntegerRangeSet indices = new IntegerRangeSet(0, DefaultSize);

            foreach (int i in operation.Item(DefaultStart, DefaultSize, DefaultSource).Select((x, index) => { indices.Add(index); return(-x); }))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
            indices.AssertComplete();
        }
Exemplo n.º 28
0
        public static void SelectMany_Indexed_ResultSelector_Unordered(Labeled <Operation> 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, DefaultSource).SelectMany((x, index) => { indices.Add(index); return(new[] { 0, -1 }); }, (x, y) => y + -DefaultStart - 2 * x))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
            indices.AssertComplete();
        }
Exemplo n.º 29
0
        public static void Take_Unordered(Labeled <Operation> operation)
        {
            IntegerRangeSet seen  = new IntegerRangeSet(DefaultStart, DefaultSize);
            int             count = 0;

            foreach (int i in operation.Item(DefaultStart, DefaultSize, DefaultSource).Take(DefaultSize / 2))
            {
                seen.Add(i);
                count++;
            }
            Assert.Equal(DefaultSize / 2, count);
        }
Exemplo n.º 30
0
        public static void GroupBy_ElementSelector_Unordered_NotPipelined(Labeled <Operation> operation)
        {
            IntegerRangeSet seenKey = new IntegerRangeSet(DefaultStart / GroupFactor, (DefaultSize + (GroupFactor - 1)) / GroupFactor);

            foreach (IGrouping <int, int> group in operation.Item(DefaultStart, DefaultSize, DefaultSource).GroupBy(x => x / GroupFactor, y => - y).ToList())
            {
                seenKey.Add(group.Key);
                IntegerRangeSet seenElement = new IntegerRangeSet(1 - Math.Min(DefaultStart + DefaultSize, (group.Key + 1) * GroupFactor), Math.Min(GroupFactor, DefaultSize - (group.Key - 1) * GroupFactor));
                Assert.All(group, x => seenElement.Add(x));
                seenElement.AssertComplete();
            }
            seenKey.AssertComplete();
        }