In FsCheck, how to generate a test record with non-negative fields?

前端 未结 2 747
予麋鹿
予麋鹿 2020-12-20 22:20

In F#, I have a record with a few fields:

    type myRecord = { a:float; b:float; c:float }

I am using FsCheck to test some properties whic

2条回答
  •  执笔经年
    2020-12-20 23:02

    You can avoid creating custom generator by using FsCheck conditional properties

    let verify_this_property (r:myRecord) =
        (r.a > 0.0 && r.b > 0.0 && r.c > 0.0) ==> lazy (myFunction r = (r.a * r.b) * r.c)
    

    Though this will result in (substantially?) slower execution of the test since FsCheck will have to discard all unsuitable test entries.

提交回复
热议问题