Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Add listOfLength for fuzzing lists with a specific length #216

Open
rhofour opened this issue Nov 24, 2017 · 2 comments
Open

Add listOfLength for fuzzing lists with a specific length #216

rhofour opened this issue Nov 24, 2017 · 2 comments
Labels

Comments

@rhofour
Copy link

rhofour commented Nov 24, 2017

I was thinking something like:
listOfLength: Int -> Fuzzer a -> Fuzzer (List a)

This looks like it shouldn't be too hard to generalize from the existing list function. The major benefit would be to allow users to decide their own probability distribution over the generated list length (using something like Fuzz.andThen). This is what motivated me to suggest this and it would limit the severity of #168 .

This is already possible with what's provided, but it could be easier:

listOfLength : Int -> Fuzzer a -> Fuzzer (List a)
listOfLength listLen fuzzer =
    List.foldl
        (Fuzz.map2 (\elem -> \list -> elem :: list))
        (Fuzz.constant [])
        (List.repeat listLen fuzzer)
@MartinKavik
Copy link

Hi, it would be nice to have even more flexibility:

listRange: Int -> Int -> Fuzzer a -> Fuzzer (List a)
listRange lo hi fuzzer =
   ...

It can favour shorter lists like the current Fuzz.list.


I'm creating combinatorics library, so my use-case is:

        , fuzz
            (( char, intRange 0 3 )
                |> tuple
                |> listOfLength 3
             -- listRange 0 3 would be better
            )
            "permutations with repetitions"
          <|
            \setWithCounts ->
                -- setWithCounts = e.g. [("a",2), ("x",5)]
        ...

Thanks!

@mgold
Copy link
Member

mgold commented Jan 23, 2018

If we're going to do this, and I'm not saying we are, why not: Fuzzer Int -> Fuzzer a -> Fuzzer (List a)?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants