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 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 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)); }
private static IEnumerable <LabeledOperation> BinaryOperations(LabeledOperation otherSource) { String label = otherSource.ToString(); Operation other = otherSource.Item; yield return(Label("Concat-Right:" + label, (start, count, source) => source(start, count / 2).Concat(other(start + count / 2, count / 2 + count % 2)))); yield return(Label("Concat-Left:" + label, (start, count, source) => other(start, count / 2).Concat(source(start + count / 2, count / 2 + count % 2)))); // Comparator needs to cover _source_ size, as which of two "equal" items is returned is undefined for unordered collections. yield return(Label("Except-Right:" + label, (start, count, source) => source(start, count + count / 2).Except(other(start + count, count), new ModularCongruenceComparer(count * 2)))); yield return(Label("Except-Left:" + label, (start, count, source) => other(start, count + count / 2).Except(source(start + count, count), new ModularCongruenceComparer(count * 2)))); yield return(Label("GroupJoin-Right:" + label, (start, count, source) => source(start, count).GroupJoin(other(start, count * CountFactor), x => x, y => y % count, (x, g) => g.Min(), new ModularCongruenceComparer(count)))); yield return(Label("GroupJoin-Left:" + label, (start, count, source) => other(start, count).GroupJoin(source(start, count * CountFactor), x => x, y => y % count, (x, g) => g.Min(), new ModularCongruenceComparer(count)))); // Comparator needs to cover _source_ size, as which of two "equal" items is returned is undefined. yield return(Label("Intersect-Right:" + label, (start, count, source) => source(start, count + count / 2).Intersect(other(start - count / 2, count + count / 2), new ModularCongruenceComparer(count * 2)))); yield return(Label("Intersect-Left:" + label, (start, count, source) => other(start, count + count / 2).Intersect(source(start - count / 2, count + count / 2), new ModularCongruenceComparer(count * 2)))); yield return(Label("Join-Right:" + label, (start, count, source) => source(0, count).Join(other(start, count), x => x, y => y - start, (x, y) => x + start, new ModularCongruenceComparer(count)))); yield return(Label("Join-Left:" + label, (start, count, source) => other(0, count).Join(source(start, count), x => x, y => y - start, (x, y) => x + start, new ModularCongruenceComparer(count)))); yield return(Label("Union-Right:" + label, (start, count, source) => source(start, count * 3 / 4).Union(other(start + count / 2, count / 2 + count % 2)))); yield return(Label("Union-Left:" + label, (start, count, source) => other(start, count * 3 / 4).Union(source(start + count / 2, count / 2 + count % 2)))); // When both sources are unordered any element can be matched to any other, so a different check is required. yield return(Label("Zip-Unordered-Right:" + label, (start, count, source) => source(0, count).Zip(other(start * 2, count), (x, y) => x + start))); yield return(Label("Zip-Unordered-Left:" + label, (start, count, source) => other(start * 2, count).Zip(source(0, count), (x, y) => y + start))); }
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))); }
private static IEnumerable<LabeledOperation> BinaryOperations(LabeledOperation otherSource) { String label = otherSource.ToString(); Operation other = otherSource.Item; yield return Label("Concat-Right:" + label, (start, count, source) => source(start, count / 2).Concat(other(start + count / 2, count / 2 + count % 2))); yield return Label("Concat-Left:" + label, (start, count, source) => other(start, count / 2).Concat(source(start + count / 2, count / 2 + count % 2))); // Comparator needs to cover _source_ size, as which of two "equal" items is returned is undefined for unordered collections. yield return Label("Except-Right:" + label, (start, count, source) => source(start, count + count / 2).Except(other(start + count, count), new ModularCongruenceComparer(count * 2))); yield return Label("Except-Left:" + label, (start, count, source) => other(start, count + count / 2).Except(source(start + count, count), new ModularCongruenceComparer(count * 2))); yield return Label("GroupJoin-Right:" + label, (start, count, source) => source(start, count).GroupJoin(other(start, count * CountFactor), x => x, y => y % count, (x, g) => g.Min(), new ModularCongruenceComparer(count))); yield return Label("GroupJoin-Left:" + label, (start, count, source) => other(start, count).GroupJoin(source(start, count * CountFactor), x => x, y => y % count, (x, g) => g.Min(), new ModularCongruenceComparer(count))); // Comparator needs to cover _source_ size, as which of two "equal" items is returned is undefined. yield return Label("Intersect-Right:" + label, (start, count, source) => source(start, count + count / 2).Intersect(other(start - count / 2, count + count / 2), new ModularCongruenceComparer(count * 2))); yield return Label("Intersect-Left:" + label, (start, count, source) => other(start, count + count / 2).Intersect(source(start - count / 2, count + count / 2), new ModularCongruenceComparer(count * 2))); yield return Label("Join-Right:" + label, (start, count, source) => source(0, count).Join(other(start, count), x => x, y => y - start, (x, y) => x + start, new ModularCongruenceComparer(count))); yield return Label("Join-Left:" + label, (start, count, source) => other(0, count).Join(source(start, count), x => x, y => y - start, (x, y) => x + start, new ModularCongruenceComparer(count))); yield return Label("Union-Right:" + label, (start, count, source) => source(start, count * 3 / 4).Union(other(start + count / 2, count / 2 + count % 2), new ModularCongruenceComparer(count))); yield return Label("Union-Left:" + label, (start, count, source) => other(start, count * 3 / 4).Union(source(start + count / 2, count / 2 + count % 2), new ModularCongruenceComparer(count))); // When both sources are unordered any element can be matched to any other, so a different check is required. yield return Label("Zip-Unordered-Right:" + label, (start, count, source) => source(0, count).Zip(other(start * 2, count), (x, y) => x + start)); yield return Label("Zip-Unordered-Left:" + label, (start, count, source) => other(start * 2, count).Zip(source(0, count), (x, y) => y + start)); }
public static void FirstOrDefault_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).FirstOrDefault(), DefaultStart, DefaultStart + DefaultSize); } else { Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).FirstOrDefault()); } Functions.AssertThrowsWrapped<DeliberateTestException>(() => operation.Item(DefaultStart, DefaultSize, source.Item).FirstOrDefault(x => false)); }
public static void SingleOrDefault(LabeledOperation source, LabeledOperation operation) { Assert.Equal(DefaultStart, operation.Item(DefaultStart, 1, source.Item).SingleOrDefault()); Assert.Equal(DefaultStart + DefaultSize / 2, operation.Item(DefaultStart, DefaultSize, source.Item).SingleOrDefault(x => x == DefaultStart + DefaultSize / 2)); if (!operation.ToString().StartsWith("DefaultIfEmpty")) { Assert.Equal(default(int), operation.Item(DefaultStart, 0, source.Item).SingleOrDefault()); Assert.Equal(default(int), operation.Item(DefaultStart, 0, source.Item).SingleOrDefault(x => x == DefaultStart + DefaultSize / 2)); } }
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()); } }