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 Jan 1, 2022
1 parent 76f7678 commit fda88a3
Show file tree
Hide file tree
Showing 3 changed files with 27 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
21 changes: 21 additions & 0 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,25 @@ 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 x <= y |> Expect.isTrue
}
|> Property.report
|> Report.render
|> (fun x -> x.Split ([|Environment.NewLine|], StringSplitOptions.None))
|> Array.item 1

let actual =
// normalize printing of a pair between .NET and Fable/JS
actual.Replace("(", "")
.Replace(" ", "")
.Replace(")", "")

actual =! "1,0"

]

0 comments on commit fda88a3

Please sign in to comment.