diff --git a/src/Hedgehog/Gen.fs b/src/Hedgehog/Gen.fs index 779d7b09..3a025aeb 100644 --- a/src/Hedgehog/Gen.fs +++ b/src/Hedgehog/Gen.fs @@ -202,7 +202,27 @@ module Gen = /// Generates a random number in the given inclusive range. [] let inline integral (range : Range<'a>) : Gen<'a> = - create (Shrink.towards <| Range.origin range) (Random.integral range) + let mapFirstDifferently f g = function + | [] -> [] + | x :: xs -> (f x) :: (xs |> List.map g) + let rec createTree (destination : ^a) (x : ^a) = + let childrenValues = + match Shrink.towards destination x |> Seq.toList with + | [] -> [] + | x :: [] -> List.singleton x + | _ :: xs -> xs + let xs = + childrenValues + |> Seq.cons destination + |> Seq.pairwise + |> Seq.toList + |> mapFirstDifferently id (fun (d, x) -> (d + LanguagePrimitives.GenericOne, x)) + |> Seq.map (fun (d, x) -> createTree d x) + Node (x, xs) + range + |> Random.integral + |> Random.map (range |> Range.origin |> createTree) + |> ofRandom // // Combinators - Choice