Last active
August 29, 2015 14:09
-
-
Save kjnilsson/8c8e4c86fc5ea316c3e0 to your computer and use it in GitHub Desktop.
FsCheck problem/query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "./bin/Debug/FsCheck.dll" | |
open System | |
open FsCheck | |
//ensure fscheck is fully initialised. | |
Runner.init.Force() | |
let whiteList = | |
let x = ['a' .. 'z'] @ ['A' .. 'Z'] | |
Gen.choose (0, x.Length - 1) | |
|> Gen.map (fun i -> x.[i]) | |
type SafeString = SafeString of string with | |
member x.Get = match x with SafeString r -> r | |
override x.ToString() = x.Get | |
type UriGenerator = | |
static member SafeString() = | |
Gen.map (fun (chars:char[]) -> String(chars)) (Gen.arrayOf whiteList) | |
|> Arb.fromGen | |
|> Arb.filter (fun s -> not (String.IsNullOrEmpty s)) | |
|> Arb.convert SafeString string | |
Arb.register<UriGenerator> | |
// works as expected | |
Gen.sample 10 10 (UriGenerator.SafeString().Generator) | |
// returns SafeStrings but not using the defined 'safe' generator above | |
Gen.sample 10 10 (Arb.generate<SafeString>) |
Bah I found it needed to be Arb.register()
As you were. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using Arb.generate the strings returned aren't "safe" and appear to use the default string generator.