public static void Sum_Int_Overflow(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Select(x => x == 0 ? int.MaxValue : x).Sum()); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Select(x => x == 0 ? int.MaxValue : (int?)x).Sum()); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Sum(x => x == 0 ? int.MinValue : -x)); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Sum(x => x == 0 ? int.MinValue : -(int?)x)); }
public static void Average_Long_Overflow(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Select(x => x == 0 ? 1 : long.MaxValue).Average()); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Select(x => x == 0 ? (long?)1 : long.MaxValue).Average()); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Average(x => x == 0 ? -1 : long.MinValue)); Functions.AssertThrowsWrapped <OverflowException>(() => labeled.Item.Average(x => x == 0 ? (long?)-1 : long.MinValue)); }
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 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 WithCancellation_ODEIssue(Labeled <ParallelQuery <int> > labeled, int count) { //the failure was an ODE coming out due to an ephemeral disposed merged cancellation token source. ParallelQuery <int> left = labeled.Item.AsUnordered().WithExecutionMode(ParallelExecutionMode.ForceParallelism); ParallelQuery <int> right = Enumerable.Range(0, 1024).Select(x => x).AsParallel().AsUnordered(); Functions.AssertThrowsWrapped <OperationCanceledException>(() => left.GroupJoin(right, x => { throw new OperationCanceledException(); }, y => y, (x, e) => x).ForAll(x => { })); Functions.AssertThrowsWrapped <OperationCanceledException>(() => left.Join(right, x => { throw new OperationCanceledException(); }, y => y, (x, e) => x).ForAll(x => { })); Functions.AssertThrowsWrapped <OperationCanceledException>(() => left.Zip <int, int, int>(right, (x, y) => { throw new OperationCanceledException(); }).ForAll(x => { })); }
public static void GetEnumerator_MoveNextAfterQueryOpeningFailsIsIllegal(Labeled <ParallelQuery <int> > labeled, int count) { ParallelQuery <int> query = labeled.Item.Select <int, int>(x => { throw new DeliberateTestException(); }).OrderBy(x => x); IEnumerator <int> enumerator = query.GetEnumerator(); //moveNext will cause queryOpening to fail (no element generated) Functions.AssertThrowsWrapped <DeliberateTestException>(() => enumerator.MoveNext()); //moveNext after queryOpening failed Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); }
public static void ToDictionary_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary((Func <int, int>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary((Func <int, int>)(x => { throw new DeliberateTestException(); }), y => y)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary(x => x, (Func <int, int>)(y => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary((Func <int, int>)(x => { throw new DeliberateTestException(); }), EqualityComparer <int> .Default)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary((Func <int, int>)(x => { throw new DeliberateTestException(); }), y => y, EqualityComparer <int> .Default)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary(x => x, (Func <int, int>)(y => { throw new DeliberateTestException(); }), EqualityComparer <int> .Default)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary(x => x, new FailingEqualityComparer <int>())); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.ToDictionary(x => x, y => y, new FailingEqualityComparer <int>())); }
public static void First_AggregateException(LabeledOperation source, LabeledOperation 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 { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First()); } Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).First(x => false)); }
public static void Aggregate_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate((i, j) => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(0, (i, j) => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(0, (i, j) => { throw new DeliberateTestException(); }, i => i)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate <int, int, int>(0, (i, j) => i, i => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(0, (i, j) => { throw new DeliberateTestException(); }, (i, j) => i, i => i)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate <int, int, int>(0, (i, j) => i, (i, j) => i, i => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate <int, int, int>(() => { throw new DeliberateTestException(); }, (i, j) => i, (i, j) => i, i => i)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(() => 0, (i, j) => { throw new DeliberateTestException(); }, (i, j) => i, i => i)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate <int, int, int>(() => 0, (i, j) => i, (i, j) => i, i => { throw new DeliberateTestException(); })); if (Environment.ProcessorCount >= 2) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(0, (i, j) => i, (i, j) => { throw new DeliberateTestException(); }, i => i)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Aggregate(() => 0, (i, j) => i, (i, j) => { throw new DeliberateTestException(); }, i => i)); } }
public static void Sum_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, int>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, int?>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, long>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, long?>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, float>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, float?>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, double>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, double?>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, decimal>)(x => { throw new DeliberateTestException(); }))); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Sum((Func <int, decimal?>)(x => { throw new DeliberateTestException(); }))); }
public static void SequenceEqual_AggregateException(Labeled <ParallelQuery <int> > left, Labeled <ParallelQuery <int> > right, int count, int item) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => left.Item.SequenceEqual(right.Item, new FailingEqualityComparer <int>())); }
public static void Contains_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Contains(1, new FailingEqualityComparer <int>())); }
public static void CountLongCount_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Count(x => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.LongCount(x => { throw new DeliberateTestException(); })); }
public static void Any_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Any(x => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Select((Func <int, int>)(x => { throw new DeliberateTestException(); })).Any()); }
public static void Max_AggregateException_NotComparable(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <ArgumentException>(() => labeled.Item.Max(x => new NotComparable(x))); }
public static void ElementAtOrDefault_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).ElementAtOrDefault(DefaultSize - 1)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).ElementAtOrDefault(DefaultSize + 1)); }
public static void Count_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Count()); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).Count(x => true)); }
public static void ToLookup_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).ToLookup(x => x)); Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).ToLookup(x => x, y => y)); }
public static void Single_AggregateException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.Single(x => { throw new DeliberateTestException(); })); Functions.AssertThrowsWrapped <DeliberateTestException>(() => labeled.Item.SingleOrDefault(x => { throw new DeliberateTestException(); })); }
public static void Cast_Assignable_InvalidCastException(Labeled <ParallelQuery <int> > labeled, int count) { Functions.AssertThrowsWrapped <InvalidCastException>(() => labeled.Item.Select(x => (Int32)x).Cast <Castable>().ForAll(x => {; })); Functions.AssertThrowsWrapped <InvalidCastException>(() => labeled.Item.Select(x => (Int32)x).Cast <Castable>().ToList()); }
public static void ForAll_AggregateException(LabeledOperation source, LabeledOperation operation) { Functions.AssertThrowsWrapped <DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).ForAll(x => { })); }