Skip to content

Commit

Permalink
Remove Gen.eval.
Browse files Browse the repository at this point in the history
Fixes #268.
  • Loading branch information
kurtschelfthout committed Sep 1, 2017
1 parent b4ac16b commit c729942
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
13 changes: 4 additions & 9 deletions src/FsCheck/Gen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,15 @@ module Gen =
[<CompiledName("Resize")>]
let resize newSize (Gen m) = Gen (fun _ r -> m newSize r)

///Generates a value of the give size with the given seed.
//[category: Generating test values]
[<CompiledName("Eval")>]
let eval n rnd (Gen m) =
let size,rnd' = Random.rangeInt (0, n, rnd)
(m size rnd').Value

///Generates n values of the given size.
//[category: Generating test values]
[<CompiledName("Sample")>]
let sample size n generator =
let sample size n (Gen generator) =
let rec sample i seed samples =
if i = 0 then samples
else sample (i-1) (Random.split seed |> snd) (eval size seed generator :: samples)
else
let sv = generator size seed
sample (i-1) sv.UpdatedState (sv.Value :: samples)
sample n (Random.create()) []

///Generates an integer between l and h, inclusive.
Expand Down
6 changes: 0 additions & 6 deletions src/FsCheck/GenExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ open System.Collections.Generic
[<AbstractClass; Sealed; System.Runtime.CompilerServices.Extension>]
type GenExtensions =

///Generates a value with maximum size n.
//[category: Generating test values]
[<System.Runtime.CompilerServices.Extension>]
static member Eval(generator, size, random) =
eval size random generator

///Generates n values of the given size.
//[category: Generating test values]
[<System.Runtime.CompilerServices.Extension>]
Expand Down
9 changes: 6 additions & 3 deletions src/FsCheck/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ module Runner =
yield EndShrink result
}

let rec private test initSize resize rnd0 gen =
seq { let rnd1,rnd2 = Random.split rnd0
let rec private test initSize resize rnd0 ((Gen eval) as gen) =
seq { // would like to get rid of this split,
// but the problem is DiscardException. If it is thrown,
// we also don't get the the updated Rnd back from eval.
let rnd1,rnd2 = Random.split rnd0
let newSize = resize initSize
//printfn "Before generate"
//result forced here!
let result, shrinks =
try
let (MkRose (Lazy result,shrinks)) = Gen.eval (newSize |> round |> int) rnd2 gen
let (MkRose (Lazy result,shrinks)) = (eval (newSize |> round |> int) rnd2).Value
result, shrinks
//printfn "After generate"
//problem: since result.Ok is no longer lazy, we only get the generated args _after_ the test is run
Expand Down
4 changes: 2 additions & 2 deletions tests/FsCheck.Test/Runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ module Runner =
[<Property>]
let ``should use configuration from enclosing module``(x:int) =
// checking if the generated value is always the same (-59) from "01234,56789" Replay
x =! -84
x =! -4

[<Property( Replay = "12345,67891")>]
let ``should use configuration on method preferentially``(x:int) =
// checking if the generated value is always the same (18) from "12345,67890" Replay
x =! 9
x =! -93

module BugReproIssue195 =

Expand Down

0 comments on commit c729942

Please sign in to comment.