Skip to content

Commit

Permalink
bespoke map-to-bind conversion in test...seems correct
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Sep 9, 2021
1 parent 50ca1fb commit c969c98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/Hedgehog/Hedgehog.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ https://github.com/hedgehogqa/fsharp-hedgehog/blob/master/doc/index.md
<RepositoryUrl>https://github.com/hedgehogqa/fsharp-hedgehog</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Hedgehog.Tests</_Parameter1>
</AssemblyAttribute>
<Compile Include="AutoOpen.fs" />
<Compile Include="Lazy.fs" />
<Compile Include="Numeric.fs" />
Expand Down
2 changes: 2 additions & 0 deletions src/Hedgehog/Lazy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module internal Hedgehog.Lazy

let constant a = Lazy(fun () -> a)

let func (f: unit -> 'a) = Lazy f

let value (ma: Lazy<'a>) = ma.Value

let map (f: 'a -> 'b) (ma: Lazy<'a>) : Lazy<'b> =
Expand Down
29 changes: 24 additions & 5 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@ open TestDsl

let asdf () =
let mutable count = 0
let prop = property {
let! i = Range.constant 0 1_000 |> Gen.int
count <- count + 1
i =! 0
}
let prop =
property {
let! i = Range.constant 0 1_000 |> Gen.int
i
}
|> Property.bind (fun i ->
Lazy.func (fun () ->
try
count <- count + 1
i =! 0
(Journal.empty, Outcome.Success ())
with e ->
(Journal.singletonMessage (string e), Failure))
|> Gen.constant
|> Property.ofGen)


// Directly check the property and inspect test failure message. Looks correct to me.
//Property.check prop

// This code currently passes,
// but the shirnk path construction and consumption has some bugs that could make this part always pass.
let report1 = Property.report prop
match report1.Status with
| OK -> failwith "Initial report should be Failed, not OK"
Expand All @@ -28,6 +45,8 @@ let asdf () =
| OK -> failwith "Recheck report should be Failed, not OK"
| GaveUp -> failwith "Recheck report should be Failed, not GaveUp"
| Failed failure2 ->
let render = Report.render report2
render |> ignore
count =! 1

let propertyTests = testList "Property tests" [
Expand Down

0 comments on commit c969c98

Please sign in to comment.