public static void GetEnumerator_AggregateException(LabeledOperation source, LabeledOperation 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")) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => { while (enumerator.MoveNext()) { ; } }); } else { Functions.AssertThrowsWrapped <DeliberateTestException>(() => enumerator.MoveNext()); } if (operation.ToString().StartsWith("OrderBy") || operation.ToString().StartsWith("ThenBy")) { Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); } else { Assert.False(enumerator.MoveNext()); } }
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(); }
public LabeledOperation Append(LabeledOperation next) { Operation op = Item; Operation nxt = next.Item; return(Label(ToString() + "|" + next.ToString(), (start, count, source) => nxt(start, count, (s, c, ignore) => op(s, c, source)))); }
public static void SelectMany_ResultSelector_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 }, (x, y) => y + -DefaultStart - 2 * x).ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public static void Contains_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Contains(DefaultStart)); }
public static void Distinct_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery<int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, source.Item).Select(x => x / 2).Distinct(); Assert.All(query.ToList(), x => seen.Add((int)x)); 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(); }
public static IEnumerable <object[]> UnaryFailingOperators() { LabeledOperation source = UnorderedRangeSources().First(); foreach (LabeledOperation operation in new[] { Label("Distinct", (start, count, s) => s(start, count).Distinct(new FailingEqualityComparer <int>())), Label("GroupBy", (start, count, s) => s(start, count).GroupBy <int, int>(x => { throw new DeliberateTestException(); }).Select(g => g.Key)), Label("GroupBy-Comparer", (start, count, s) => s(start, count).GroupBy(x => x, new FailingEqualityComparer <int>()).Select(g => g.Key)), Label("GroupBy-ElementSelector", (start, count, s) => s(start, count).GroupBy <int, int, int>(x => x, x => { throw new DeliberateTestException(); }).Select(g => g.Key)), Label("GroupBy-ResultSelector", (start, count, s) => s(start, count).GroupBy <int, int, int, int>(x => x, x => x, (x, g) => { throw new DeliberateTestException(); })), Label("Select", (start, count, s) => s(start, count).Select <int, int>(x => { throw new DeliberateTestException(); })), Label("Select-Index", (start, count, s) => s(start, count).Select <int, int>((x, index) => { throw new DeliberateTestException(); })), Label("SelectMany", (start, count, s) => s(start, count).SelectMany <int, int>(x => { throw new DeliberateTestException(); })), Label("SelectMany-Index", (start, count, s) => s(start, count).SelectMany <int, int>((x, index) => { throw new DeliberateTestException(); })), Label("SelectMany-ResultSelector", (start, count, s) => s(start, count).SelectMany <int, int, int>(x => Enumerable.Range(x, 2), (group, elem) => { throw new DeliberateTestException(); })), Label("SelectMany-Index-ResultSelector", (start, count, s) => s(start, count).SelectMany <int, int, int>((x, index) => Enumerable.Range(x, 2), (group, elem) => { throw new DeliberateTestException(); })), Label("SkipWhile", (start, count, s) => s(start, count).SkipWhile(x => { throw new DeliberateTestException(); })), Label("SkipWhile-Index", (start, count, s) => s(start, count).SkipWhile((x, index) => { throw new DeliberateTestException(); })), Label("TakeWhile", (start, count, s) => s(start, count).TakeWhile(x => { throw new DeliberateTestException(); })), Label("TakeWhile-Index", (start, count, s) => s(start, count).SkipWhile((x, index) => { throw new DeliberateTestException(); })), Label("Where", (start, count, s) => s(start, count).Where(x => { throw new DeliberateTestException(); })), Label("Where-Index", (start, count, s) => s(start, count).Where((x, index) => { throw new DeliberateTestException(); })), }) { yield return(new object[] { source, operation }); } }
public static IEnumerable <object[]> BinaryFailingOperators() { LabeledOperation failing = Label("Failing", (start, count, s) => s(start, count).Select <int, int>(x => { throw new DeliberateTestException(); })); LabeledOperation source = UnorderedRangeSources().First(); foreach (LabeledOperation operation in BinaryOperations(UnorderedRangeSources().First())) { foreach (LabeledOperation other in UnorderedRangeSources()) { yield return(new object[] { other.Append(failing), operation }); } yield return(new object[] { Failing, operation }); } foreach (LabeledOperation operation in new[] { Label("Except-Fail", (start, count, s) => s(start, count).Except(source.Item(start, count), new FailingEqualityComparer <int>())), Label("GroupJoin-Fail", (start, count, s) => s(start, count).GroupJoin(source.Item(start, count), x => x, y => y, (x, g) => x, new FailingEqualityComparer <int>())), Label("Intersect-Fail", (start, count, s) => s(start, count).Intersect(source.Item(start, count), new FailingEqualityComparer <int>())), Label("Join-Fail", (start, count, s) => s(start, count).Join(source.Item(start, count), x => x, y => y, (x, y) => x, new FailingEqualityComparer <int>())), Label("Union-Fail", (start, count, s) => s(start, count).Union(source.Item(start, count), new FailingEqualityComparer <int>())), Label("Zip-Fail", (start, count, s) => s(start, count).Zip <int, int, int>(source.Item(start, count), (x, y) => { throw new DeliberateTestException(); })), }) { yield return(new object[] { source, operation }); } }
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(); }
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(); }
public static void Distinct_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, source.Item).Select(x => x / 2).Distinct(); Assert.All(query.ToList(), x => seen.Add((int)x)); seen.AssertComplete(); }
public static void Aggregate_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate((x, y) => x)); Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y)); Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y, r => r)); Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (a, x) => a + x, (l, r) => l + r, r => r)); Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(() => 0, (a, x) => a + x, (l, r) => l + r, r => r)); }
public static void Aggregate_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate((x, y) => x)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (x, y) => x + y, r => r)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(0, (a, x) => a + x, (l, r) => l + r, r => r)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Aggregate(() => 0, (a, x) => a + x, (l, r) => l + r, r => r)); }
public static void ElementAt_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, (start, count, ignore) => source.Item(start, count).WithCancellation(cs.Token)).ElementAt(0)); }
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 Contains_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Contains(DefaultStart)); }
public static void LastOrDefault_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, (start, count, ignore) => source.Item(start, count).WithCancellation(cs.Token)).LastOrDefault()); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).LastOrDefault(x => true)); }
public static void Zip_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(0, DefaultSize, source.Item) .Zip(operation.Item(DefaultStart, DefaultSize, source.Item), (x, y) => y); Assert.All(query.ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public static void SequenceEqual_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).SequenceEqual(ParallelEnumerable.Range(0, 2))); Functions.AssertIsCanceled(cs, () => ParallelEnumerable.Range(0, 2).SequenceEqual(operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item))); }
public static void DefaultIfEmpty_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).DefaultIfEmpty()) { seen.Add(i); } seen.AssertComplete(); }
public static void SelectMany_Indexed_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 }.Select(y => y + -DefaultStart - 2 * x)); }).ToList(), x => seen.Add(x)); seen.AssertComplete(); indices.AssertComplete(); }
public static void Except_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, source.Item) .Except(operation.Item(DefaultStart + DefaultSize, DefaultSize, source.Item)); Assert.All(query.ToList(), x => seen.Add((int)x)); seen.AssertComplete(); }
public static void Select_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Select(x => - x)) { seen.Add(i); } seen.AssertComplete(); }
public static void Concat_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); Assert.All( operation.Item(DefaultStart, DefaultSize / 2, source.Item) .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, source.Item)).ToList(), x => seen.Add(x) ); seen.AssertComplete(); }
public static void Distinct_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery<int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, source.Item).Select(x => x / 2).Distinct(); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void SelectMany_ResultSelector_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2); foreach (int i in operation.Item(0, DefaultSize, source.Item).SelectMany(x => new[] { 0, -1 }, (x, y) => y + -DefaultStart - 2 * x)) { seen.Add(i); } seen.AssertComplete(); }
public static void Cast_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int? i in operation.Item(DefaultStart, DefaultSize, source.Item).Cast<int?>()) { Assert.True(i.HasValue); seen.Add(i.Value); } seen.AssertComplete(); }
public static void DefaultIfEmpty_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).DefaultIfEmpty()) { seen.Add(i); } seen.AssertComplete(); }
public static void Concat_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize / 2, source.Item) .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, source.Item))) { seen.Add(i); } seen.AssertComplete(); }
public static void Where_Indexed_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize / 2); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Where((x, index) => x < DefaultStart + DefaultSize / 2)) { seen.Add(i); } seen.AssertComplete(); }
public static void Except_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery<int> query = operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, source.Item) .Except(operation.Item(DefaultStart + DefaultSize, DefaultSize, source.Item)); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void Concat_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); Assert.All( operation.Item(DefaultStart, DefaultSize / 2, source.Item) .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, source.Item)).ToList(), x => seen.Add(x) ); seen.AssertComplete(); }
public static void Aggregate_OperationCanceledException_PreCanceled(LabeledOperation source, LabeledOperation operation) { CancellationTokenSource cs = new CancellationTokenSource(); cs.Cancel(); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Aggregate((x, y) => x)); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Aggregate(0, (x, y) => x + y)); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Aggregate(0, (x, y) => x + y, r => r)); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Aggregate(0, (a, x) => a + x, (l, r) => l + r, r => r)); Functions.AssertIsCanceled(cs, () => operation.Item(DefaultStart, DefaultSize, source.Append(WithCancellation(cs.Token)).Item).Aggregate(() => 0, (a, x) => a + x, (l, r) => l + r, r => r)); }
public static void Cast_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int?i in operation.Item(DefaultStart, DefaultSize, source.Item).Cast <int?>()) { Assert.True(i.HasValue); seen.Add(i.Value); } seen.AssertComplete(); }
public static void Concat_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize / 2, source.Item) .Concat(operation.Item(DefaultStart + DefaultSize / 2, DefaultSize / 2, source.Item))) { seen.Add(i); } seen.AssertComplete(); }
public static void Distinct_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, source.Item).Select(x => x / 2).Distinct(); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void Except_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, source.Item) .Except(operation.Item(DefaultStart + DefaultSize, DefaultSize, source.Item)); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void Zip_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart, DefaultSize, source.Item) .Zip(operation.Item(0, DefaultSize, source.Item), (x, y) => x); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void Take_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); int count = 0; foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Take(DefaultSize / 2)) { seen.Add(i); count++; } Assert.Equal(DefaultSize / 2, count); }
public static void Select_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize + 1, DefaultSize); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Select(x => -x)) { seen.Add(i); } seen.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(); }
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_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 Zip_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery<int> query = operation.Item(0, DefaultSize, source.Item) .Zip(operation.Item(DefaultStart, DefaultSize, source.Item), (x, y) => y); Assert.All(query.ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public static void GetEnumerator_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); IEnumerator<int> enumerator = operation.Item(DefaultStart, DefaultSize, source.Item).GetEnumerator(); while (enumerator.MoveNext()) { int current = enumerator.Current; seen.Add(current); Assert.Equal(current, enumerator.Current); } seen.AssertComplete(); Assert.Throws<NotSupportedException>(() => enumerator.Reset()); }
public static void GroupJoin_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seenKey = new IntegerRangeSet(DefaultStart / GroupFactor, DefaultSize / GroupFactor); foreach (KeyValuePair<int, IEnumerable<int>> group in operation.Item(DefaultStart / GroupFactor, DefaultSize / GroupFactor, source.Item) .GroupJoin(operation.Item(DefaultStart, DefaultSize, source.Item), 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 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 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(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); int count = 0; foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Take(DefaultSize / 2)) { seen.Add(i); count++; } Assert.Equal(DefaultSize / 2, count); }
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(); }
public static void Where_Indexed_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize / 2); foreach (int i in operation.Item(DefaultStart, DefaultSize, source.Item).Where((x, index) => x < DefaultStart + DefaultSize / 2)) { seen.Add(i); } 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(); }
public static void Zip_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery<int> query = operation.Item(DefaultStart, DefaultSize, source.Item) .Zip(operation.Item(0, DefaultSize, source.Item), (x, y) => x); foreach (int i in query) { seen.Add(i); } seen.AssertComplete(); }
public static void Join_Unordered_NotPipelined(LabeledOperation source, LabeledOperation 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 SelectMany_ResultSelector_Unordered(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(-DefaultStart - DefaultSize * 2 + 1, DefaultSize * 2); foreach (int i in operation.Item(0, DefaultSize, source.Item).SelectMany(x => new[] { 0, -1 }, (x, y) => y + -DefaultStart - 2 * x)) { seen.Add(i); } seen.AssertComplete(); }
public static void GroupBy_ElementSelector_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seenKey = new IntegerRangeSet(DefaultStart / GroupFactor, (DefaultSize + (GroupFactor - 1)) / GroupFactor); foreach (IGrouping<int, int> group in operation.Item(DefaultStart, DefaultSize, source.Item).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(); }
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 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 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(); }