property-based-testing

@composite vs flatmap in complex strategies

£可爱£侵袭症+ 提交于 2020-08-10 16:39:07
问题 hypothesis allows two different ways to define derived strategies, @composite and flatmap . As far as I can tell the former can do anything the latter can do. However, the implementation of the numpy arrays strategy, speaks of some hidden costs # We support passing strategies as arguments for convenience, or at least # for legacy reasons, but don't want to pay the perf cost of a composite # strategy (i.e. repeated argument handling and validation) when it's not # needed. So we get the best of

jqwik pairs of sorted array with some element of it

喜夏-厌秋 提交于 2020-02-25 09:36:29
问题 Following code aims to generate random sorted array, and key as one element of that array. But I do not know the issue, the keys are not in the array? @Provide Arbitrary<Map<Integer, Integer[]>> llstPairs() { // sortedArrayGenerator is generattor that return Arbitrary<Integer[]> sorted values // and it works fine Arbitrary<Integer[]> vals = sortedArrayGenerator(); Integer[] sample = vals.sample(); Arbitrary<Integer> key = Arbitraries.samples(sample); return Arbitraries.maps(key,vals); } Why

jqwik pairs of sorted array with some element of it

北城余情 提交于 2020-02-25 09:34:21
问题 Following code aims to generate random sorted array, and key as one element of that array. But I do not know the issue, the keys are not in the array? @Provide Arbitrary<Map<Integer, Integer[]>> llstPairs() { // sortedArrayGenerator is generattor that return Arbitrary<Integer[]> sorted values // and it works fine Arbitrary<Integer[]> vals = sortedArrayGenerator(); Integer[] sample = vals.sample(); Arbitrary<Integer> key = Arbitraries.samples(sample); return Arbitraries.maps(key,vals); } Why

jqwik pairs of sorted array with some element of it

北慕城南 提交于 2020-02-25 09:33:10
问题 Following code aims to generate random sorted array, and key as one element of that array. But I do not know the issue, the keys are not in the array? @Provide Arbitrary<Map<Integer, Integer[]>> llstPairs() { // sortedArrayGenerator is generattor that return Arbitrary<Integer[]> sorted values // and it works fine Arbitrary<Integer[]> vals = sortedArrayGenerator(); Integer[] sample = vals.sample(); Arbitrary<Integer> key = Arbitraries.samples(sample); return Arbitraries.maps(key,vals); } Why

Pattern for generating negative Scalacheck scenarios: Using property based testing to test validation logic in Scala

China☆狼群 提交于 2019-12-22 08:43:32
问题 We are looking for a viable design pattern for building Scalacheck Gen (generators) that can produce both positive and negative test scenarios. This will allow us to run forAll tests to validate functionality (positive cases), and also verify that our case class validation works correctly by failing on all invalid combinations of data. Making a simple, parameterized Gen that does this on a one-off basis is pretty easy. For example: def idGen(valid: Boolean = true): Gen[String] = Gen.oneOf(ID

Why is my precondition being ignored on my Property-based test?

佐手、 提交于 2019-12-13 01:13:54
问题 Why is my precondition being ignored on my Property-based test? The precondition for my test is the following: fun rowCount -> rowCount >= 0 Thus, my actual test is: [<Fact>] let ``number of cells in grid equals rowcount squared`` () = Check.QuickThrowOnFailure <| fun rowCount -> rowCount >= 0 ==> fun rowCount -> rowCount |> createGrid |> Map.toList |> List.length = rowCount * rowCount However, my test continues to fail: Result Message: System.Exception : Falsifiable, after 3 tests (1 shrink)

Generating unique strings in FsCheck

心已入冬 提交于 2019-12-12 14:42:46
问题 I need generate unique non- null strings to be used as Dictionary keys. I tried something like: public static Gen<NonNull<string>> UniqueStrings() { return from s in Arb.Default.NonNull<string>().Generator select s; } Then I use UniqueString() in: public static Arb<Foo> Foos() { // Foo's constructor will use the string parameter // as key to an internal Dictionary return (from nonNullString in UniqueStrings() select new Foo(nonNullString.Item)).ToArbitrary(); } However, I get an exception in

Example that shows the limitations of integrated shrinking

廉价感情. 提交于 2019-12-11 05:13:57
问题 I just watched a video that presents the notion of integrated shrinking for property based tests. The approach seems to have some advantages over type directed shrinking , however it was pointed out in this reddit thread that the integrated shrinking approach does not fit well in the case of monadic generators: Doing shrinking in your way does not fit well with a monadic style for generators. Here is an example, consider generating an arbitrary list (ignore termination for now): do x <-

Haskell: Property Based Testing for Higher Order Function

痴心易碎 提交于 2019-12-11 05:13:38
问题 I have two properties that a function foo must satisfy: prop_1 :: [Int] -> Bool prop_1 xs = foo xs id == xs prop_2 :: [Int] -> (Int -> Int) -> (Int -> Int) -> Bool prop_2 xs f g = foo (foo xs f) g == foo xs (g . f) I am trying to check whether the above properties satisfy the following function using quickCheck: foo :: [a] -> (a -> b) -> [b] foo xs f = [] When I tried running quickCheck with prop_2 I get the following error: quickCheck(prop_2) <interactive>:18:1: error: No instance for (Show

Generating random objects as test cases

会有一股神秘感。 提交于 2019-12-10 11:46:12
问题 This question is part of larger question that can be found here We have classes that come from Entity Framework. In other words they are not Records that are immutable they are quite posit list of mutable properties without constructor. FsCheck cannot deal with such entities out of the box and for each entity we are forced to write separate generator like so: let BLOGen = gen { let! cat = Gen.choose(0, 1000) let! opt = Gen.choose(0, 1000) let! name = Arb.Default.String().Generator let! dVal =