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

Purpose of 'size' parameter in Gen.sample #87

Closed
moodmosaic opened this Issue Feb 18, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@moodmosaic
Contributor

moodmosaic commented Feb 18, 2015

These examples produce similar results, even though size is completely different on each example:

let sample' = sample 0 11 // Size = 0
let actual = sample' <| choose (0, 9)

Results to:

Length = 11
    [0]: 4
    [1]: 0
    [2]: 4
    [3]: 0
    [4]: 3
    [5]: 9
    [6]: 3
    [7]: 9
    [8]: 2
    [9]: 8
    [10]: 2
let sample' = sample 1000 11 // Size = 1000
let actual = sample' <| choose (0, 9)

Results to something similar:

Length = 11
    [0]: 8
    [1]: 6
    [2]: 2
    [3]: 3
    [4]: 7
    [5]: 3
    [6]: 1
    [7]: 2
    [8]: 6
    [9]: 2
    [10]: 0

Given that sample is currently defined as below, is it really necessary to parameterize the size?

[<CompiledName("Sample")>]
let sample size n gn  = 
    let rec sample i seed samples =
        if i = 0 then samples
        else sample (i-1) (Random.stdSplit seed |> snd) (eval size seed gn :: samples)
    sample n (Random.newSeed()) []
@kurtschelfthout

This comment has been minimized.

Show comment
Hide comment
@kurtschelfthout

kurtschelfthout Feb 18, 2015

Member

That's just because Gen.choose basically ignores size. It gives you a uniform distribution between min an max. Try sampling Arb.Default.Int32().Generator or a list or something and you'll see a difference.

Member

kurtschelfthout commented Feb 18, 2015

That's just because Gen.choose basically ignores size. It gives you a uniform distribution between min an max. Try sampling Arb.Default.Int32().Generator or a list or something and you'll see a difference.

@moodmosaic

This comment has been minimized.

Show comment
Hide comment
@moodmosaic

moodmosaic Feb 18, 2015

Contributor

In QuickCheck you can do this:

λ sample $ choose (0, 9 :: Int)
1
5
0
2
3
4
6
5
5
4
1

Would it be possible to do something similar with FsCheck? (Using similar syntax.)

Contributor

moodmosaic commented Feb 18, 2015

In QuickCheck you can do this:

λ sample $ choose (0, 9 :: Int)
1
5
0
2
3
4
6
5
5
4
1

Would it be possible to do something similar with FsCheck? (Using similar syntax.)

@kurtschelfthout

This comment has been minimized.

Show comment
Hide comment
@kurtschelfthout

kurtschelfthout Feb 18, 2015

Member

I don't understand the question. You mean you want a function that does exactly what QuickCheck sample does? https://hackage.haskell.org/package/QuickCheck-2.7.6/docs/src/Test-QuickCheck-Gen.html#sample%27
Yes that should be straightforward to port, because FsCheck has resize, sequence and generate too.

Member

kurtschelfthout commented Feb 18, 2015

I don't understand the question. You mean you want a function that does exactly what QuickCheck sample does? https://hackage.haskell.org/package/QuickCheck-2.7.6/docs/src/Test-QuickCheck-Gen.html#sample%27
Yes that should be straightforward to port, because FsCheck has resize, sequence and generate too.

@moodmosaic

This comment has been minimized.

Show comment
Hide comment
@moodmosaic

moodmosaic Feb 19, 2015

Contributor

That's just because Gen.choose basically ignores size.

What is size exactly though? It's not clear from the XML documentation.

You mean you want a function that does exactly what QuickCheck sample does?

The problem with the current sample function is that it can be a bit confusing to those familiar with QuickCheck, because QuickCheck defines sample in a different way:

sample :: Show a => Gen a -> IO ()

I'd happily send a Pull Request with a function that does exactly what QuickCheck's sample does. Otherwise, I'd use something like:

let sample' = sample 0 11 // Size = 0
let actual = sample' <| choose (0, 9)
Contributor

moodmosaic commented Feb 19, 2015

That's just because Gen.choose basically ignores size.

What is size exactly though? It's not clear from the XML documentation.

You mean you want a function that does exactly what QuickCheck sample does?

The problem with the current sample function is that it can be a bit confusing to those familiar with QuickCheck, because QuickCheck defines sample in a different way:

sample :: Show a => Gen a -> IO ()

I'd happily send a Pull Request with a function that does exactly what QuickCheck's sample does. Otherwise, I'd use something like:

let sample' = sample 0 11 // Size = 0
let actual = sample' <| choose (0, 9)
@kurtschelfthout

This comment has been minimized.

Show comment
Hide comment
@kurtschelfthout

kurtschelfthout Feb 19, 2015

Member

See "The size of test data" on this page https://fsharp.github.io/FsCheck/TestData.html

I'd prefer to leave sample as-is, size is an important part of how FsCheck works.

QuickCheck generators also uses size in almost exactly the same way, it's just that the implementation of QuickCheck's sample chooses size for you.

Member

kurtschelfthout commented Feb 19, 2015

See "The size of test data" on this page https://fsharp.github.io/FsCheck/TestData.html

I'd prefer to leave sample as-is, size is an important part of how FsCheck works.

QuickCheck generators also uses size in almost exactly the same way, it's just that the implementation of QuickCheck's sample chooses size for you.

@moodmosaic

This comment has been minimized.

Show comment
Hide comment
@moodmosaic

moodmosaic Feb 19, 2015

Contributor

Thank you! That makes sense.

Contributor

moodmosaic commented Feb 19, 2015

Thank you! That makes sense.

@moodmosaic moodmosaic closed this Feb 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment