Skip to content

Commit

Permalink
Add MergeSources to property CE
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Dec 30, 2021
1 parent 454dbdd commit d54534f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. Revert runtime optimization of `Gen.integral`. ([#398][398], [@TysonMN][TysonMN])
- Change `ListGen.traverse` from monadic to applicative. ([#399][399], [@TysonMN][TysonMN])
- Fix bug in the `BindReturn` method of the `property` CE where the generated value is not added to the Journal. ([#401][401], [@TysonMN][TysonMN])
- Add `BindReturn` to the `gen` CE. This essentially changes the last call to `let!` to use `Gen.map` instead of `Gen.bind`. Add `MergeSources` to the `gen` CE. This change enables the `and!` syntax.
- Add `BindReturn` to the `gen` CE. This essentially changes the last call to `let!` to use `Gen.map` instead of `Gen.bind`. Add `MergeSources` to the `gen` and `property` CEs. This change enables the `and!` syntax. ([#400][400], [@TysonMN][TysonMN])

## Version 0.12.0 (2021-12-12)

Expand Down Expand Up @@ -194,6 +194,8 @@

[401]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/401
[400]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/400
[399]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/399
[398]:
Expand Down
3 changes: 3 additions & 0 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ module PropertyBuilder =
|> Property.ofGen
|> Property.map f

member __.MergeSources(ga, gb) =
Gen.zip ga gb

member __.ReturnFrom(m : Property<'a>) : Property<'a> =
m

Expand Down
15 changes: 15 additions & 0 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,19 @@ let propertyTests = testList "Property tests" [

actual =! "false"

testCase "and! syntax is applicative" <| fun () ->
// Based on https://well-typed.com/blog/2019/05/integrated-shrinking/#:~:text=For%20example%2C%20consider%20the%20property%20that
let actual =
property {
let! x = Range.constant 0 1_000_000_000 |> Gen.int32
and! y = Range.constant 0 1_000_000_000 |> Gen.int32
return Expect.isLessThanOrEqual x y "Expected x <= y from (x, y)"
}
|> Property.report
|> Report.render
|> (fun x -> x.Split ([|Environment.NewLine|], StringSplitOptions.None))
|> Array.item 1

actual =! "(1, 0)"

]

0 comments on commit d54534f

Please sign in to comment.