Skip to content

Commit

Permalink
Add BindReturn to property CE
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Nov 26, 2021
1 parent 302809e commit a63f90c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Version ?

- Rename `Property.failOnFalse` to `Property.falseToFailure` ([#384][384], [@TysonMN][TysonMN])
- Add `BindReturn` to the `property` CE ([#364][364], [@TysonMN][TysonMN])
- A breaking change. Previously, returning a `bool` from a `property` CE (after using `let!`) caused the CE to have return type `Property<unit>`. Now this results in a return type of `Property<bool>`. The previous behavior can now be expressed by piping the `Property<bool>` instance into `Property.falseToFailure`.

## Version 0.11.1 (2021-11-19)

Expand Down Expand Up @@ -188,6 +190,8 @@
https://github.com/hedgehogqa/fsharp-hedgehog/pull/381
[380]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/380
[364]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/364
[363]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/363
[362]:
Expand Down
6 changes: 6 additions & 0 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ module PropertyBuilder =
member __.Return(b : bool) : Property<unit> =
Property.ofBool b

member __.BindReturn(m : Gen<'a>, f: 'a -> 'b) =
m
|> Gen.map (fun a -> (Journal.empty, Success a))
|> Property.ofGen
|> Property.map f

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

Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Benchmarks () =
let! i = Gen.int32 (Range.constant 0 10000)
return i >= 0
}
|> Property.falseToFailure
|> Property.check

[<Benchmark>]
Expand All @@ -23,6 +24,7 @@ type Benchmarks () =
let! i = Gen.string (Range.constant 0 100) Gen.ascii
return i.Length >= 0
}
|> Property.falseToFailure
|> Property.check

[<Benchmark>]
Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Tests/GenTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ let genTests = testList "Gen tests" [
let! _ = Gen.int64 (Range.exponentialBounded ())
return true
}
|> Property.falseToFailure
|> Property.check

fableIgnore "uint64 can create exponentially bounded integer" <| fun _ ->
property {
let! _ = Gen.uint64 (Range.exponentialBounded ())
return true
}
|> Property.falseToFailure
|> Property.check

testCase "apply is chainable" <| fun _ ->
Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let propertyTests = testList "Property tests" [
let! xs = Range.singleton 0 |> Gen.int32 |> Gen.list (Range.singleton 5) |> Gen.map ResizeArray
return false
}
|> Property.falseToFailure
|> Property.renderWith (PropertyConfig.withShrinks 0<shrinks> PropertyConfig.defaultConfig)
Expect.isNotMatch report "\.\.\." "Abbreviation (...) found"

Expand Down Expand Up @@ -57,6 +58,7 @@ let propertyTests = testList "Property tests" [
let! opt = Gen.constant () |> Gen.option
return opt |> Option.isSome
}
|> Property.falseToFailure
|> Property.report
|> Report.render
|> ignore
Expand Down
1 change: 1 addition & 0 deletions tests/Hedgehog.Tests/ShrinkTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ let shrinkTests = testList "Shrink tests" [
let! actual = Range.linear 1 1_000_000 |> Gen.int32
return actual < 500_000
}
|> Property.falseToFailure
|> Property.reportWith propConfig
match report.Status with
| Failed failureData ->
Expand Down

0 comments on commit a63f90c

Please sign in to comment.