Ejemplo n.º 1
0
        public void Zip()
        {
            Spec.ForAny <List <int> >(ms =>
            {
                var xs = QueryExpr.Zip(ms, ms, (a, b) => a * b).Run();
                var ys = Enumerable.Zip(ms, ms, (a, b) => a * b);

                return(Enumerable.SequenceEqual(xs, ys));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 2
0
        public static void Main(/*string[] args*/)
        {
            Spec.ForAny <int[]>(xs => xs.Reverse().Reverse().SequenceEqual(xs))
            .QuickCheck("RevRev");

            Spec.ForAny <Color> (c => ((Color)((Color32)c)).Equals(c)).QuickCheck("Color -> Color32 -> Color");

            Spec.ForAny <int[]>(xs => xs.Reverse().SequenceEqual(xs))
            .QuickCheck("RevId");
        }
Ejemplo n.º 3
0
        public void WhereIndexed()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = xs.AsQueryExpr().Where((n, index) => index % 2 == 0).Run();
                var y = xs.Where((n, index) => index % 2 == 0);

                return(Enumerable.SequenceEqual(x, y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 4
0
 public void OfEnumerable()
 {
     Spec.ForAny <List <int> >(xs =>
     {
         IEnumerable <int> _xs = xs;
         var x = _xs.AsParStream().Select(i => i + 1).ToArray();
         var y = _xs.AsParallel().Select(i => i + 1).ToArray();
         return(new SortedSet <int>(x).SequenceEqual(new SortedSet <int>(y)));
     }).QuickCheckThrowOnFailure();
 }
Ejemplo n.º 5
0
 public void ToEnumerable()
 {
     Spec.ForAny <List <int> >(xs =>
     {
         IEnumerable <int> _xs = xs;
         var x = _xs.AsStream().Select(i => i + 1).ToEnumerable().Count();
         var y = _xs.Select(i => i + 1).Count();
         return(x == y);
     }).QuickCheckThrowOnFailure();
 }
Ejemplo n.º 6
0
 public void TestFluent()
 {
     Spec
     .ForAny((int n) => n + n == 2 * n)
     .Classify(x => x % 2 == 0, "even")
     .Classify(x => x % 2 != 0, "odd")
     .Classify(x => x < 0, "neg")
     .Classify(x => x >= 0, "pos")
     .Classify(x => Math.Abs(x) > 50, "large")
     .Check(Configuration);
 }
Ejemplo n.º 7
0
        public void Select()
        {
            Func <IEnumerable <object>, bool> f = xs => {
                var x = xs.AsQueryExpr().Select(n => n.ToString()).Run();
                var y = xs.Select(n => n.ToString());
                return(Enumerable.SequenceEqual(x, y));
            };

            Spec.ForAny <TestInput <object> >(xs =>
                                              TestInput <object> .RunTestFunc <object>(f, xs))
            .QuickCheckThrowOnFailure();
        }
Ejemplo n.º 8
0
        public void Aggregate()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = (from n in xs.AsQueryExpr()
                         select n * 2).Aggregate(0, (acc, value) => acc + value).Run();
                var y = (from n in xs
                         select n * 2).Aggregate(0, (acc, value) => acc + value);

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 9
0
        public void SumDouble()
        {
            Spec.ForAny <double[]>(xs =>
            {
                var x = (from n in xs.AsParallelQueryExpr()
                         select n * 2).Sum().Run();
                var y = (from n in xs.AsParallel()
                         select n * 2).Sum();

                return((Double.IsNaN(x) && Double.IsNaN(y)) || Math.Ceiling(x) == Math.Ceiling(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 10
0
        public void SumInt()
        {
            Spec.ForAny <int []>(xs =>
            {
                var x = (from n in xs.AsQueryExpr()
                         select n * 2).Sum().Run();
                var y = (from n in xs
                         select n * 2).Sum();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 11
0
        public void SumDouble()
        {
            Spec.ForAny <double[]>(xs =>
            {
                var x = (from n in xs.AsQueryExpr()
                         select n * 2).Sum().Run();
                var y = (from n in xs
                         select n * 2).Sum();

                return((Double.IsNaN(x) && Double.IsNaN(y)) || x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 12
0
        public void SumLong()
        {
            Spec.ForAny <long[]>(xs =>
            {
                var x = (from n in xs.AsParallelQueryExpr()
                         select n * 2).Sum().Run();
                var y = (from n in xs.AsParallel()
                         select n * 2).Sum();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 13
0
        public void SelectMany()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = xs.AsQueryExpr()
                        .SelectMany(n => xs.Where(_n => _n % 2 == 0).Select(_n => n * _n))
                        .Sum().Run();
                var y = xs.SelectMany(n => xs.Where(_n => _n % 2 == 0).Select(_n => n * _n))
                        .Sum();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 14
0
        public void SkipWhile()
        {
            Func <IEnumerable <int>, bool> f = xs =>
            {
                var x = xs.AsQueryExpr().SkipWhile(i => i < 10).Run();
                var y = xs.SkipWhile(i => i < 10);
                return(Enumerable.SequenceEqual(x, y));
            };

            Spec.ForAny <TestInput <int> >(xs =>
                                           TestInput <int> .RunTestFunc <int>(f, xs))
            .QuickCheckThrowOnFailure();
        }
Ejemplo n.º 15
0
        public void ForEach()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = new List <int>();
                xs.AsQueryExpr().ForEach(num => x.Add(num)).Run();

                var y = new List <int>();
                xs.ToList().ForEach(num => y.Add(num));

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 16
0
        public void NestedSelectManyTest()
        {
            Spec.ForAny <List <int> >(xs =>
            {
                var x = xs.AsQueryExpr()
                        .SelectMany(m => Enumerable.Repeat(m, Enumerable.Range(1, 10).Sum()).Select(i => i * i))
                        .Run();

                var y = xs
                        .SelectMany(m => Enumerable.Repeat(m, Enumerable.Range(1, 10).Sum()).Select(i => i * i));

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 17
0
        public void SelectManyCompehension()
        {
            Spec.ForAny <string[]>(xs =>
            {
                var x = (from num in xs.AsParallelQueryExpr()
                         from _num in xs
                         select num + " " + _num).Run();
                var y = (from num in xs.AsParallel().AsOrdered()
                         from _num in xs
                         select num + " " + _num);

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 18
0
        public void SelectManyNested()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = xs.AsQueryExpr()
                        .SelectMany(num => xs.SelectMany(_num => new[] { num *_num }))
                        .Sum().Run();
                var y = xs
                        .SelectMany(num => xs.SelectMany(_num => new[] { num *_num }))
                        .Sum();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 19
0
        public void ListSource()
        {
            Spec.ForAny <List <int> >(xs =>
            {
                var x = (from n in xs.AsQueryExpr()
                         select n * 2)
                        .Run();

                var y = (from n in xs
                         select n * 2);

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 20
0
        public void Detuple5()
        {
            Spec.ForAny <List <int> >(ms =>
            {
                var xs = ms.AsQueryExpr()
                         .Aggregate(Tuple.Create(0, 1), (t, _) => Tuple.Create(t.Item2, t.Item1 + t.Item2))
                         .Run();

                var ys = ms
                         .Aggregate(Tuple.Create(0, 1), (t, _) => Tuple.Create(t.Item2, t.Item1 + t.Item2));

                return(Tuple.Equals(xs, ys));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 21
0
        public void SkipN()
        {
            Spec.ForAny <int[], int>((xs, n) =>
            {
                var x = xs.AsQueryExpr()
                        .Skip(n)
                        .Run();

                var y = xs
                        .Skip(n);

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 22
0
        public void Where()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = (from n in xs.AsQueryExpr()
                         where n % 2 == 0
                         select n).Run();
                var y = from n in xs
                        where n % 2 == 0
                        select n;

                return(Enumerable.SequenceEqual(x, y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 23
0
        public void ToArray()
        {
            Spec.ForAny <List <int> >(xs =>
            {
                var x = xs.AsParallelQueryExpr()
                        .ToArray()
                        .Run();

                var y = xs.AsParallel()
                        .ToArray();

                return(x.OrderBy(i => i).SequenceEqual(y.OrderBy(i => i)));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 24
0
        public void ToArray()
        {
            Spec.ForAny <List <int> >(xs =>
            {
                var x = xs.AsQueryExpr()
                        .ToArray()
                        .Run();

                var y = xs
                        .ToArray();

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 25
0
 public void Select()
 {
     using (var context = new GpuContext(platformWildCard))
     {
         Spec.ForAny <int[]>(xs =>
         {
             using (var _xs = context.CreateGpuArray(xs))
             {
                 var x = context.Run(_xs.AsGpuQueryExpr().Select(n => n * 2).ToArray());
                 var y = xs.Select(n => n * 2).ToArray();
                 return(x.SequenceEqual(y));
             }
         }).QuickCheckThrowOnFailure();
     }
 }
Ejemplo n.º 26
0
        public void Detuple4()
        {
            Spec.ForAny <List <int> >(ms =>
            {
                var xs = ms.AsQueryExpr()
                         .Select(i => new Tuple <int, int>(i, i * 42))
                         .Where(m => m.Item1 % 2 == 0)
                         .Run();

                var ys = ms
                         .Select(i => new Tuple <int, int>(i, i * 42))
                         .Where(m => m.Item1 % 2 == 0);

                return(Enumerable.SequenceEqual(xs, ys));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 27
0
        public void ZipWithFilter()
        {
            using (var context = new GpuContext(platformWildCard))
            {
                Spec.ForAny <int[]>(ms =>
                {
                    using (var _ms = context.CreateGpuArray(ms))
                    {
                        var xs = context.Run(GpuQueryExpr.Zip(_ms, _ms, (a, b) => a * b).Where(x => x % 2 == 0).ToArray());
                        var ys = Enumerable.Zip(ms, ms, (a, b) => a * b).Where(x => x % 2 == 0).ToArray();

                        return(xs.SequenceEqual(ys));
                    }
                }).QuickCheckThrowOnFailure();
            }
        }
Ejemplo n.º 28
0
        public void OrderByDescending()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = (from num in xs.AsParallelQueryExpr()
                         orderby num descending
                         select num * 2)
                        .Run();

                var y = from num in xs.AsParallel()
                        orderby num descending
                        select num * 2;

                return(x.SequenceEqual(y));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 29
0
        public void Detuple6()
        {
            Spec.ForAny <List <int> >(ms =>
            {
                var xs = ms.AsQueryExpr()
                         .Select(x1 => Tuple.Create(x1 * x1, Tuple.Create(x1, -x1)))
                         .Where(t1 => t1.Item2.Item1 == -t1.Item2.Item2)
                         .Run();

                var ys = ms
                         .Select(x2 => Tuple.Create(x2 * x2, Tuple.Create(x2, -x2)))
                         .Where(t2 => t2.Item2.Item1 == -t2.Item2.Item2);

                return(Enumerable.SequenceEqual(xs, ys));
            }).QuickCheckThrowOnFailure();
        }
Ejemplo n.º 30
0
        public void Count()
        {
            Spec.ForAny <int[]>(xs =>
            {
                var x = xs.AsParallelQueryExpr()
                        .Select(i => i)
                        .Count()
                        .Run();

                var y = xs.AsParallel()
                        .Select(i => i)
                        .Count();

                return(x == y);
            }).QuickCheckThrowOnFailure();
        }