简体   繁体   中英

FSCheck shrinker isn't called

I can't seem to get the FSCheck shrinker to work. Say I have this

    let arb_chars =
        Arb.fromGenShrink(
            Arb.generate<char[]>,
            fun cs -> seq {
                printfn "shrinking..."
                for i in 0..(cs.Length) do
                    printfn "  shrink %d" i
                    yield [| cs.[0] |]
            })

    let prop_len() = gen {
        //let! a = Arb.generate<char[]> // this doesn't work either...
        let! a = arb_chars.Generator
        let len = a.Length
        printfn "a.Length = %A" len
        return (len <> 5)
    }
    :
    Check.One(config, prop_len)

When I run it, I always get 0 shrinks. Here's a typical run:

a.Length = 0
a.Length = 4
a.Length = 1
a.Length = 0
a.Length = 4
a.Length = 7
a.Length = 6
a.Length = 7
a.Length = 19
a.Length = 18
a.Length = 5
Falsifiable, after 11 tests (0 shrinks) (StdGen (19971972,296557937)):
Original:
<null>

Use Prop.ForAll to define your property and use the custom generator/shrinker. Something like this (sorry typing from memory but should be close)

let prop_len = Prop.ForAll (arb_chars) 
    (fun a ->
        let len = a.Length
        printfn "a.Length = %A" len
        return (len <> 5)
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM