fscheck

IndexOutOfRangeException using FsCheck

天大地大妈咪最大 提交于 2020-03-25 18:48:08
问题 I have just started working with FsCheck and have been writing some simple tests. However I keep coming across an issue which causes Xunit to throw an exception which then kills the VS2012 test runner (tests appear to run forever). It seems as though any attempt to return a non-literal result causes this exception. Some examples: ///This will work, the test will trivially succeed and the result values ///will be available in the "test output" screen in VS2012's test explorer. let [<Property>]

How to exclude null value when using FsCheck Property attribute?

a 夏天 提交于 2019-12-24 08:58:46
问题 I need to write a simple method that receives a parameter (e.g. a string ) and does smth. Usually I'd end up with two tests. The first one would be a guard clause. The second would validate the expected behavior (for simplicity, the method shouldn't fail): [Fact] public void DoSmth_WithNull_Throws() { var sut = new Sut(); Assert.Throws<ArgumentNullException>(() => sut.DoSmth(null)); } [Fact] public void DoSmth_WithValidString_DoesNotThrow() { var s = "123"; var sut = new Sut(); sut.DoSmth(s);

How do I implement multiple argument generation using FsCheck?

拟墨画扇 提交于 2019-12-23 22:40:03
问题 How do I implement multiple argument generation using FsCheck? I implemented the following to support multiple argument generation: // Setup let pieces = Arb.generate<Piece> |> Gen.filter (isKing >> not) |> Arb.fromGen let positionsList = Arb.generate<Space list> |> Arb.fromGen I then used these arguments to test the behavior of a function that's responsible for generating move options for a given checker: // Test Prop.forAll pieces <| fun piece -> Prop.forAll positionsList <| fun

fscheck generating string with size between min & max

南楼画角 提交于 2019-12-23 10:18:38
问题 I try to write a FsCheck generator that generates strings with length in a given interval. My attempt is the following: let genString minLength maxLength = let isValidLength (s : string) = s.Length >= minLength && s.Length <= maxLength Arb.generate |> Gen.suchThat isValidLength |> Arb.fromGen ...and I get the error: "System.Exception : No instances of class FsCheck.Arbitrary`1[a] for type System.String with arguments set []" What am I doing wrong? thanks! UPDATE 1: I managed to write the

How extract the int from a FsCheck.Gen.choose

耗尽温柔 提交于 2019-12-12 21:08:06
问题 I'm new on F#, and can't see how extract the int value from: let autoInc = FsCheck.Gen.choose(1,999) The compiler say the type is Gen<int> , but can't get the int from it!. I need to convert it to decimal, and both types are not compatible. 回答1: From a consumer's point of view, you can use the Gen.sample combinator which, given a generator (e.g. Gen.choose ), gives you back some example values. The signature of Gen.sample is: val sample : size:int -> n:int -> gn:Gen<'a> -> 'a list (* `size`

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

Issues Creating Records with FsCheck

喜你入骨 提交于 2019-12-11 10:58:13
问题 This question is a follow-up to an earlier question on using FsCheck to generate records. The original question was answered with a well composed example solution. However, prior to the answer being shared, I attempted to create a generator which is included below. Unfortunately, the generated records of type QueryRequest = {Symbol: string; StartDate: DateTime; EndDate: DateTime} have the following issues: Missing symbol Start dates earlier than January 1, 2000 End dates later than January 1,

Using FsCheck to Generate Records

元气小坏坏 提交于 2019-12-11 10:57:39
问题 I'd like to use FsCheck (with XUnit) to create records of type: type QueryRequest = {Symbol: string; StartDate: DateTime; EndDate: DateTime} where Symbol is limited to 3 options - ORCL , IBM , AAPL , and StartDate and EndDate are limited to the range between January 1, 2000 and January 1, 2019 . However, I'm unclear as to how proceed. Should I use Arb.generate<T> or Arb.Default or some other utility upon which to base the generation and shrinking of the test cases? Update 1 Follow-on question

Cannot get model based test working

与世无争的帅哥 提交于 2019-12-11 05:54:34
问题 As an exercise I wanted to implement a 2-3 finger tree. That should be the perfect opportunity to try out FsCheck's model-based testing. I decided to try the newer experimental version. So far I only coded one command for the test machine because I already fail at making that work—one the other hand it keeps the post short. The full code is available on GitHub. open CmdQ open Fuchu open FsCheck open FsCheck.Experimental type TestType = uint16 type ModelType = ResizeArray<TestType> type

How to pass a Type as an attribute parameter using F# syntax?

血红的双手。 提交于 2019-12-11 00:54:59
问题 FsCheck allows a custom Arbitrary in its NUnit integration: [<Property(Verbose = true, Arbitrary= [typeof<Test.Arithmetic.MyArb>])>] static member MultiplyIdentity (x: int64) = x * 1 = x This syntax doesn't work. I feel a bit embarrassed to ask, but apparently I never needed this before: how do you specify the type in F# as an attribute parameter? Microsoft says nothing about it, nor does the Wikibooks project and I have some trouble googling this (the word type is omnipresent). Note 1: the