public static IEnumerable <object[]> SumData(int[] counts) { foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), x => Functions.SumRange(0L, x))) { yield return(results); } }
public static IEnumerable <object[]> DistinctUnorderedData(int[] counts) { foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>().Select(x => x * DuplicateFactor))) { yield return(new object[] { results[0], ((int)results[1]) / DuplicateFactor }); } }
// If ThreadPool becomes available, uncomment the below //private static ThreadPoolManager _poolManager = new ThreadPoolManager(); public static IEnumerable <object[]> DegreeData(int[] counts, int[] degrees) { foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), x => degrees.Cast <int>().DefaultIfEmpty(x))) { yield return(results); } }
public static IEnumerable <object[]> Ranges(int start, IEnumerable <int> counts) { foreach (object[] parms in UnorderedSources.Ranges(start, counts)) { yield return(new object[] { ((Labeled <ParallelQuery <int> >)parms[0]).Order(), parms[1] }); } }
public static IEnumerable <object[]> ElementAtUnorderedData(int[] counts) { // A deliberate decision was made here to test with all types, because this reflects partitioning/indexing foreach (object[] results in UnorderedSources.Ranges(counts.DefaultIfEmpty(Sources.OuterLoopCount), Positions)) { yield return(results); } }
public static IEnumerable <object[]> Ranges <T>(IEnumerable <int> counts, params Func <int, IEnumerable <T> >[] modifiers) { foreach (object[] parms in UnorderedSources.Ranges(counts, modifiers)) { parms[0] = ((Labeled <ParallelQuery <int> >)parms[0]).Order(); yield return(parms); } }
// // Take // public static IEnumerable <object[]> TakeUnorderedData(int[] counts) { Func <int, IEnumerable <int> > take = x => new[] { -x, -1, 0, 1, x / 2, x, x * 2 }.Distinct(); foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), take)) { yield return(results); } }
public static IEnumerable <object[]> ElementAtOutOfRangeData(int[] counts) { Func <int, IEnumerable <int> > positions = x => new[] { -1, x, x * 2 }.Distinct(); foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), positions)) { yield return(results); } }
public static IEnumerable <object[]> OnlyOneData(int[] counts) { Func <int, IEnumerable <int> > positions = x => new[] { 0, x / 2, Math.Max(0, x - 1) }.Distinct(); foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), positions)) { yield return(results); } }
// // Average // // Get a set of ranges from 0 to each count, with an extra parameter containing the expected average. public static IEnumerable <object[]> AverageData(int[] counts) { Func <int, double> average = x => (x - 1) / 2.0; foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), average)) { yield return(results); } }
// 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) { Func <int, int> max = x => x - 1; foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), max)) { yield return(results); } }
public static IEnumerable <object[]> ElementAtOutOfRangeData(int[] counts) { foreach (object[] results in UnorderedSources.Ranges(counts.DefaultIfEmpty(Sources.OuterLoopCount), InvalidPositions)) { yield return(results); } foreach (object[] results in Sources.Ranges(counts.DefaultIfEmpty(Sources.OuterLoopCount), InvalidPositions)) { yield return(results); } }
public static IEnumerable <object[]> EmptyData() { foreach (object[] query in UnorderedSources.Ranges(new[] { 0 })) { yield return(new object[] { query[0], 1 }); } yield return(new object[] { Labeled.Label("Empty-Int", ParallelEnumerable.Empty <int>()), 1 }); yield return(new object[] { Labeled.Label("Empty-Decimal", ParallelEnumerable.Empty <decimal>()), 1.5M }); yield return(new object[] { Labeled.Label("Empty-String", ParallelEnumerable.Empty <string>()), "default" }); }
// // SelectMany // public static IEnumerable <object[]> SelectManyUnorderedData(int[] counts) { foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>())) { foreach (Labeled <Func <int, int, IEnumerable <int> > > expander in Expanders()) { foreach (int count in new[] { 0, 1, 2, 8 }) { yield return(new object[] { results[0], results[1], expander, count }); } } } }
/// <summary> /// Run through all sources, ensuring 64k elements for each core (to saturate buffers in producers/consumers). /// </summary> /// Data returned is in the format of the underlying sources. /// <returns>Rows of sourced data to check.</returns> public static IEnumerable <object[]> ProducerBlocked_Data() { // Provide enough elements to ensure all the cores get >64K ints. int elements = 64 * 1024 * Environment.ProcessorCount; foreach (object[] data in Sources.Ranges(new[] { elements })) { yield return(data); } foreach (object[] data in UnorderedSources.Ranges(new[] { elements })) { yield return(data); } }
public static IEnumerable <object[]> SingleData(int[] elements, int[] counts) { foreach (int element in elements) { foreach (object[] results in UnorderedSources.Ranges(element, counts.Cast <int>())) { yield return(new object[] { results[0], results[1], element }); } foreach (object[] results in Sources.Ranges(element, counts.Cast <int>())) { yield return(new object[] { results[0], results[1], element }); } } }
public static IEnumerable <object[]> AggregateExceptionData(int[] counts) { foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>())) { Labeled <ParallelQuery <int> > query = (Labeled <ParallelQuery <int> >)results[0]; if (query.ToString().StartsWith("Partitioner")) { yield return(new object[] { Labeled.Label(query.ToString(), Partitioner.Create(UnorderedSources.GetRangeArray(0, (int)results[1]), false).AsParallel()), results[1] }); } else if (query.ToString().StartsWith("Enumerable.Range")) { yield return(new object[] { Labeled.Label(query.ToString(), new StrictPartitioner <int>(Partitioner.Create(Enumerable.Range(0, (int)results[1]), EnumerablePartitionerOptions.None), (int)results[1]).AsParallel()), results[1] }); } else { yield return(results); } } }
// 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) { Func <int, int> max = x => x - 1; foreach (object[] results in UnorderedSources.Ranges(counts.Cast <int>(), max)) { yield return(results); } // 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[] { new Labeled <ParallelQuery <int> >("Out-of-order input", data.AsParallel()), count, max(count) }); } }
public static IEnumerable<object[]> LastUnorderedData(int[] counts) { Func<int, IEnumerable<int>> positions = x => new[] { 1, x / 2 + 1, Math.Max(1, x - 1) }.Distinct(); foreach (object[] results in UnorderedSources.Ranges(counts.Cast<int>(), positions)) yield return results; }