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 661c169
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 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
57 changes: 34 additions & 23 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,40 @@ 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 report1 = Property.report 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.reportOptimizedRecheckWith
failure1.Size
({ Value = failure1.Seed.Value; Gamma = failure1.Seed.Gamma })
failure1.ShrinkPath
PropertyConfig.defaultConfig
prop
match report2.Status with
| OK -> failwith "Recheck report should be Failed, not OK"
| GaveUp -> failwith "Recheck report should be Failed, not GaveUp"
| Failed failure2 ->
count =! 1
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)
Property.check prop
//let report1 = Property.report 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.reportOptimizedRecheckWith
// failure1.Size
// ({ Value = failure1.Seed.Value; Gamma = failure1.Seed.Gamma })
// failure1.ShrinkPath
// PropertyConfig.defaultConfig
// prop
// match report2.Status with
// | OK -> failwith "Recheck report should be Failed, not OK"
// | GaveUp -> failwith "Recheck report should be Failed, not GaveUp"
// | Failed failure2 ->
// count =! 1

let propertyTests = testList "Property tests" [
testCase "recheck only tests shrunken input" <| asdf
Expand Down

0 comments on commit 661c169

Please sign in to comment.