fscheck

How do I write a FsCheck generator for an interface in C#

偶尔善良 提交于 2019-12-10 19:22:54
问题 Suppose I have an interface IPerson with 2 read properties age (int) and name (string). I also have a class Person implementing IPerson. How do I write a FsCheck generator for generating instances of IPerson type? 回答1: Something like the below should work: Gen<IPerson> gen = from age in Arb.Default.Int32().Generator from name in Arb.Default.String().Generator select new Person(age, name) as IPerson; 来源: https://stackoverflow.com/questions/35203290/how-do-i-write-a-fscheck-generator-for-an

How to generate null strings for FsCheck tests

五迷三道 提交于 2019-12-10 13:03:34
问题 Using FsCheck, the F# version of the Haskell QuickCheck test library, to generate tests from C#, I found that the random string generator does not generate the null string. using FsCheck.Fluent; Spec.ForAny<string>(s => s != null).QuickCheck(); // always pass Furthermore, there seems not to handle null strings by design, but I have not managed to pin it down from the documentation. For example, just picking between two strings, one of them null, won't work: var strings = Any.ValueIn<string>

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 =

fscheck doesn't generate random enough data

巧了我就是萌 提交于 2019-12-08 22:13:07
问题 I'm playing with FsCheck so I have this implementation: let add a b = if a > 100 then failwith "nasty bug" else a + b ...and this FsCheck based test: fun (a:int) -> (add a 0) = a |> Check.QuickThrowOnFailure and the test never fails. My guess is that the 100 values produced by the random generator are never bigger than 100. Shouldn't the values be more "random"? 回答1: When you use Check.QuickThrowOnFailure , it uses the configuration Config.QuickThrowOnFailure , which has these values: >

Exception upon using FsCheck

孤街醉人 提交于 2019-12-08 07:40:53
问题 Upon running with xUnit the simplest test from FsCheck open FsCheck [<Property>] let revRevIsOrig (xs:list<int>) = List.rev(List.rev xs) = xs I receive the exception ---- System.InvalidCastException : Unable to cast object of type 'FsList@303[System.Int32]' to type 'FsCheck.Arbitrary`1[Microsoft.FSharp.Collections.FSharpList`1[System.Int32]]'. I tried to catch the exception and debug, but occurs before Would anyone have any clue on how to solve this ? Way to reproduce: make a new project

How to use FsCheck to generate random numbers as input for property-based testing

自闭症网瘾萝莉.ら 提交于 2019-12-06 02:47:55
问题 I thought it's time to try out FsCheck but it proves tougher than I thought. There's a lot of documentation on Arb , generators and so on, but there doesn't seem to be any guidance in how to apply that knowledge. Or I'm just not getting it. What may make it harder to grasp is that the relation between tests, properties, generators, arbitraries, shrinking and, in my case, randomness (some tests automatically generate random data, others don't) is not clear to me. I don't have a Haskell

How to use FsCheck to generate random numbers as input for property-based testing

被刻印的时光 ゝ 提交于 2019-12-04 09:36:01
I thought it's time to try out FsCheck but it proves tougher than I thought. There's a lot of documentation on Arb , generators and so on, but there doesn't seem to be any guidance in how to apply that knowledge. Or I'm just not getting it. What may make it harder to grasp is that the relation between tests, properties, generators, arbitraries, shrinking and, in my case, randomness (some tests automatically generate random data, others don't) is not clear to me. I don't have a Haskell background so that doesn't help much either. Now for the question: how do I generate random integers? My test

how to use xUnit and FsCheck with IoC and mocking in F#

∥☆過路亽.° 提交于 2019-12-04 06:40:46
问题 I want to write unit tests F# using property base testing technic. however I came across several obstacle. Code I want to test is in C# Domain objects come from EF i.e. no constructors only mutable properties sut is a class that will require a lot of constructor injections. Their number will change quite frequently as we add new functions. We do not want to change old tests when we add new parameter to constructor. sut already exists and is working so changing it pattern to take only one

How does one generate a “complex” object in FsCheck?

烂漫一生 提交于 2019-12-01 03:27:11
I'd like to create an FsCheck Generator to generate instances of a "complex" object. By complex, I mean an existing class in C# that has a number of child properties and collections. These properties and collections in turn need to have data generated for them. Imagine this class was named Menu with child collections Dishes and Drinks (I'm making this up so ignore the crappy design). I want to do the following: Generate a variable number of Dishes and a variable number of Drinks . Generate the Dish and Drink instances using the FsCheck API to populate their properties. Set some other primitive

How does one generate a “complex” object in FsCheck?

旧巷老猫 提交于 2019-11-30 23:13:06
问题 I'd like to create an FsCheck Generator to generate instances of a "complex" object. By complex, I mean an existing class in C# that has a number of child properties and collections. These properties and collections in turn need to have data generated for them. Imagine this class was named Menu with child collections Dishes and Drinks (I'm making this up so ignore the crappy design). I want to do the following: Generate a variable number of Dishes and a variable number of Drinks . Generate