Quantcast
Channel: User Tarmil - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Answer by Tarmil for Generating custom data in FsCheck

$
0
0

To always generate valid Quality and ShelfLife, you need to register Arbitrary instances:

type Arbs =    static member Quality() =        Arb.Default.NonNegativeInt()        |> Arb.convert (fun (NonNegativeInt x) -> Quality x) (fun (Quality x) -> NonNegativeInt x)    static member ShelfLife() =        Arb.Default.NonNegativeInt()        |> Arb.convert (fun (NonNegativeInt x) -> ShelfLife x) (fun (ShelfLife x) -> NonNegativeInt x)Arb.register<Arbs>()

For the actual property you want to check, here's a rewording that will help translate it to FsCheck: IF Style is not Legendary, THEN after 100 days the quality is 0. In code:

let ``Non-legendary item breaks after 100 days`` (item: Item) =    (item.Style <> Legendary) ==>        let agedItem = item |> repeat 100 decreaseQuality        agedItem.Quality = Quality 0

Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>