When implementing property-based testing, when should I use an input generator over a precondition expression?

When implementing property-based testing, when should I use the input generator over the precondition expression?

Are there any performance considerations when choosing a particular option?

Inside, does one method inevitably use another?

I would think that the expression of the precondition would take longer than the input generator. Has anyone checked this out?

Why do we need both?

+4
source share
1 answer

precondition (, FsCheck ==>), . , 1 ( 100, FsCheck).

100, , .

, , . , , , x > 0, FsCheck , 50% . , (, , : ).

FsCheck , , .

FizzBuzz kata, FizzBuzz, :

[<Property(MaxFail = 2000)>]
let ``FizzBuzz.transform returns FizzBuzz`` (number : int) =
    number % 15 = 0 ==> lazy
    let actual = FizzBuzz.transform number
    let expected = "FizzBuzz"
    expected = actual

MaxFail. , , , 14 15 . FsCheck 1000 , , 14 15 , 67 , . FsCheck 100 , .

MaxFail, . 2000 , 133 .

, :

[<Property(QuietOnSuccess = true)>]
let ``FizzBuzz.transform returns FizzBuzz`` () =
    let fiveAndThrees =
        Arb.generate<int> |> Gen.map ((*) (3 * 5)) |> Arb.fromGen
    Prop.forAll fiveAndThrees <| fun number ->

        let actual = FizzBuzz.transform number

        let expected = "FizzBuzz"
        expected = actual

ad-hoc . , .

, , unmatching . .

+8

All Articles