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(); }
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"); }
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(); }
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(); }
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(); }
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); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
public void ToArray() { Spec.ForAny <List <int> >(xs => { var x = xs.AsQueryExpr() .ToArray() .Run(); var y = xs .ToArray(); return(x.SequenceEqual(y)); }).QuickCheckThrowOnFailure(); }
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(); } }
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(); }
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(); } }
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(); }
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(); }
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(); }