quicktheories / QuickTheories

Property based testing for Java 8
Apache License 2.0
505 stars 51 forks source link

Generate.oneOff(..) #28

Closed merlijn closed 6 years ago

merlijn commented 7 years ago

We are developing a course for property based testing (for java & scala) and are using scalacheck for scala and this library for the java side. We like it very much since it is more functional, using java 8 lambdas. Since the 0.20 release we think it is greatly improved.

While we don't think you should copy everything from scalaCheck, some nice features we are 'missing' (would like to see/use):

  // picking a random generator from a list
  - Gen<T> Generate.oneOff(List<Gen<T>> generators)
  // flatmapping on a Gen
  - Gen<A> Gen.flatMap(Function<T, Gen<A>> fn)

What do you think?

hcoles commented 7 years ago

Glad you like it - we're also think 0.20 is a step in the right direction although there are going to be some teething troubles as it was a large change (be sure to update to v0.21 there was a fairly major issue in 0.20 I've not had chance to write up yet).

I think copying good ideas from elsewhere is an excellent idea.

Both flatMap and oneOf make sense.

Flatmap ought to be straightforward. Implementing oneOf would be difficult to do while maintaining the current behaviour of always visiting the maxima, minima and shrink point of each Gen. Whether or not this is important/worth introducing complexity for is debatable.

Out of interest where will the course run?

merlijn commented 7 years ago

Thanks for the quick response. We noticed you were working on the project and made a release today :)

Regarding your question on the course. It will be an internal one at the company (ING) we are working currently. It will target both scala/java developers.

Btw, I just opened a pull request for the oneOf(..), the implementation might be too naive though.

hcoles commented 6 years ago

This is now released in 0.23 along with a default mix method on Gen that takes a weighting allowing uneven mixes of Gens.