public static void GroupJoin_Unordered_Multiple(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 / KeyFactor, (x, y) => KeyValuePair.Create(x, y)), p => { seenOuter.Add(p.Key); if (p.Key < (rightCount + (KeyFactor - 1)) / KeyFactor) { IntegerRangeSet seenInner = new IntegerRangeSet(p.Key * KeyFactor, Math.Min(rightCount - p.Key * KeyFactor, KeyFactor)); Assert.All(p.Value, y => { Assert.Equal(p.Key, y / KeyFactor); seenInner.Add(y); }); seenInner.AssertComplete(); } else { Assert.Empty(p.Value); } }); seenOuter.AssertComplete(); }
public static void Aggregate_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).Aggregate((i, j) => i)); AssertExtensions.Throws <ArgumentNullException>("func", () => UnorderedSources.Default(1).Aggregate(null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).Aggregate(0, (i, j) => i)); AssertExtensions.Throws <ArgumentNullException>("func", () => UnorderedSources.Default(1).Aggregate(0, null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).Aggregate(0, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("func", () => UnorderedSources.Default(1).Aggregate(0, null, i => i)); AssertExtensions.Throws <ArgumentNullException>("resultSelector", () => UnorderedSources.Default(1).Aggregate <int, int, int>(0, (i, j) => i, null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).Aggregate(0, (i, j) => i, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("updateAccumulatorFunc", () => UnorderedSources.Default(1).Aggregate(0, null, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("combineAccumulatorsFunc", () => UnorderedSources.Default(1).Aggregate(0, (i, j) => i, null, i => i)); AssertExtensions.Throws <ArgumentNullException>("resultSelector", () => UnorderedSources.Default(1).Aggregate <int, int, int>(0, (i, j) => i, (i, j) => i, null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).Aggregate(() => 0, (i, j) => i, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("seedFactory", () => UnorderedSources.Default(1).Aggregate <int, int, int>(null, (i, j) => i, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("updateAccumulatorFunc", () => UnorderedSources.Default(1).Aggregate(() => 0, null, (i, j) => i, i => i)); AssertExtensions.Throws <ArgumentNullException>("combineAccumulatorsFunc", () => UnorderedSources.Default(1).Aggregate(() => 0, (i, j) => i, null, i => i)); AssertExtensions.Throws <ArgumentNullException>("resultSelector", () => UnorderedSources.Default(1).Aggregate <int, int, int>(() => 0, (i, j) => i, (i, j) => i, null)); }
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(); }
// Get a set of ranges from 0 to each count, having an extra parameter describing the maximum (count - 1) public static IEnumerable <object[]> MaxData(int[] counts) { counts = counts.DefaultIfEmpty(Sources.OuterLoopCount).ToArray(); Func <int, int> max = x => x - 1; foreach (int count in counts) { yield return(new object[] { Labeled.Label("Default", UnorderedSources.Default(0, count)), count, max(count) }); } // A source with data explicitly created out of order foreach (int count in counts) { int[] data = Enumerable.Range(0, count).ToArray(); for (int i = 0; i < count / 2; i += 2) { int tmp = data[i]; data[i] = data[count - i - 1]; data[count - i - 1] = tmp; } yield return(new object[] { Labeled.Label("Out-of-order input", data.AsParallel()), count, max(count) }); } }
public static void Cast_Unordered_InvalidCastException(int count) { AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Cast <double>().ForAll(x => {; })); AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Cast <double>().ToList()); }
public static void Any_OneFalse(int count, int position) { Assert.True(UnorderedSources.Default(count).Any(x => !(x == position))); }
public static void All_AllFalse(int count) { Assert.Equal(count == 0, UnorderedSources.Default(count).All(x => x < 0)); }
public static void Average_Long_AllNull(int count) { Assert.Null(UnorderedSources.Default(count).Select(x => (long?)null).Average()); Assert.Null(UnorderedSources.Default(count).Average(x => (long?)null)); }
public static void Average_Int_AllNull(int count, double average) { Assert.Null(UnorderedSources.Default(count).Select(x => (int?)null).Average()); Assert.Null(UnorderedSources.Default(count).Average(x => (int?)null)); }
public static void Aggregate_Collection_Seed(int count) { Assert.Equal(Enumerable.Range(0, count), UnorderedSources.Default(count).Aggregate(ImmutableList <int> .Empty, (l, x) => l.Add(x)).OrderBy(x => x)); }
public static void Aggregate_Sum_Seed(int count) { Assert.Equal(Functions.SumRange(0, count), UnorderedSources.Default(count).Aggregate(0, (x, y) => x + y)); }
public static void Aggregate_Sum(int count) { // The operation will overflow for long-running sizes, but that's okay: // The helper is overflowing too! Assert.Equal(Functions.SumRange(0, count), UnorderedSources.Default(count).Aggregate((x, y) => x + y)); }
public static void Any_AllFalse(int count) { IntegerRangeSet seen = new IntegerRangeSet(0, count); Assert.False(UnorderedSources.Default(count).Any(x => !seen.Add(x))); seen.AssertComplete(); }
public static void Cast_Unordered_Assignable_InvalidCastException(int count) { AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Select(x => (Int32)x).Cast <Castable>().ForAll(x => {; })); AssertThrows.Wrapped <InvalidCastException>(() => UnorderedSources.Default(count).Select(x => (Int32)x).Cast <Castable>().ToList()); }
public static void Aggregate_Sum_Result(int count) { Assert.Equal(Functions.SumRange(0, count) + ResultFuncModifier, UnorderedSources.Default(count).Aggregate(0, (x, y) => x + y, result => result + ResultFuncModifier)); }
public static void TakeWhile_AllFalse(int count, int take) { _ = take; Assert.Empty(UnorderedSources.Default(count).TakeWhile(x => false)); }
protected virtual ParallelQuery <int> CreateRight(int count) => UnorderedSources.Default(count);
public static void Average_Float_SomeNull(int count, float average) { Assert.Equal((float?)Math.Truncate(average), UnorderedSources.Default(count).Select(x => (x % 2 == 0) ? (float?)x : null).Average()); Assert.Equal((float?)Math.Truncate(-average), UnorderedSources.Default(count).Average(x => (x % 2 == 0) ? -(float?)x : null)); }
public static void Any_AggregateException() { AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Any(x => { throw new DeliberateTestException(); })); AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).Select((Func <int, int>)(x => { throw new DeliberateTestException(); })).Any()); }
public static void Average_Long_SomeNull(int count, double average) { Assert.Equal(Math.Truncate(average), UnorderedSources.Default(count).Select(x => (x % 2 == 0) ? (long?)x : null).Average()); Assert.Equal(Math.Truncate(-average), UnorderedSources.Default(count).Average(x => (x % 2 == 0) ? -(long?)x : null)); }
public static void Any_Contents(int count) { Assert.Equal(count > 0, UnorderedSources.Default(count).Any()); }
public static void All_AggregateException() { AssertThrows.Wrapped <DeliberateTestException>(() => UnorderedSources.Default(1).All(x => { throw new DeliberateTestException(); })); }
public static void Any_AllTrue(int count) { Assert.Equal(count > 0, UnorderedSources.Default(count).Any(x => x >= 0)); }
public static void All_OneTrue(int count, int position) { Assert.False(UnorderedSources.Default(count).All(x => x == position)); }
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(); }