testing - Force FsCheck to generate NonEmptyString for discriminating union fields of type string -


i'm trying achieve following behaviour fscheck: i'd create generator generate instance of myunion type, every string field being non-null/empty.

type mynestedunion =     | x of string     | y of int * string  type myunion =     | of int * int * string * string     | b of mynestedunion 

my 'real' type larger/deeper myunion, , fscheck able generate instance without problem, string fields of union cases empty. (for example might generate b (y (123, "")))

perhaps there's obvious way of combining fscheck's nonemptystring , support generating arbitrary union types i'm missing?

any tips/pointers in right direction appreciated.

thanks!

this goes against grain of property based testing (in explicitly prevent valid test cases being generated), wire non-empty string generator used strings:

type alt =     static member nonemptystring () : arbitrary<string> =         arb.default.nonemptystring()         |> arb.convert             (fun (nes : nonemptystring) -> nes.get)             nonemptystring.nonemptystring  arb.register<alt>()  let g = arb.generate<myunion>  gen.sample 1 10 g 

note you'd need re-register default generator after test since mappings global.

a more by-the-book solution use default derived generator , filter values contain invalid strings (i.e. use ==>), might find not feasible particularly deep nested types.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -