From 4c4c2aaa97d0b25e9a3aecfc09e6d2e36e39e04b Mon Sep 17 00:00:00 2001 From: Anthony Lloyd Date: Fri, 13 Oct 2023 21:50:32 +0100 Subject: [PATCH] move remove Create --- CsCheck/Check.cs | 22 +- CsCheck/Gen.cs | 1378 +++++++++++++++--------------- Tests/CheckTests.cs | 2 +- Tests/GenTests.cs | 88 +- Tests/IMToolsTests.cs | 8 +- Tests/ModelTests.cs | 2 +- Tests/PCGTests.cs | 14 +- Tests/ShrinkingChallengeTests.cs | 12 +- Tests/SlimCollectionsTests.cs | 12 +- 9 files changed, 751 insertions(+), 787 deletions(-) diff --git a/CsCheck/Check.cs b/CsCheck/Check.cs index 3cc3fcc..04a45d8 100644 --- a/CsCheck/Check.cs +++ b/CsCheck/Check.cs @@ -1476,31 +1476,31 @@ public static void SampleMetamorphic(this Gen initial, GenMetamorphic o { try { - d.V1.Item2(d.V0.State1); - d.V1.Item3(d.V0.State2); - return equal(d.V0.State1, d.V0.State2); + d.Item2.Item2(d.Item1.State1); + d.Item2.Item3(d.Item1.State2); + return equal(d.Item1.State1, d.Item1.State2); } catch (Exception e) { - d.V0.Exception = e; + d.Item1.Exception = e; return false; } }, seed, iter, time, threads, p => { - if (p.V0 == null) return ""; + if (p.Item1 is null) return ""; var sb = new StringBuilder(); - var initialState = initial.Generate(new PCG(p.V0.Stream, p.V0.Seed), null, out _); + var initialState = initial.Generate(new PCG(p.Item1.Stream, p.Item1.Seed), null, out _); sb.Append("\nInitial State: ").Append(print(initialState)); - sb.Append("\n Operations: ").Append(p.V1.Item1); - if (p.V0.Exception is null) + sb.Append("\n Operations: ").Append(p.Item2.Item1); + if (p.Item1.Exception is null) { - sb.Append("\nFinal State 1: ").Append(print(p.V0.State1)); - sb.Append("\nFinal State 2: ").Append(print(p.V0.State2)); + sb.Append("\nFinal State 1: ").Append(print(p.Item1.State1)); + sb.Append("\nFinal State 2: ").Append(print(p.Item1.State2)); } else { - sb.Append("\n Exception: ").Append(p.V0.Exception.ToString()); + sb.Append("\n Exception: ").Append(p.Item1.Exception.ToString()); } return sb.ToString(); }); diff --git a/CsCheck/Gen.cs b/CsCheck/Gen.cs index b824554..c435630 100644 --- a/CsCheck/Gen.cs +++ b/CsCheck/Gen.cs @@ -18,6 +18,7 @@ namespace CsCheck; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; +using System.Xml.Schema; /// Size representation of Gen generated data. public sealed class Size @@ -126,7 +127,7 @@ public GenOperation Operation(Action(PCG pcg, Size? min, out Size size); -public delegate T GenMap(T pcg, ref Size size); +public delegate T GenMap(T v, ref Size size); /// Provides a set of static methods for composing generators. public static class Gen @@ -180,7 +181,7 @@ public override R Generate(PCG pcg, Size? min, out Size size) public static Gen Select(this Gen gen, Func selector) => new GenSelect(gen, selector); - sealed class GenSelect(Gen<(T1, T2)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2)> gen, Func selector) : Gen { private readonly Gen<(T1, T2)> gen = gen; private readonly Func selector = selector; @@ -193,9 +194,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3)> gen = gen; private readonly Func selector = selector; @@ -208,9 +209,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3, T4)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3, T4)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3, T4)> gen = gen; private readonly Func selector = selector; @@ -223,9 +224,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3, T4)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3, T4, T5)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3, T4, T5)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3, T4, T5)> gen = gen; private readonly Func selector = selector; @@ -238,9 +239,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3, T4, T5)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3, T4, T5, T6)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3, T4, T5, T6)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3, T4, T5, T6)> gen = gen; private readonly Func selector = selector; @@ -253,9 +254,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3, T4, T5, T6)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3, T4, T5, T6, T7)> gen = gen; private readonly Func selector = selector; @@ -268,9 +269,9 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); - sealed class GenSelect(Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func selector) : Gen + sealed class GenSelectTuple(Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func selector) : Gen { private readonly Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen = gen; private readonly Func selector = selector; @@ -283,588 +284,417 @@ public override R Generate(PCG pcg, Size? min, out Size size) } /// Projects each element of a generator into a new form. public static Gen Select(this Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func selector) - => new GenSelect(gen, selector); + => new GenSelectTuple(gen, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2); + } + } /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2); - }); + public static Gen Select(this Gen gen1, Gen gen2, Func selector) + => new GenSelect(gen1, gen2, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2, v3); + } + } /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3); - }); + public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Func selector) + => new GenSelect(gen1, gen2, gen3, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Gen gen4, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2, v3, v4); + } + } /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4); - }); + public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, Func selector) + => new GenSelect(gen1, gen2, gen3, gen4, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + if (Size.IsLessThan(min, size)) return default!; + size.Add(s); + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2, v3, v4, v5); + } + } /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, - Gen gen5, Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - if (Size.IsLessThan(min, size)) return default!; - size.Add(s); - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5); - }); + public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, Gen gen5, Func selector) + => new GenSelect(gen1, gen2, gen3, gen4, gen5, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v6 = gen6.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var (a, b, c, d, e, f, g, h, i) = (1, 2, 3, 4, 5, 6, 7, 8, 9); + return selector(v1, v2, v3, v4, v5, v6); + } + } /// Projects each element of a generator into a new form. public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, - Gen gen5, Gen gen6, Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6); - }); + Gen gen5, Gen gen6, Func selector) + => new GenSelect(gen1, gen2, gen3, gen4, gen5, gen6, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6, Gen gen7, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + private readonly Gen gen7 = gen7; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v6 = gen6.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v7 = gen7.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2, v3, v4, v5, v6, v7); + } + } /// Projects each element of a generator into a new form. public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, - Gen gen5, Gen gen6, Gen gen7, Func selector) => - Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7); - }); + Gen gen5, Gen gen6, Gen gen7, Func selector) + => new GenSelect(gen1, gen2, gen3, gen4, gen5, gen6, gen7, selector); + sealed class GenSelect(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6, Gen gen7, Gen gen8, Func selector) : Gen + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + private readonly Gen gen7 = gen7; + private readonly Gen gen8 = gen8; + private readonly Func selector = selector; + public override R Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v6 = gen6.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v7 = gen7.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v8 = gen8.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + return selector(v1, v2, v3, v4, v5, v6, v7, v8); + } + } /// Projects each element of a generator into a new form. public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Func selector) - => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4, - Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, - Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, - Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, Gen gen11, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, Gen gen2, Gen gen3, - Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, Gen gen11, Gen gen12, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v12 = gen12.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, - Gen gen2, Gen gen3, Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, - Gen gen11, Gen gen12, Gen gen13, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v12 = gen12.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v13 = gen13.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, - Gen gen2, Gen gen3, Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, - Gen gen11, Gen gen12, Gen gen13, Gen gen14, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v12 = gen12.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v13 = gen13.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v14 = gen14.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14); - }); - - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, - Gen gen2, Gen gen3, Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, - Gen gen11, Gen gen12, Gen gen13, Gen gen14, Gen gen15, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v12 = gen12.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v13 = gen13.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v14 = gen14.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v15 = gen15.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15); - }); + => new GenSelect(gen1, gen2, gen3, gen4, gen5, gen6, gen7, gen8, selector); - /// Projects each element of a generator into a new form. - public static Gen Select(this Gen gen1, - Gen gen2, Gen gen3, Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8, Gen gen9, Gen gen10, - Gen gen11, Gen gen12, Gen gen13, Gen gen14, Gen gen15, Gen gen16, - Func selector) => Create((PCG pcg, Size? min, out Size size) => - { - var v1 = gen1.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v5 = gen5.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v6 = gen6.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v7 = gen7.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v8 = gen8.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v9 = gen9.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v10 = gen10.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v11 = gen11.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v12 = gen12.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v13 = gen13.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v14 = gen14.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v15 = gen15.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v16 = gen16.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - return selector(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16); - }); - - /// Projects each element of a generator into a tuple. - public static Gen<(T0 V0, T1 V1)> Select(this Gen gen0, Gen gen1) => Create((PCG pcg, Size? min, out Size size) => + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2) : Gen<(T1, T2)> { - var v0 = gen0.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v1 = gen1.Generate(pcg, min, out var s); - size.Add(s); - return (v0, v1); - }); + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + public override (T1, T2) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + return (v1, v2); + } + } + /// Projects each element of a generator into a tuple. + public static Gen<(T1, T2)> Select(this Gen gen1, Gen gen2) + => new GenSelectTupleCreate(gen1, gen2); + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3) : Gen<(T1, T2, T3)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + public override (T1, T2, T3) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + return (v1, v2, v3); + } + } /// Projects each element of a generator into a tuple. - public static Gen<(T0 V0, T1 V1, T2 V2)> Select(this Gen gen0, Gen gen1, Gen gen2) - => Create((PCG pcg, Size? min, out Size size) => - { - var v0 = gen0.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v1 = gen1.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out s); - size.Add(s); - return (v0, v1, v2); - }); + public static Gen<(T1, T2, T3)> Select(this Gen gen1, Gen gen2, Gen gen3) + => new GenSelectTupleCreate(gen1, gen2, gen3); + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3, Gen gen4) : Gen<(T1, T2, T3, T4)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + public override (T1, T2, T3, T4) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + return (v1, v2, v3, v4); + } + } /// Projects each element of a generator into a tuple. - public static Gen<(T0 V0, T1 V1, T2 V2, T3 V3)> Select(this Gen gen0, Gen gen1, - Gen gen2, Gen gen3) => Create((PCG pcg, Size? min, out Size size) => - { - var v0 = gen0.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v1 = gen1.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - return (v0, v1, v2, v3); - }); + public static Gen<(T1, T2, T3, T4)> Select(this Gen gen1, Gen gen2, Gen gen3, Gen gen4) + => new GenSelectTupleCreate(gen1, gen2, gen3, gen4); + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5) : Gen<(T1, T2, T3, T4, T5)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + public override (T1, T2, T3, T4, T5) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + return (v1, v2, v3, v4, v5); + } + } /// Projects each element of a generator into a tuple. - public static Gen<(T0 V0, T1 V1, T2 V2, T3 V3, T4 V4)> Select(this Gen gen0, Gen gen1, - Gen gen2, Gen gen3, Gen gen4) => Create((PCG pcg, Size? min, out Size size) => - { - var v0 = gen0.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - var v1 = gen1.Generate(pcg, min, out var s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v3 = gen3.Generate(pcg, min, out s); - size.Add(s); - if (Size.IsLessThan(min, size)) return default!; - var v4 = gen4.Generate(pcg, min, out s); - size.Add(s); - return (v0, v1, v2, v3, v4); - }); + public static Gen<(T1, T2, T3, T4, T5)> Select(this Gen gen1, Gen gen2, Gen gen3, + Gen gen4, Gen gen5) + => new GenSelectTupleCreate(gen1, gen2, gen3, gen4, gen5); + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6) : Gen<(T1, T2, T3, T4, T5, T6)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + public override (T1, T2, T3, T4, T5, T6) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v6 = gen6.Generate(pcg, min, out s); + size.Add(s); + return (v1, v2, v3, v4, v5, v6); + } + } /// Projects each element of a generator into a tuple. - public static Gen<(T0 V0, T1 V1, T2 V2, T3 V3, T4 V4, T5 V5)> Select(this Gen gen0, Gen gen1, - Gen gen2, Gen gen3, Gen gen4, Gen gen5) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3, T4, T5, T6)> Select(this Gen gen1, Gen gen2, Gen gen3, + Gen gen4, Gen gen5, Gen gen6) + => new GenSelectTupleCreate(gen1, gen2, gen3, gen4, gen5, gen6); + + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6, Gen gen7) : Gen<(T1, T2, T3, T4, T5, T6, T7)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + private readonly Gen gen7 = gen7; + public override (T1, T2, T3, T4, T5, T6, T7) Generate(PCG pcg, Size? min, out Size size) { - var v0 = gen0.Generate(pcg, min, out size); + var v1 = gen1.Generate(pcg, min, out size); if (Size.IsLessThan(min, size)) return default!; - var v1 = gen1.Generate(pcg, min, out var s); + var v2 = gen2.Generate(pcg, min, out var s); size.Add(s); if (Size.IsLessThan(min, size)) return default!; - var v2 = gen2.Generate(pcg, min, out s); + var v3 = gen3.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v4 = gen4.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v5 = gen5.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v6 = gen6.Generate(pcg, min, out s); + size.Add(s); + if (Size.IsLessThan(min, size)) return default!; + var v7 = gen7.Generate(pcg, min, out s); + size.Add(s); + return (v1, v2, v3, v4, v5, v6, v7); + } + } + /// Projects each element of a generator into a tuple. + public static Gen<(T1, T2, T3, T4, T5, T6, T7)> Select(this Gen gen1, Gen gen2, Gen gen3, + Gen gen4, Gen gen5, Gen gen6, Gen gen7) + => new GenSelectTupleCreate(gen1, gen2, gen3, gen4, gen5, gen6, gen7); + + sealed class GenSelectTupleCreate(Gen gen1, Gen gen2, Gen gen3, Gen gen4, + Gen gen5, Gen gen6, Gen gen7, Gen gen8) : Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> + { + private readonly Gen gen1 = gen1; + private readonly Gen gen2 = gen2; + private readonly Gen gen3 = gen3; + private readonly Gen gen4 = gen4; + private readonly Gen gen5 = gen5; + private readonly Gen gen6 = gen6; + private readonly Gen gen7 = gen7; + private readonly Gen gen8 = gen8; + public override (T1, T2, T3, T4, T5, T6, T7, T8) Generate(PCG pcg, Size? min, out Size size) + { + var v1 = gen1.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + var v2 = gen2.Generate(pcg, min, out var s); size.Add(s); if (Size.IsLessThan(min, size)) return default!; var v3 = gen3.Generate(pcg, min, out s); @@ -875,8 +705,22 @@ public static Gen SelectProjects each element of a generator into a tuple. + public static Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> Select(this Gen gen1, Gen gen2, Gen gen3, + Gen gen4, Gen gen5, Gen gen6, Gen gen7, Gen gen8) + => new GenSelectTupleCreate(gen1, gen2, gen3, gen4, gen5, gen6, gen7, gen8); sealed class GenSelectMany(Gen gen, Func> selector) : Gen { @@ -1090,142 +934,207 @@ public override R Generate(PCG pcg, Size? min, out Size size) public static Gen SelectMany(this Gen<(T1, T2, T3, T4, T5)> gen, Func> selector) => new GenSelectManyTuple(gen, selector); - /// Filters the elements of a generator based on a predicate. - public static Gen Where(this Gen gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + sealed class GenWhere(Gen gen, Func predicate) : Gen { - int i = 100; - while (i-- > 0) + private readonly Gen gen = gen; + private readonly Func predicate = predicate; + public override T Generate(PCG pcg, Size? min, out Size size) { - var t = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t)) return t; + int i = 100; + while (i-- > 0) + { + var t = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t)) return t; + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2)> Where(this Gen<(T1, T2)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen Where(this Gen gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2)> gen, Func predicate) : Gen<(T1, T2)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2)) return (t1, t2); + int i = 100; + while (i-- > 0) + { + var (t1, t2) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2)) return (t1, t2); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3)> Where(this Gen<(T1, T2, T3)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2)> Where(this Gen<(T1, T2)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3)> gen, Func predicate) : Gen<(T1, T2, T3)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3)) return (t1, t2, t3); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3)) return (t1, t2, t3); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3, T4)> Where(this Gen<(T1, T2, T3, T4)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3)> Where(this Gen<(T1, T2, T3)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3, T4)> gen, Func predicate) : Gen<(T1, T2, T3, T4)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3, T4)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3, T4) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3, t4) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3, t4)) return (t1, t2, t3, t4); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3, t4) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3, t4)) return (t1, t2, t3, t4); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3, T4, T5)> Where(this Gen<(T1, T2, T3, T4, T5)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3, T4)> Where(this Gen<(T1, T2, T3, T4)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3, T4, T5)> gen, Func predicate) : Gen<(T1, T2, T3, T4, T5)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3, T4, T5)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3, T4, T5) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3, t4, t5) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3, t4, t5)) return (t1, t2, t3, t4, t5); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3, t4, t5) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3, t4, t5)) return (t1, t2, t3, t4, t5); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3, T4, T5, T6)> Where(this Gen<(T1, T2, T3, T4, T5, T6)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3, T4, T5)> Where(this Gen<(T1, T2, T3, T4, T5)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3, T4, T5, T6)> gen, Func predicate) : Gen<(T1, T2, T3, T4, T5, T6)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3, T4, T5, T6)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3, T4, T5, T6) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3, t4, t5, t6) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3, t4, t5, t6)) return (t1, t2, t3, t4, t5, t6); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3, t4, t5, t6) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3, t4, t5, t6)) return (t1, t2, t3, t4, t5, t6); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3, T4, T5, T6, T7)> Where(this Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3, T4, T5, T6)> Where(this Gen<(T1, T2, T3, T4, T5, T6)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func predicate) : Gen<(T1, T2, T3, T4, T5, T6, T7)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3, T4, T5, T6, T7)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3, T4, T5, T6, T7) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3, t4, t5, t6, t7) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3, t4, t5, t6, t7)) return (t1, t2, t3, t4, t5, t6, t7); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3, t4, t5, t6, t7) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3, t4, t5, t6, t7)) return (t1, t2, t3, t4, t5, t6, t7); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); - + } /// Filters the elements of a generator based on a predicate. - public static Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> Where(this Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func predicate) => Create((PCG pcg, Size? min, out Size size) => + public static Gen<(T1, T2, T3, T4, T5, T6, T7)> Where(this Gen<(T1, T2, T3, T4, T5, T6, T7)> gen, Func predicate) + => new GenWhere(gen, predicate); + + sealed class GenWhere(Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func predicate) : Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> { - int i = 100; - while (i-- > 0) + private readonly Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen = gen; + private readonly Func predicate = predicate; + public override (T1, T2, T3, T4, T5, T6, T7, T8) Generate(PCG pcg, Size? min, out Size size) { - var (t1, t2, t3, t4, t5, t6, t7, t8) = gen.Generate(pcg, min, out size); - if (Size.IsLessThan(min, size)) return default!; - if (predicate(t1, t2, t3, t4, t5, t6, t7, t8)) return (t1, t2, t3, t4, t5, t6, t7, t8); + int i = 100; + while (i-- > 0) + { + var (t1, t2, t3, t4, t5, t6, t7, t8) = gen.Generate(pcg, min, out size); + if (Size.IsLessThan(min, size)) return default!; + if (predicate(t1, t2, t3, t4, t5, t6, t7, t8)) return (t1, t2, t3, t4, t5, t6, t7, t8); + } + throw new CsCheckException("Failing Where max count"); } - throw new CsCheckException("Failing Where max count"); - }); + } + /// Filters the elements of a generator based on a predicate. + public static Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> Where(this Gen<(T1, T2, T3, T4, T5, T6, T7, T8)> gen, Func predicate) + => new GenWhere(gen, predicate); - /// Create a generator where the element is one of the constants. - public static Gen OneOfConst(params T[] constants) => Create((PCG pcg, Size? min, out Size size) => + sealed class GenOneOfConst(params T[] constants) : Gen { - var i = pcg.Next((uint)constants.Length); - size = new Size(i); - return constants[i]; - }); + private readonly T[] constants = constants; + public override T Generate(PCG pcg, Size? min, out Size size) + { + var i = pcg.Next((uint)constants.Length); + size = new Size(i); + return constants[i]; + } + } + /// Create a generator where the element is one of the constants. + public static Gen OneOfConst(params T[] constants) + => new GenOneOfConst(constants); - /// Create a generator where the element is generated from one of the generators. - public static Gen OneOf(params IGen[] gens) => Create((PCG pcg, Size? min, out Size size) => + sealed class GenOneOf(params IGen[] gens) : Gen { - var i = pcg.Next((uint)gens.Length); - var next = i == min?.I ? min.Next : null; - var r = gens[i].Generate(pcg, next, out size); - size = new Size(i, size); - return r; - }); + private readonly IGen[] gens = gens; + public override T Generate(PCG pcg, Size? min, out Size size) + { + var i = pcg.Next((uint)gens.Length); + var next = i == min?.I ? min.Next : null; + var r = gens[i].Generate(pcg, next, out size); + size = new Size(i, size); + return r; + } + } + /// Create a generator where the element is generated from one of the generators. + public static Gen OneOf(params IGen[] gens) + => new GenOneOf(gens); /// Create a generator for an enum. public static Gen Enum() where T : Enum - { - return OneOfConst((T[])System.Enum.GetValues(typeof(T))); - } + => OneOfConst((T[])System.Enum.GetValues(typeof(T))); - /// Create a generator where the element is one of the constants weighted by the frequency. - public static Gen FrequencyConst(params (int Frequency, T Constant)[] constants) + sealed class GenFrequencyConst(uint total, params (int Frequency, T Constant)[] constants) : Gen { - uint l = 0; - foreach (var (i, _) in constants) l += (uint)i; - return Create((PCG pcg, Size? _, out Size size) => + private readonly uint total = total; + private readonly (int Frequency, T Constant)[] constants = constants; + public override T Generate(PCG pcg, Size? min, out Size size) { - var v = (int)pcg.Next(l); + var v = (int)pcg.Next(total); size = new Size((ulong)v); for (var j = 0; j < constants.Length; j++) { @@ -1234,17 +1143,23 @@ public static Gen FrequencyConst(params (int Frequency, T Constant)[] cons return constants[j].Constant; } return default!; - }); + } + } + /// Create a generator where the element is one of the constants weighted by the frequency. + public static Gen FrequencyConst(params (int Frequency, T Constant)[] constants) + { + uint total = 0; + foreach (var (i, _) in constants) total += (uint)i; + return new GenFrequencyConst(total, constants); } - /// Create a generator where the element is generated by one of the generators weighted by the frequency. - public static Gen Frequency(params (int Frequency, IGen Generator)[] gens) + sealed class GenFrequency(uint total, params (int Frequency, IGen Generator)[] gens) : Gen { - uint l = 0; - foreach (var (i, _) in gens) l += (uint)i; - return Create((PCG pcg, Size? min, out Size size) => + private readonly uint total = total; + private readonly (int Frequency, IGen Generator)[] gens = gens; + public override T Generate(PCG pcg, Size? min, out Size size) { - var nSize = pcg.Next(l); + var nSize = pcg.Next(total); var v = (int)nSize; for (var i = 0; i < gens.Length; i++) { @@ -1259,9 +1174,24 @@ public static Gen Frequency(params (int Frequency, IGen Generator)[] ge } size = new Size(0); return default!; - }); + } + } + /// Create a generator where the element is generated by one of the generators weighted by the frequency. + public static Gen Frequency(params (int Frequency, IGen Generator)[] gens) + { + uint total = 0; + foreach (var (i, _) in gens) total += (uint)i; + return new GenFrequency(total, gens); } + sealed class GenRecursive(Func> gen) : Gen + { + private readonly Func> gen = gen; + public override T Generate(PCG pcg, Size? min, out Size size) + { + return gen().Generate(pcg, null, out size); + } + } /// /// Recursively generate a type. /// @@ -1269,8 +1199,8 @@ public static Gen Frequency(params (int Frequency, IGen Generator)[] ge public static Gen Recursive(Func, Gen> f) { Gen? gen = null; - gen = f(Create((PCG pcg, Size? _, out Size size) => gen!.Generate(pcg, null, out size))); - return gen!; + gen = f(new GenRecursive(() => gen!)); + return gen; } /// @@ -1279,10 +1209,19 @@ public static Gen Recursive(Func, Gen> f) /// The function to create the generator give the depth and an instance of the generator. public static Gen Recursive(Func, Gen> f) { - Gen gen(int i) => f(i, Create((PCG pcg, Size? _, out Size size) => gen(i + 1).Generate(pcg, null, out size))); + Gen gen(int i) => f(i, new GenRecursive(() => gen(i + 1))); return gen(0); } + sealed class GenRecursiveMap(Func> gen, GenMap map) : Gen + { + private readonly Func> gen = gen; + private readonly GenMap map = map; + public override T Generate(PCG pcg, Size? min, out Size size) + { + return map(gen().Generate(pcg, null, out size), ref size); + } + } /// /// Recursively generate a type with a map of type and size. /// @@ -1291,7 +1230,7 @@ public static Gen Recursive(Func, Gen> f) public static Gen Recursive(Func, Gen> f, GenMap map) { Gen? gen = null; - gen = f(Create((PCG pcg, Size? _, out Size size) => map(gen!.Generate(pcg, null, out size), ref size))); + gen = f(new GenRecursiveMap(() => gen!, map)); return gen; } @@ -1302,19 +1241,25 @@ public static Gen Recursive(Func, Gen> f, GenMap map) /// The type and size map function. public static Gen Recursive(Func, Gen> f, GenMap map) { - Gen gen(int i) => f(i, Create((PCG pcg, Size? _, out Size size) => map(gen(i + 1).Generate(pcg, null, out size), ref size))); + Gen gen(int i) => f(i, new GenRecursiveMap(() => gen(i + 1), map)); return gen(0); } - /// Create a second exact clone by running the generator again with the same seed. - public static Gen<(T V0, T V1)> Clone(this Gen gen) => Create((PCG pcg, Size? min, out Size size) => + sealed class GenClone(Gen gen) : Gen<(T, T)> { - var seed = pcg.Seed; - var stream = pcg.Stream; - var r1 = gen.Generate(pcg, min, out size); - var r2 = gen.Generate(new PCG(stream, seed), min, out _); - return (r1, r2); - }); + private readonly Gen gen = gen; + public override (T, T) Generate(PCG pcg, Size? min, out Size size) + { + var seed = pcg.Seed; + var stream = pcg.Stream; + var r1 = gen.Generate(pcg, min, out size); + var r2 = gen.Generate(new PCG(stream, seed), min, out _); + return (r1, r2); + } + } + /// Create a second exact clone by running the generator again with the same seed. + public static Gen<(T, T)> Clone(this Gen gen) + => new GenClone(gen); public static GenDictionary Dictionary(this Gen genK, Gen genV) => new(genK, genV); @@ -1332,36 +1277,55 @@ static void ShuffleInPlace(IList a, PCG pcg, int lower) } } - /// Create a generator by shuffling the elements. - public static Gen Shuffle(T[] constants) => Create((PCG pcg, Size? _, out Size size) => + sealed class GenShuffleConst(T[] constants) : Gen { - constants = (T[])constants.Clone(); - ShuffleInPlace(constants, pcg, 0); - size = new Size(0); - return constants; - }); + private readonly T[] constants = constants; + public override T[] Generate(PCG pcg, Size? min, out Size size) + { + var array = (T[])constants.Clone(); + ShuffleInPlace(array, pcg, 0); + size = new Size(0); + return array; + } + } + /// Create a generator by shuffling the elements. + public static Gen Shuffle(T[] constants) + => new GenShuffleConst(constants); - /// Shuffle the generated elements. - public static Gen Shuffle(this Gen gen) => Create((PCG pcg, Size? _, out Size size) => + sealed class GenShuffle(Gen gen) : Gen { - var a = gen.Generate(pcg, null, out size); - ShuffleInPlace(a, pcg, 0); - return a; - }); + private readonly Gen gen = gen; + public override T[] Generate(PCG pcg, Size? min, out Size size) + { + var a = gen.Generate(pcg, null, out size); + ShuffleInPlace(a, pcg, 0); + return a; + } + } + /// Shuffle the generated elements. + public static Gen Shuffle(this Gen gen) + => new GenShuffle(gen); - /// Create a generator by shuffling the elements. - public static Gen Shuffle(T[] a, int length) => Create((PCG pcg, Size? _, out Size size) => + sealed class GenShuffleConstLength(T[] constants, int length) : Gen { - a = (T[])a.Clone(); - size = new Size(0); - int lower = Math.Max(a.Length - length, 0); - ShuffleInPlace(a, pcg, lower); - if (lower == 0) return a; - var r = new T[length]; - for (int i = 0; i < r.Length; i++) - r[i] = a[i + lower]; - return r; - }); + private readonly T[] constants = constants; + private readonly int length = length; + public override T[] Generate(PCG pcg, Size? min, out Size size) + { + var a = (T[])constants.Clone(); + size = new Size(0); + int lower = Math.Max(a.Length - length, 0); + ShuffleInPlace(a, pcg, lower); + if (lower == 0) return a; + var r = new T[length]; + for (int i = 0; i < r.Length; i++) + r[i] = a[i + lower]; + return r; + } + } + /// Create a generator by shuffling the elements. + public static Gen Shuffle(T[] constants, int length) + => new GenShuffleConstLength(constants, length); /// Create a generator by shuffling the elements. public static Gen Shuffle(T[] a, int start, int finish) => diff --git a/Tests/CheckTests.cs b/Tests/CheckTests.cs index b561063..3271459 100644 --- a/Tests/CheckTests.cs +++ b/Tests/CheckTests.cs @@ -274,7 +274,7 @@ public void SampleConcurrent_ConcurrentDictionary() Gen.Dictionary(Gen.Int[0, 100], Gen.Byte)[0, 10].Select(l => new ConcurrentDictionary(l)) .SampleConcurrent( Gen.Int[0, 100].Select(Gen.Byte) - .Operation>(t =>$"d[{t.V0}] = {t.V1}", (d, t) => d[t.V0] = t.V1), + .Operation>(t =>$"d[{t.Item1}] = {t.Item2}", (d, t) => d[t.Item1] = t.Item2), Gen.Int[0, 100] .Operation>(i => $"TryRemove({i})", (d, i) => d.TryRemove(i, out _)) diff --git a/Tests/GenTests.cs b/Tests/GenTests.cs index 2b7e797..36c0625 100644 --- a/Tests/GenTests.cs +++ b/Tests/GenTests.cs @@ -31,8 +31,8 @@ public void Bool_Distribution() public void SByte_Range() { (from t in Gen.Select(Gen.SByte, Gen.SByte) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.SByte[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -44,7 +44,7 @@ public void SByte_Distribution() const int buckets = 70; const int frequency = 10; var expected = Enumerable.Repeat(frequency, buckets).ToArray(); - Gen.SByte[0, (sbyte)(buckets - 1)] + Gen.SByte[0, buckets - 1] .Convert().Array[frequency * buckets] .Select(sample => Tally(buckets, sample)) .Sample(actual => Check.ChiSquared(expected, actual), iter: 1, time: -2); @@ -54,8 +54,8 @@ public void SByte_Distribution() public void Byte_Range() { (from t in Gen.Byte.Select(Gen.Byte) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Byte[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -83,8 +83,8 @@ public void Short_Zigzag_Roundtrip() public void Short_Range() { (from t in Gen.Short.Select(Gen.Short) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Short[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -106,8 +106,8 @@ public void Short_Distribution() public void UShort_Range() { (from t in Gen.UShort.Select(Gen.UShort) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.UShort[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -129,8 +129,8 @@ public void UShort_Distribution() public void Int_Range() { (from t in Gen.Int.Select(Gen.Int) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Int[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -208,10 +208,10 @@ public void Int_Distribution() public void Int_Skew() { (from t in Gen.Int.Select(Gen.Int, Gen.Double[-10.0, 10.0]) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) - from value in Gen.Int.Skew[start, finish, t.V2] - select (value, start, finish, t.V2)) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) + from value in Gen.Int.Skew[start, finish, t.Item3] + select (value, start, finish, t.Item3)) .Sample(i => i.value >= i.start && i.value <= i.finish); } @@ -235,8 +235,8 @@ public void Zigzag() public void UInt_Range() { (from t in Gen.UInt.Select(Gen.UInt) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.UInt[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -258,9 +258,9 @@ public void UInt_Distribution() public void UInt_Skew() { (from t in Gen.UInt.Select(Gen.UInt, Gen.Double[-10.0, 10.0]) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) - from value in Gen.UInt.Skew[start, finish, t.V2] + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) + from value in Gen.UInt.Skew[start, finish, t.Item3] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); } @@ -291,8 +291,8 @@ public void Long_Gen_Method() public void Long_Range() { (from t in Gen.Long.Select(Gen.Long) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Long[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -314,8 +314,8 @@ public void Long_Distribution() public void ULong_Range() { (from t in Gen.ULong.Select(Gen.ULong) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.ULong[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -349,8 +349,8 @@ public void Single_Unit_Range() public void Single_Range() { (from t in Gen.Single.Unit.Select(Gen.Single.Unit) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Single[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -428,8 +428,8 @@ public void Double_Unit_Range() public void Double_Range() { (from t in Gen.Double.Unit.Select(Gen.Double.Unit) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Double[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish, seed: "89rtRQWk16go", iter: 1); @@ -452,9 +452,9 @@ public void Double_Distribution() public void Double_Skew() { (from t in Gen.Double.Unit.Select(Gen.Double.Unit, Gen.Double[-10.0, 10.0]) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) - from value in Gen.Double.Skew[start, finish, t.V2] + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) + from value in Gen.Double.Skew[start, finish, t.Item3] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); } @@ -527,8 +527,8 @@ public void Decimal_Unit_Range() public void Decimal_Range() { (from t in Gen.Decimal.Unit.Select(Gen.Decimal.Unit) - let start = Math.Min(t.V0, t.V1) - let finish = Math.Max(t.V0, t.V1) + let start = Math.Min(t.Item1, t.Item2) + let finish = Math.Max(t.Item1, t.Item2) from value in Gen.Decimal[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -551,8 +551,8 @@ public void Decimal_Distribution() public void Date_Range() { (from t in Gen.Date.Select(Gen.Date) - let start = t.V0 < t.V1 ? t.V0 : t.V1 - let finish = t.V0 < t.V1 ? t.V1 : t.V0 + let start = t.Item1 < t.Item2 ? t.Item1 : t.Item2 + let finish = t.Item1 < t.Item2 ? t.Item2 : t.Item1 from value in Gen.Date[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -562,8 +562,8 @@ public void Date_Range() public void DateTime_Range() { (from t in Gen.DateTime.Select(Gen.DateTime) - let start = t.V0 < t.V1 ? t.V0 : t.V1 - let finish = t.V0 < t.V1 ? t.V1 : t.V0 + let start = t.Item1 < t.Item2 ? t.Item1 : t.Item2 + let finish = t.Item1 < t.Item2 ? t.Item2 : t.Item1 from value in Gen.DateTime[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -573,8 +573,8 @@ public void DateTime_Range() public void TimeSpan_Range() { (from t in Gen.TimeSpan.Select(Gen.TimeSpan) - let start = t.V0 < t.V1 ? t.V0 : t.V1 - let finish = t.V0 < t.V1 ? t.V1 : t.V0 + let start = t.Item1 < t.Item2 ? t.Item1 : t.Item2 + let finish = t.Item1 < t.Item2 ? t.Item2 : t.Item1 from value in Gen.TimeSpan[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -596,8 +596,8 @@ public void Guid() public void Char_Range() { (from t in Gen.Char.Select(Gen.Char) - let start = t.V0 > t.V1 ? t.V1 : t.V0 - let finish = t.V0 > t.V1 ? t.V0 : t.V1 + let start = t.Item1 > t.Item2 ? t.Item2 : t.Item1 + let finish = t.Item1 > t.Item2 ? t.Item1 : t.Item2 from value in Gen.Char[start, finish] select (value, start, finish)) .Sample(i => i.value >= i.start && i.value <= i.finish); @@ -673,9 +673,9 @@ public void Frequency() { const int frequency = 10; (from f in Gen.Select(Gen.Int[1, 5], Gen.Int[1, 5], Gen.Int[1, 5]) - let expected = new[] { f.V0 * frequency, f.V1 * frequency, f.V2 * frequency } - from actual in Gen.FrequencyConst((f.V0, 0), (f.V1, 1), (f.V2, 2)) - .Array[frequency * (f.V0 + f.V1 + f.V2)] + let expected = new[] { f.Item1 * frequency, f.Item2 * frequency, f.Item3 * frequency } + from actual in Gen.FrequencyConst((f.Item1, 0), (f.Item2, 1), (f.Item3, 2)) + .Array[frequency * (f.Item1 + f.Item2 + f.Item3)] .Select(sample => Tally(3, sample)) select (expected, actual)) .Sample(t => Check.ChiSquared(t.expected, t.actual), iter: 1, time: -2); diff --git a/Tests/IMToolsTests.cs b/Tests/IMToolsTests.cs index aed62b4..30b7913 100644 --- a/Tests/IMToolsTests.cs +++ b/Tests/IMToolsTests.cs @@ -88,8 +88,8 @@ public void AddOrUpdate_Metamorphic() .Select(i => new ImHolder> { Im = i }) .SampleMetamorphic( Gen.Select(Gen.Int[0, upperBound], Gen.Int, Gen.Int[0, upperBound], Gen.Int).Metamorphic>>( - (d, t) => d.Im = d.Im.AddOrUpdate(t.V0, t.V1).AddOrUpdate(t.V2, t.V3), - (d, t) => d.Im = t.V0 == t.V2 ? d.Im.AddOrUpdate(t.V2, t.V3) : d.Im.AddOrUpdate(t.V2, t.V3).AddOrUpdate(t.V0, t.V1) + (d, t) => d.Im = d.Im.AddOrUpdate(t.Item1, t.Item2).AddOrUpdate(t.Item3, t.Item4), + (d, t) => d.Im = t.Item1 == t.Item3 ? d.Im.AddOrUpdate(t.Item3, t.Item4) : d.Im.AddOrUpdate(t.Item3, t.Item4).AddOrUpdate(t.Item1, t.Item2) ) , equal: (a, b) => Check.Equal(a.Im.Enumerate().Select(j => (j.Key, j.Value)), b.Im.Enumerate().Select(j => (j.Key, j.Value))) , print: i => Check.Print(i.Im.Enumerate().Select(j => (j.Key, j.Value))) @@ -109,8 +109,8 @@ public void AddOrUpdate_ModelBased() .SampleModelBased( Gen.Int[0, upperBound].Select(Gen.Int).Operation>, Dictionary>((h, d, kv) => { - h.Im = h.Im.AddOrUpdate(kv.V0, kv.V1); - d[kv.V0] = kv.V1; + h.Im = h.Im.AddOrUpdate(kv.Item1, kv.Item2); + d[kv.Item1] = kv.Item2; }) , equal: (h, d) => { diff --git a/Tests/ModelTests.cs b/Tests/ModelTests.cs index 525e839..23e92da 100644 --- a/Tests/ModelTests.cs +++ b/Tests/ModelTests.cs @@ -66,7 +66,7 @@ public static class ModelGen public readonly static Gen Name = Gen.String["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "]; public readonly static Gen Currency = Gen.Enum(); public readonly static Gen Country = Gen.Enum(); - public readonly static Gen Quantity = Gen.Int[-99, 99].Select(Gen.Int[0, 5]).Select(t => t.V0 * (int)Math.Pow(10, t.V1)); + public readonly static Gen Quantity = Gen.Int[-99, 99].Select(Gen.Int[0, 5]).Select((m, e) => m * (int)Math.Pow(10, e)); public readonly static Gen Coupon = Gen.Int[0, 100].Select(i => 0.125 * i); public readonly static Gen Price = Gen.Int[0001, 9999].Select(i => 0.01 * i); public readonly static Gen Date = Gen.Date[new DateTime(2000, 1, 1), new DateTime(2040, 1, 1)]; diff --git a/Tests/PCGTests.cs b/Tests/PCGTests.cs index 39ca2f9..eb04e0f 100644 --- a/Tests/PCGTests.cs +++ b/Tests/PCGTests.cs @@ -160,26 +160,26 @@ public void PCG_Next64() public void PCG_Next_UInt() { Gen.UInt[1, uint.MaxValue].Select(genPCG) - .Select(t => (Max: t.V0, x: t.V1.Next(t.V0))) - .Sample(t => t.x <= t.Max); + .Select((max, pcg) => (max, pcg.Next(max))) + .Sample((max, x) => x <= max); } [Fact] public void PCG_Next64_ULong() { Gen.ULong[1, ulong.MaxValue].Select(genPCG) - .Select(t => (Max: t.V0, x: t.V1.Next64(t.V0))) - .Sample(t => t.x <= t.Max); + .Select((max, pcg) => (max, pcg.Next64(max))) + .Sample((max, x) => x <= max); } [Fact] public void SeedString_RoundTrip() { Gen.Select(Gen.ULong, Gen.UInt) - .Sample(t => + .Sample((i0, i1) => { - var seed = PCG.ToSeedString(t.V0, t.V1); - Assert.Equal(t, PCG.ParseSeedString(seed)); + var seed = PCG.ToSeedString(i0, i1); + Assert.Equal((i0, i1), PCG.ParseSeedString(seed)); }); } diff --git a/Tests/ShrinkingChallengeTests.cs b/Tests/ShrinkingChallengeTests.cs index 602df0f..65677bc 100644 --- a/Tests/ShrinkingChallengeTests.cs +++ b/Tests/ShrinkingChallengeTests.cs @@ -8,7 +8,7 @@ public class ShrinkingChallengeTests { - [Fact(Skip="fails")] + [Fact(Skip = "fails")] public void No1_Bound5() { static short Sum(short[] l) @@ -19,9 +19,9 @@ static short Sum(short[] l) } var sGen = Gen.Short.Array[0, 10].Where(i => Sum(i) < 256); Gen.Select(sGen, sGen, sGen, sGen, sGen) - .Sample(t => + .Sample((a1, a2, a3, a4, a5) => { - var total = Sum(t.V0) + Sum(t.V1) + Sum(t.V2) + Sum(t.V3) + Sum(t.V4); + var total = Sum(a1) + Sum(a2) + Sum(a3) + Sum(a4) + Sum(a5); return (short)total < 5 * 256; }); } @@ -105,21 +105,21 @@ public void No5_LengthList() public void No6_Difference_MustNotBeZero() { Gen.Int.Positive.Select(Gen.Int.Positive) - .Sample(t => t.V0 < 10 || t.V0 != t.V1); + .Sample((i0, i1) => i0 < 10 || i0 != i1); } [Fact(Skip="fails")] public void No6_Difference_MustNotBeSmall() { Gen.Int.Positive.Select(Gen.Int.Positive) - .Sample(t => t.V0 < 10 || Math.Abs(t.V0 - t.V1) > 4 || t.V0 == t.V1); + .Sample((i0, i1) => i0 < 10 || Math.Abs(i0 - i1) > 4 || i0 == i1); } [Fact(Skip="fails")] public void No6_Difference_MustNotBeOne() { Gen.Int.Positive.Select(Gen.Int.Positive) - .Sample(t => t.V0 < 10 || Math.Abs(t.V0 - t.V1) != 1); + .Sample((i0, i1) => i0 < 10 || Math.Abs(i0 - i1) != 1); } class Heap { public int Head; public Heap Left; public Heap Right; } diff --git a/Tests/SlimCollectionsTests.cs b/Tests/SlimCollectionsTests.cs index 4b949bc..a6ac856 100644 --- a/Tests/SlimCollectionsTests.cs +++ b/Tests/SlimCollectionsTests.cs @@ -32,7 +32,7 @@ public void ListSlim_Concurrency() .SampleConcurrent( Gen.Byte.Operation>((l, i) => { lock (l) l.Add(i); }), Gen.Int.NonNegative.Operation>((l, i) => { if (i < l.Count) { var _ = l[i]; } }), - Gen.Int.NonNegative.Select(Gen.Byte).Operation>((l, t) => { if (t.V0 < l.Count) l[t.V0] = t.V1; }), + Gen.Int.NonNegative.Select(Gen.Byte).Operation>((l, t) => { if (t.Item1 < l.Count) l[t.Item1] = t.Item2; }), Gen.Operation>(l => l.ToArray()) ); } @@ -139,8 +139,8 @@ public void MapSlim_ModelBased() .SampleModelBased( Gen.Select(Gen.Int[0, 100], Gen.Byte).Operation, Dictionary>((m, d, t) => { - m[t.V0] = t.V1; - d[t.V0] = t.V1; + m[t.Item1] = t.Item2; + d[t.Item1] = t.Item2; }) ); } @@ -151,8 +151,8 @@ public void MapSlim_Metamorphic() Gen.Dictionary(Gen.Int, Gen.Byte).Select(d => new MapSlim(d)) .SampleMetamorphic( Gen.Select(Gen.Int[0, 100], Gen.Byte, Gen.Int[0, 100], Gen.Byte).Metamorphic>( - (d, t) => { d[t.V0] = t.V1; d[t.V2] = t.V3; }, - (d, t) => { if (t.V0 == t.V2) { d[t.V2] = t.V3; } else { d[t.V2] = t.V3; d[t.V0] = t.V1; } } + (d, t) => { d[t.Item1] = t.Item2; d[t.Item3] = t.Item4; }, + (d, t) => { if (t.Item1 == t.Item3) { d[t.Item3] = t.Item4; } else { d[t.Item3] = t.Item4; d[t.Item1] = t.Item2; } } ) ); } @@ -162,7 +162,7 @@ public void MapSlim_Concurrency() { Gen.Dictionary(Gen.Int, Gen.Byte).Select(d => new MapSlim(d)) .SampleConcurrent( - Gen.Int.Select(Gen.Byte).Operation>((m, t) => { lock (m) m[t.V0] = t.V1; }), + Gen.Int.Select(Gen.Byte).Operation>((m, t) => { lock (m) m[t.Item1] = t.Item2; }), Gen.Int.NonNegative.Operation>((m, i) => { if (i < m.Count) { var _ = m.Key(i); } }), Gen.Int.Operation>((m, i) => { var _ = m.IndexOf(i); }), Gen.Operation>(m => { var _ = m.ToArray(); })