コード例 #1
0
ファイル: ExceptTests.cs プロジェクト: karthikrajkumar/demo
        public static void Except_SourceMultiple(ParallelQuery <int> leftQuery, int leftCount, ParallelQuery <int> rightQuery, int rightCount, int start, int count)
        {
            int seen = start;

            Assert.All(leftQuery.Except(rightQuery), x => Assert.Equal(seen++, x));
            Assert.Equal(start + count, seen);
        }
コード例 #2
0
ファイル: ExceptTests.cs プロジェクト: karthikrajkumar/demo
        public static void Except_NotPipelined(Labeled <ParallelQuery <int> > left, int leftCount, ParallelQuery <int> rightQuery, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery = left.Item;
            int seen = start;

            Assert.All(leftQuery.Except(rightQuery).ToList(), x => Assert.Equal(seen++, x));
            Assert.Equal(count + start, seen);
        }
コード例 #3
0
ファイル: ExceptTests.cs プロジェクト: layomia/dotnet_runtime
        public static void Except_Unordered_NotPipelined(int leftCount, int rightStart, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightStart, rightCount);
            IntegerRangeSet     seen       = new IntegerRangeSet(start, count);

            Assert.All(leftQuery.Except(rightQuery).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
コード例 #4
0
ファイル: ExceptTests.cs プロジェクト: viniciustaveira/corefx
        public static void Except_Unordered_NotPipelined(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            IntegerRangeSet     seen       = new IntegerRangeSet(start, count);

            Assert.All(leftQuery.Except(rightQuery).ToList(), x => seen.Add(x));
            seen.AssertComplete();
        }
コード例 #5
0
ファイル: ExceptTests.cs プロジェクト: karthikrajkumar/demo
        public static void Except(Labeled <ParallelQuery <int> > left, int leftCount, ParallelQuery <int> rightQuery, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery = left.Item;
            int seen = start;

            foreach (int i in leftQuery.Except(rightQuery))
            {
                Assert.Equal(seen++, i);
            }
            Assert.Equal(count + start, seen);
        }
コード例 #6
0
ファイル: ExceptTests.cs プロジェクト: layomia/dotnet_runtime
        public static void Except_Unordered(int leftCount, int rightStart, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightStart, rightCount);
            IntegerRangeSet     seen       = new IntegerRangeSet(start, count);

            foreach (int i in leftQuery.Except(rightQuery))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
コード例 #7
0
ファイル: ExceptTests.cs プロジェクト: viniciustaveira/corefx
        public static void Except_Unordered(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;
            IntegerRangeSet     seen       = new IntegerRangeSet(start, count);

            foreach (int i in leftQuery.Except(rightQuery))
            {
                seen.Add(i);
            }
            seen.AssertComplete();
        }
コード例 #8
0
ファイル: ExceptTests.cs プロジェクト: karthikrajkumar/demo
        public static void Except_Distinct_NotPipelined(Labeled <ParallelQuery <int> > left, int leftCount, ParallelQuery <int> rightQuery, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery = left.Item;

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            int expectedCount = Math.Max(0, leftCount - rightCount);
            int seen          = expectedCount == 0 ? 0 : leftCount - expectedCount;

            Assert.All(leftQuery.Except(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor),
                                        new ModularCongruenceComparer(DuplicateFactor * 2)).ToList(), x => Assert.Equal(seen++, x));
            Assert.Equal(expectedCount == 0 ? 0 : leftCount, seen);
        }
コード例 #9
0
        internal static ParallelQuery <int> MakeExcept(bool orderPreserved)
        {
            int[] a = Enumerable.Range(-5, 110).ToArray();
            int[] b = { -100, -50, -5, -4, -3, -2, -1, 101, 102, 103, 104, 105, 106, 180 };

            ParallelQuery <int> ipe = a.AsParallel();

            if (orderPreserved)
            {
                ipe = ipe.AsOrdered();
            }

            return(ipe.Except(b.AsParallel()));
        }
コード例 #10
0
ファイル: ExceptTests.cs プロジェクト: karthikrajkumar/demo
        public static void Except_Unordered_Distinct_NotPipelined(int leftCount, int rightStart, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = UnorderedSources.Default(leftCount);
            ParallelQuery <int> rightQuery = UnorderedSources.Default(rightStart, rightCount);

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            int             expectedCount = Math.Max(0, leftCount - rightCount);
            IntegerRangeSet seen          = new IntegerRangeSet(leftCount - expectedCount, expectedCount);

            Assert.All(leftQuery.Except(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor),
                                        new ModularCongruenceComparer(DuplicateFactor * 2)).ToList(), x => seen.Add(x % (DuplicateFactor * 2)));
            seen.AssertComplete();
        }
コード例 #11
0
ファイル: ExceptTests.cs プロジェクト: viniciustaveira/corefx
        public static void Except_Distinct(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            int expectedCount = Math.Max(0, leftCount - rightCount);
            int seen          = expectedCount == 0 ? 0 : leftCount - expectedCount;

            foreach (int i in leftQuery.Except(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor), new ModularCongruenceComparer(DuplicateFactor * 2)))
            {
                Assert.Equal(seen++, i);
            }
            Assert.Equal(expectedCount == 0 ? 0 : leftCount, seen);
        }
コード例 #12
0
ファイル: ExceptTests.cs プロジェクト: viniciustaveira/corefx
        public static void Except_Unordered_Distinct(Labeled <ParallelQuery <int> > left, int leftCount, Labeled <ParallelQuery <int> > right, int rightCount, int start, int count)
        {
            ParallelQuery <int> leftQuery  = left.Item;
            ParallelQuery <int> rightQuery = right.Item;

            leftCount  = Math.Min(DuplicateFactor * 2, leftCount);
            rightCount = Math.Min(DuplicateFactor, (rightCount + 1) / 2);
            int             expectedCount = Math.Max(0, leftCount - rightCount);
            IntegerRangeSet seen          = new IntegerRangeSet(leftCount - expectedCount, expectedCount);

            foreach (int i in leftQuery.Except(rightQuery.Select(x => Math.Abs(x) % DuplicateFactor), new ModularCongruenceComparer(DuplicateFactor * 2)))
            {
                seen.Add(i % (DuplicateFactor * 2));
            }
            seen.AssertComplete();
        }
