From 6dc45a1e7704c732aa19762adf5e3f7ec251ddd6 Mon Sep 17 00:00:00 2001 From: Kurt Schelfthout Date: Sat, 11 Sep 2021 15:25:14 +0100 Subject: [PATCH] Add a few missing methods to Fluent.Arbitrary. --- FsCheck Release Notes.md | 7 +++++++ src/FsCheck/FSharp.Arbitrary.fs | 2 +- src/FsCheck/Fluent.Arbitrary.fs | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/FsCheck Release Notes.md b/FsCheck Release Notes.md index 7f8df52d..186df81e 100644 --- a/FsCheck Release Notes.md +++ b/FsCheck Release Notes.md @@ -1,3 +1,10 @@ +### 3.0.0-beta2 - To be released + +* Fixed bug that caused exceptions not to be propagated to output correctly. + +* Added a few missing methods in `Fluent.Arbitrary`. + + ### 3.0.0-beta1 - 5 September 2021 * *Backwards incompatible*: Refactor and split of the `Gen` and `Arbitrary` APIs into `FsCheck.FSharp` and `FsCheck.Fluent`. This is a first step in splitting the entire API into a functional (for F# consumers) and fluent (for C# and VB.NET consumers) interface. This should be clearer for both kinds of consumers. diff --git a/src/FsCheck/FSharp.Arbitrary.fs b/src/FsCheck/FSharp.Arbitrary.fs index 251aa2f4..1c03c1c4 100644 --- a/src/FsCheck/FSharp.Arbitrary.fs +++ b/src/FsCheck/FSharp.Arbitrary.fs @@ -85,7 +85,7 @@ module Arb = override __.Shrinker b = b |> a.Shrinker |> Seq.filter pred } - + /// Generates 2-tuples. let zip(t1: Arbitrary<'T1>, t2: Arbitrary<'T2>) = let generator = Gen.zip t1.Generator t2.Generator let shrinker (l,r) = Seq.zip (t1.Shrinker l) (t2.Shrinker r) diff --git a/src/FsCheck/Fluent.Arbitrary.fs b/src/FsCheck/Fluent.Arbitrary.fs index 820c1e29..1034c6b5 100644 --- a/src/FsCheck/Fluent.Arbitrary.fs +++ b/src/FsCheck/Fluent.Arbitrary.fs @@ -50,4 +50,23 @@ type Arb private() = static member MapFilter (arb:Arbitrary<'T>, map: Func<_,_>, filter: Func<_,_>) = Arb.mapFilter map.Invoke filter.Invoke arb + /// Generates 2-tuples. + [] + static member Zip(t1: Arbitrary<'T1>, t2: Arbitrary<'T2>) = + let generator = Gen.Zip(t1.Generator, t2.Generator) + let shrinker (struct (l,r)) = Seq.map2 (fun l r -> struct (l,r)) (t1.Shrinker l) (t2.Shrinker r) + Arb.fromGenShrink(generator, shrinker) + + /// Generates one-dimensional arrays. + /// The length of the generated array is between 0 and size. + /// The sum of the sizes of the elements is equal to the size of the generated array. + [] + static member Array (elements: Arbitrary<'T>) = + Arb.array elements + + /// Generates nullable values that are null 1/8 of the time. + [] + static member Nullable (value: Arbitrary<'T>) = + Arb.nullable value +