Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

@adamgfraser adamgfraser commented Sep 8, 2019

Adds small, medium, and large sized combinators for generators to generate a distribution of sizes based on the size parameter. The large combinator mimics the current behavior and with the size configured at 100 generates uniform sizes between 0 and 100. The medium combinator uses an exponential distribution and so generate values between 0 and 100 but with most values towards the smaller end of the range and some larger values. The small combinator uses a logarithmic distribution and generates values between 0 and 7 with the default configuration.

I changed the collection generators like listOf to use new medium combinator. I think this should be a win-win in terms of performance and test coverage. We will be generating fewer larger collections which should speed up tests. And there are a lot of bugs that can be easier to catch with smaller collections that I don't think we weren't testing enough before.

Resolves #1601.

@adamgfraser adamgfraser requested a review from jdegoes September 8, 2019 18:55
ghostdogpr
ghostdogpr previously approved these changes Sep 8, 2019
* useful when the process to shrink a value is simpler than the process used
* to generate it.
*/
final def reshrink[R1 <: R, B](f: A => Sample[R1, B]): Gen[R1, B] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thinking. 👍

* Returns two raised to the specified power. If the specified power is
* negative returns zero.
*/
final def pow2(n: Int): Int = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 2.pow(n)?

* the nearest integer. If the specified integer is zero or negative returns
* zero.
*/
final def log2Ceil(n: Int): Int = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing like this in Scala / Java math lib?

* the nearest integer. If the specified integer is zero or negative returns
* zero.
*/
final def log2Floor(n: Int): Int = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also compose logs and floor, right? e.g. here

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great and sorely needed! Just a quick question about the math combinators. Otherwise, looks perfect!

@adamgfraser
Copy link
Contributor Author

Yes I think you are right about the math combinators. I went down that road because all the logarithm and power operators use Double values so I thought since we knew we only cared about integers we could be more efficient by doing bitwise operations. But doing some informal benchmarking that doesn't appear to be the case. I'll go back to using the native methods.

@jdegoes
Copy link
Member

jdegoes commented Sep 9, 2019

Looks great!

@jdegoes jdegoes merged commit 726d3c2 into zio:master Sep 9, 2019
@adamgfraser adamgfraser deleted the size branch September 10, 2019 00:32
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

Successfully merging this pull request may close these issues.

ZIO Test: Improve Use of Size Parameter in Tests

3 participants