Skip to content

Commit

Permalink
Revert Gen.integral to its previous non-duplicate-free implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Dec 29, 2021
1 parent 5f1ab55 commit 325795f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Version ?.?.?

- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. ([#398][398], [@TysonMN][TysonMN])
- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. Revert runtime optimization of `Gen.integral`. ([#398][398], [@TysonMN][TysonMN])

## Version 0.12.0 (2021-12-12)

Expand Down
16 changes: 13 additions & 3 deletions src/Hedgehog/Gen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,21 @@ module Gen =

/// Generates a random number in the given inclusive range.
let inline integral (range : Range<'a>) : Gen<'a> =
// https://github.com/hedgehogqa/fsharp-hedgehog/pull/239
range
|> Random.integral
|> Random.map (range |> Range.origin |> Shrink.createTree)
|> ofRandom
|> create (range |> Range.origin |> Shrink.towards)
// The code below was added in
// https://github.com/hedgehogqa/fsharp-hedgehog/pull/239
// It is more efficient than the code above in that the shrink tree is duplicate free.
// However, such a tree does work well when combining applicatively.
// The advantage of a duplicate-free shrink tree is less time spent shrinking.
// The advantage of applicatively combining tree is a potentially smaller shrunken value.
// The latter is better, so reverting to the previous shrink tree for now.
// Maybe it is possible to achieve the best of both.
//range
//|> Random.integral
//|> Random.map (range |> Range.origin |> Shrink.createTree)
//|> ofRandom

//
// Combinators - Choice
Expand Down

0 comments on commit 325795f

Please sign in to comment.