Exemple #1
0
        public static void Zip_Unordered(int leftCount, int rightCount)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(leftCount, rightCount);
            IntegerRangeSet     seen_left  = new IntegerRangeSet(0, leftCount);
            IntegerRangeSet     seen_right = new IntegerRangeSet(leftCount, rightCount);
            var expected_seen = Math.Min(leftCount, rightCount);

            foreach (var pair in leftQuery.Zip(rightQuery, (x, y) => KeyValuePair.Create(x, y)))
            {
                // Can only validate about whether the elements have been previously seen, not anything about the order.
                seen_left.Add(pair.Key);
                seen_right.Add(pair.Value);
            }

            // Zip truncates the longer collection, but which elements it leaves off is undefined when unordered.
            Assert.Equal(expected_seen, seen_left.Count(kv => kv.Value));
            Assert.Equal(expected_seen, seen_right.Count(kv => kv.Value));
            if (leftCount <= rightCount)
            {
                seen_left.AssertComplete();
            }
            if (rightCount <= leftCount)
            {
                seen_right.AssertComplete();
            }
        }