Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient falseToFailure #437

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 0.14.0
- No longer targeting .NET Framework ([#417][417], [@LyndonGingerich][LyndonGingerich])
- The runtime of `Property.recheck` is now about the same as `Property.check`. Previously, it was about ten times slower. ([#433][433], [@TysonMN][TysonMN])
- The error message given when a deadend is reached during rechecking is improved to say that the cause is a change in generators. ([#436][436], [@TysonMN][TysonMN])
- The implementation of `Property.falseToFailure` is now better. As a result, `Property.recheckBool` now only tests the shrunken input. ([#437][437], [@TysonMN][TysonMN])

## Version 0.13.0 (2022-07-23)

- Fix bug in `Property.recheck` where the result is always `Failed`. ([#415][415], [@TysonMN][TysonMN])
Expand Down Expand Up @@ -199,6 +205,12 @@
[LyndonGingerich]
https://github.com/LyndonGingerich

[436]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/436
[433]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/433
[417]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/417
[416]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/416
[415]:
Expand Down
5 changes: 4 additions & 1 deletion src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace Hedgehog

open System

type internal TestReturnedFalseException() =
inherit System.Exception("Expected 'true' but was 'false'.")


[<Struct>]
type Property<'a> =
Expand Down Expand Up @@ -95,7 +98,7 @@ module Property =
|> ofGen

let falseToFailure p =
p |> bind ofBool
p |> map (fun b -> if not b then raise (TestReturnedFalseException()))

let internal printValue (value) : string =
// sprintf "%A" is not prepared for printing ResizeArray<_> (C# List<T>) so we prepare the value instead
Expand Down
29 changes: 28 additions & 1 deletion tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,34 @@ let propertyTests = testList "Property tests" [
//render.Contains "actual: 1" =! true // comment out for now since it causes the Fable test to fail


testCase "recheckBool only tests shrunken input" <| fun () ->
let mutable count = 0
let prop =
property {
let! i = Range.constant 0 1_000_000 |> Gen.int32
count <- count + 1
return i = 0
}

let report1 = Property.reportBool prop
match report1.Status with
| OK -> failwith "Initial report should be Failed, not OK"
| GaveUp -> failwith "Initial report should be Failed, not GaveUp"
| Failed failure1 ->
count <- 0
let report2 =
Property.reportRecheckBool
(RecheckData.serialize failure1.RecheckInfo.Value.Data)
prop
match report2.Status with
| OK -> failwith "Recheck report should be Failed, not OK"
| GaveUp -> failwith "Recheck report should be Failed, not GaveUp"
| Failed _ ->
let render = Report.render report2
count =! 1
//render.Contains "actual: 1" =! true // comment out for now since it causes the Fable test to fail


testCase "recheck passes after code is fixed" <| fun () ->
let mutable b = false
let prop =
Expand Down Expand Up @@ -151,5 +179,4 @@ let propertyTests = testList "Property tests" [
.Replace(")", "")

actual =! "1,0"

]