elm-explorations / test

Write unit and fuzz tests for Elm code.
https://package.elm-lang.org/packages/elm-explorations/test/latest
BSD 3-Clause "New" or "Revised" License
236 stars 40 forks source link

Hash fuzzed input to detect duplicates? #11

Open mgold opened 6 years ago

mgold commented 6 years ago

When generating random values from a fuzzer, there is no guarantee that each one will be unique. You may ask for 100 cases but get less. It may be possible you get much less.

One solution is to hash each input, store the hashes, and reject inputs with a duplicate hash. We'd need to fail the test after some number of failed attempts to create distinct inputs, perhaps max 20 (2*numberOfRequestedRuns).

Since we'd want a designated union type tag for this failure condition, it makes sense to do this while we're doing a major revision.

Is there any interest in exploring this idea?

drathier commented 6 years ago

There definitely is, but I'd like to pair this with knowing roughly how many possible values a fuzzer can produce. No reason to keep generating booleans to try to find a third value. Also, we probably want to generate more values if we're fuzzing a huge thing, like a Dict (Int, Int) (List String).

Janiczek commented 2 years ago

No reason to keep generating booleans to try to find a third value.

The status quo is that you still keep generating booleans, and run the toExpectation function to boot.

I think we could do this optimization separately (retry generating if we've already tested an input for a test -- skipping some toExpectation calls), and then there is the separate issue of generating all values exhaustively if the fuzzer allows it. I'll create an issue for that one as I and @gampleman have some thoughts around it already :)

Edit: #188