qala-io / datagen

Java lib that generates random data (numbers, strings, dates) - mostly to facilitate Randomized Testing.
http://qala.io/blog/randomized-testing.html
Apache License 2.0
60 stars 5 forks source link

Provide a way of generating a list of values with specific characteristics #18

Closed php-coder closed 5 years ago

php-coder commented 6 years ago

We have many methods for generating just a single value but it would be super useful to provide an API for generating a list (or set) of value with some characteristics.

Maybe something like this:

List<Integer> ints = RandomList.ofLength(between(1, 5)).withValues(between(1, 10));

Another option is to leverage Java 8 streams API and have a method that takes a function that produce some value and invokes this function N times.

ctapobep commented 6 years ago

The API that you're looking for may already exist:

length(5).alphanumerics(500)
php-coder commented 6 years ago

Ok, thanks! I'll try to use it but it still doesn't cover the case when I have a custom object generator.

php-coder commented 6 years ago

I've just tried to refactor some my helpers and I gave up. Because my understanding how it should be didn't work with the library API at least once, now I can't fully trust it. Also I can't read about these methods because there is no API docs.

For example, I found that there is numerics() method but I don't know what it does. Instead of having frustration with API each time, I started to think that it's better to write my own random generators.. :-(

ctapobep commented 6 years ago

I found that there is numerics() method but I don't know what it does.

I thought the API for this particular method was pretty straightforward:

> between(4, 6).with(spacesLeft(2)).numerics(3)
"  8467", "  231", "  72"

Is there something confusing?

I started to think that it's better to write my own random generators

That's perfectly fine. There won't be any library that satisfies all your needs. Datagen could be used either for widespread cases or to help you build your own randomization utilities helpful for your domain.

Also I can't read about these methods because there is no API docs.

JavaDocs will be added with time. I agree that this should be done, I just don't have much time/inspiration to work on the lib right now. But do you need JavaDocs that badly? Most of the methods in the lib are 1-5 lines long. Even for those that have JavaDocs it could be easier to read source code.