Home - Tags - Bookmarks - About

Write you some QuickCheck - Generating random booleans

Friday, 12 February 2016

This post is part of a series of posts on implementing a minimal version of QuickCheck from scratch. The source code is available on GitHub.

In the previous post I’ve generated random characters. In this post, I’ll be doing the same for booleans.

Two generators are required for this, which have been ported already on previous posts:

Given the above, a boolean generator can be written as:

let bool =
    Gen.oneof [ Gen.init true
                Gen.init false ]

val bool : Gen<bool>

Finally, here are some sample booleans:

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

━━━

This post has been filed under #fsharp #quickcheck

Feedback

Have feedback on this page? Let @nikosbaxevanis know on twitter. Need help or found a bug? Contact me.


© 2011-2018 Nikos Baxevanis. All written content on this site is provided under a Creative Commons ShareAlike license. All code is provided under a MIT license unless otherwise stated.