コード例 #13
0
        private static void RunAllTests(
            TestTracker result, ParallelQuery <int> q, bool orderPreserved,
            string leftOpName, bool leftOrderDefined)
        {
            LogTestRun(leftOpName, "All1", orderPreserved);
            result.MustEqual(
                q.All(i => i > 100),
                q.ToArray().Any(i => i > 100));

            LogTestRun(leftOpName, "All2", orderPreserved);
            result.MustEqual(
                q.All(i => i == 75),
                q.ToArray().All(i => i == 75));

            LogTestRun(leftOpName, "Any1", orderPreserved);
            result.MustEqual(
                q.Any(i => i > 100),
                q.ToArray().Any(i => i > 100));

            LogTestRun(leftOpName, "Any2", orderPreserved);
            result.MustEqual(
                q.Any(i => i == 75),
                q.ToArray().Any(i => i == 75));

            LogTestRun(leftOpName, "Concat", orderPreserved);
            result.MustSequenceEqual(
                q.Concat(q).Concat(new int[] { 1, 2, 3 }.AsParallel()),
                q.Reverse().Reverse().ToArray().Concat(q.Reverse().Reverse()).Concat(new int[] { 1, 2, 3 }),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "DefaultIfEmpty", orderPreserved);
            result.MustSequenceEqual(
                q.DefaultIfEmpty(),
                q.ToArray().DefaultIfEmpty(), orderPreserved && leftOrderDefined);

            LogTestRun(leftOpName, "ElementAt", orderPreserved);
            IEnumerable <int> q2 = q.ToArray();
            int        count1 = q.Count(), count2 = q2.Count();
            List <int> list1 = new List <int>();
            List <int> list2 = new List <int>();

            for (int i = 0; i < count1; i++)
            {
                list1.Add(q.ElementAt(i));
            }
            for (int i = 0; i < count2; i++)
            {
                list2.Add(q2.ElementAt(i));
            }
            result.MustSequenceEqual(list1, list2, leftOrderDefined);

            LogTestRun(leftOpName, "Except", orderPreserved);
            result.MustSequenceEqual(
                q.Except(Enumerable.Range(90, 50).AsParallel()),
                q.ToArray().Except(Enumerable.Range(90, 50)),
                false);

            LogTestRun(leftOpName, "First", orderPreserved);
            CheckFirstOrLast(
                result,
                q.First(),
                q.ToArray().First(),
                leftOrderDefined);

            LogTestRun(leftOpName, "GroupBy", orderPreserved);
            result.MustGroupByEqual(
                q.GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e)),
                q.ToArray().GroupBy(i => i % 5, (i, e) => new Pair <int, IEnumerable <int> >(i, e)));

            LogTestRun(leftOpName, "GroupJoin", orderPreserved);
            result.MustSequenceEqual(
                q.GroupJoin(q, i => i, i => i, (i, e) => e.FirstOrDefault()),
                q.ToArray().GroupJoin(q.ToArray(), i => i, i => i, (i, e) => e.FirstOrDefault()),
                false);

            LogTestRun(leftOpName, "Intersect", orderPreserved);
            result.MustSequenceEqual(
                q.Intersect(Enumerable.Range(90, 50).AsParallel()),
                q.ToArray().Intersect(Enumerable.Range(90, 50)),
                false);

            LogTestRun(leftOpName, "Join1", orderPreserved);
            result.MustSequenceEqual(
                q.Join((new int[] { 1, 1, 2, 3, 3 }).AsParallel(), i => i, i => i, (i, j) => i + j),
                q.ToArray().Join(new int[] { 1, 1, 2, 3, 3 }, i => i, i => i, (i, j) => i + j),
                false);

            LogTestRun(leftOpName, "Join2", orderPreserved);
            result.MustSequenceEqual(
                q.Join((new int[] { 1, 1, 100, 3, 3 }).AsParallel(), i => new String('a', i), i => new String('a', i), (i, j) => i + j),
                q.ToArray().Join(new int[] { 1, 1, 100, 3, 3 }, i => new String('a', i), i => new String('a', i), (i, j) => i + j),
                false);

            LogTestRun(leftOpName, "Last", orderPreserved);
            CheckFirstOrLast(
                result,
                q.Last(),
                q.ToArray().Last(),
                leftOrderDefined);

            LogTestRun(leftOpName, "Min", orderPreserved);
            CheckFirstOrLast(
                result,
                q.Min(),
                q.ToArray().Min(),
                leftOrderDefined);

            LogTestRun(leftOpName, "Max", orderPreserved);
            CheckFirstOrLast(
                result,
                q.Min(),
                q.ToArray().Min(),
                leftOrderDefined);

            LogTestRun(leftOpName, "OrderBy-ThenBy", orderPreserved);
            result.MustSequenceEqual(
                q.Concat(q).OrderBy(i => i % 5).ThenBy(i => - i),
                q.ToArray().Concat(q).OrderBy(i => i % 5).ThenBy(i => - i),
                true);

            LogTestRun(leftOpName, "OrderByDescending-ThenByDescending", orderPreserved);
            result.MustSequenceEqual(
                q.Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i),
                q.ToArray().Concat(q).OrderByDescending(i => i % 5).ThenByDescending(i => - i),
                true);

            LogTestRun(leftOpName, "Reverse", orderPreserved);
            result.MustSequenceEqual(
                q.Concat(q).Reverse(),
                q.ToArray().Concat(q).Reverse(),
                orderPreserved && leftOrderDefined);

            LogTestRun(leftOpName, "Select", orderPreserved);
            result.MustSequenceEqual(
                q.Select(i => 5 * i - 17),
                q.ToArray().Select(i => 5 * i - 17),
                orderPreserved && leftOrderDefined);

            LogTestRun(leftOpName, "SelectMany", orderPreserved);
            result.MustSequenceEqual(
                q.SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j),
                q.ToArray().SelectMany(i => new int[] { 1, 2, 3 }, (i, j) => i + 100 * j),
                false);

            LogTestRun(leftOpName, "SequenceEqual", orderPreserved);
            if (orderPreserved && leftOrderDefined)
            {
                result.MustEqual(q.SequenceEqual(q), true);
            }
            else
            {
                // We don't check the return value as it can be either true or false
                q.SequenceEqual(q);
            }

            LogTestRun(leftOpName, "Skip", orderPreserved);
            CheckTakeSkip(
                result,
                q.Skip(10),
                q.ToArray().Skip(10),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "SkipWhile", orderPreserved);
            CheckTakeSkip(
                result,
                q.SkipWhile(i => i < 30),
                q.ToArray().SkipWhile(i => i < 30),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "SkipWhileIndexed", orderPreserved);
            CheckTakeSkip(
                result,
                q.SkipWhile((i, j) => j < 30),
                q.ToArray().SkipWhile((i, j) => j < 30),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "Take", orderPreserved);
            CheckTakeSkip(
                result,
                q.Take(10),
                q.ToArray().Take(10),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "TakeWhile", orderPreserved);
            CheckTakeSkip(
                result,
                q.TakeWhile(i => i < 30),
                q.ToArray().TakeWhile(i => i < 30),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "TakeWhileIndexed", orderPreserved);
            CheckTakeSkip(
                result,
                q.TakeWhile((i, j) => j < 30),
                q.ToArray().TakeWhile((i, j) => j < 30),
                leftOrderDefined && orderPreserved);

            LogTestRun(leftOpName, "Union", orderPreserved);
            result.MustSequenceEqual(
                q.Union(Enumerable.Range(90, 50).AsParallel()),
                q.ToArray().Union(Enumerable.Range(90, 50)),
                false);

            LogTestRun(leftOpName, "Where", orderPreserved);
            result.MustSequenceEqual(
                q.Where(i => i < 20 || i > 80),
                q.ToArray().Where(i => i < 20 || i > 80),
                orderPreserved && leftOrderDefined);

            LogTestRun(leftOpName, "Zip", orderPreserved);
            IEnumerable <KeyValuePair <int, int> > zipQ = q.Zip(q, (i, j) => new KeyValuePair <int, int>(i, j));

            result.MustSequenceEqual(
                zipQ.Select(p => p.Key),
                q.Reverse().Reverse().ToArray(),
                orderPreserved && leftOrderDefined);
            result.MustSequenceEqual(
                zipQ.Select(p => p.Value),
                q.Reverse().Reverse().ToArray(),
                orderPreserved && leftOrderDefined);
        }
コード例 #14
0
ファイル: ExceptTests.cs プロジェクト: noahfalk/corefx
 public static void Except_SourceMultiple(ParallelQuery<int> leftQuery, int leftCount, ParallelQuery<int> rightQuery, int rightCount, int start, int count)
 {
     int seen = start;
     Assert.All(leftQuery.Except(rightQuery), x => Assert.Equal(seen++, x));
     Assert.Equal(start + count, seen);
 }
コード例 #15
0
 /// <summary>
 /// Produces the set difference of two sequences by using the specified comparison function
 /// to compare values.
 /// </summary>
 /// <typeparam name="TLexical">
 /// The type of the elements of the input sequences. Any Type which implements the ILexical
 /// interface is applicable.
 /// </typeparam>
 /// <param name="first">
 /// A sequence whose elements that are not also in second will be returned.
 /// </param>
 /// <param name="second">
 /// A sequence whose elements that also occur in the first sequence will cause those
 /// elements to be removed from the returned sequence.
 /// </param>
 /// <param name="equate">
 /// A function to compare two instances of type TLexical and return true or false.
 /// </param>
 /// <returns>A sequence that contains the set difference of the elements of two sequences.</returns>
 public static ParallelQuery <TLexical> Except <TLexical>(this ParallelQuery <TLexical> first, ParallelQuery <TLexical> second, Func <TLexical, TLexical, bool> equate)
     where TLexical : ILexical => first.Except(second, Equality.Create(equate));