Skip to content

Commit

Permalink
Merge pull request #437 from TysonMN/efficient_falseToFailure
Browse files Browse the repository at this point in the history
Efficient falseToFailure
  • Loading branch information
TysonMN authored Jul 16, 2023
2 parents 935c404 + 1f0ffd5 commit f4a4b00
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
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"

]

0 comments on commit f4a4b00

Please sign in to comment.