Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the filters option to int(), float() and to the rest of the VG functions #11

Open
MissaouiChedy opened this issue Jun 9, 2017 · 0 comments

Comments

@MissaouiChedy
Copy link

MissaouiChedy commented Jun 9, 2017

Pain point

When using the existing data generators (functions under the Pollution.VG module such as int, float, etc), it is possible to specify options such as min, max and must_have values. However, it is not possible to filter out generated values.

Proposal

Add the possibility to use the existing filters option that is not taken into account when passed to the Pollution.VG.int function, among others.

Here is an example usage:

Pollution.VG.int(filters: %{ odd: fn n -> rem(n, 2) == 0 end})

The previous filter specification causes the generator to discard odd integers.

It would be nice if we could use the filter option with all the VG functions.

Details

In my understanding, functions under the Pollution.VG module generates a State struct that acts as a specification that Pollution.Generator uses to generate random values.

Looking inside the following summarized State returned by the following call Pollution.VG.int:

%Pollution.State{
       ......,
       filters: %{}, .....}

We can see that some filter facility is already defined, but seems to be disabled.

In the lib/pollution/generator.ex file, we can see under the as_stream function that filters are fetched and applied to the resulting Stream.

However in the Pollution.Generator.Int.create function, the filters: option is ignored when creating the State struct.

Questions

  • Why is the filters: ignored?
  • Is there any non obvious concerns regarding filters: that should be addressed before implementing them?

Use case

I came across the need to generate positive integers that are powers of two (1, 2, 4, 8, 16, 32 ...) in my property based tests, the filters: option can help in achieving this behavior.

Kind Regards.

@MissaouiChedy MissaouiChedy changed the title Resources and guidelines for creating custom generators Add the filters option to the int(), float() and wherever applicable Jun 9, 2017
@MissaouiChedy MissaouiChedy changed the title Add the filters option to the int(), float() and wherever applicable Add the filters option to int(), float() and to the rest of the VG functions Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant