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

IntegerRangeRandomizer does not generate random values in the given range #241

Closed
ysimhadri opened this issue Feb 21, 2017 · 8 comments
Closed
Labels
Milestone

Comments

@ysimhadri
Copy link

Thank you for taking time to open this issue 😄

Please provide as much context as possible to help us fixing the issue (at least random-beans version you are using).

  • If you are reporting a bug, the best way is to provide a failing test.
  • If you are requesting a feature, don't hesitate to explain in detail your suggestion with code examples.
  • If you have a question, please first check if there is no (closed) issue about it. You may ask your question on the Gitter channel of the project.

Many thanks upfront!

@fmbenhassine
Copy link
Member

fmbenhassine commented Feb 22, 2017

Hi,

Can the EnhancedRandomBuilder only genearate positive values for integer datatypes

Yes, here is an example of how to do that:

EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
                .randomize(Integer.class, new IntegerRangeRandomizer(0, 100))
                .build();

Kind regards
Mahmoud

@ysimhadri
Copy link
Author

I am getting back negative values.Drilled down the code.
FieldPopulator

void populateField(final Object target, final Field field, final PopulatorContext context) throws IllegalAccessException {
Randomizer<?> randomizer = randomizerProvider.getRandomizerByField(field);
if (randomizer instanceof SkipRandomizer) {
return;
}
context.pushStackItem(new PopulatorContextStackItem(target, field));
if(!context.isExceedRandomizationDepth()) {
Object value;
if (randomizer != null) {
value = randomizer.getRandomValue(); IntegerRandomizer is showing up instead of IntegerRangeRandomizer
} else {
value = generateRandomValue(field, context);
}
setProperty(target, field, value);
}
context.popStackItem();
}

@fmbenhassine
Copy link
Member

Hi,

Thank you for reporting this issue! Indeed, this is a bug in random beans.
We'll fix it asap and keep you informed.

Kind regards
Mahmoud

@fmbenhassine fmbenhassine changed the title This is a feature I am talking about.Can the EnhancedRandomBuilder only genearate positive values for integer datatypes IntegerRangeRandomizer does not generate random values in the given range Feb 23, 2017
@fmbenhassine fmbenhassine added this to the 3.6.0 milestone Feb 23, 2017
@fmbenhassine
Copy link
Member

Hi,

I've deployed version 3.6.0-SNAPSHOT to maven central with a fix for this issue.
Could you please give it a try and tell me if this is ok for you?

Kind regards
Mahmoud

@fmbenhassine
Copy link
Member

Any update on this?

@fmbenhassine
Copy link
Member

No updates, so I'm closing this issue.
The fix will be part of v3.6

@ysimhadri In case of any problem, you can reopen this issue and it will be addressed in next version

@driversti
Copy link

Hi. The bug still exists in 3.7.0 for Long

@fmbenhassine
Copy link
Member

Hi. The bug still exists in 3.7.0 for Long

@driversti The fix for this issue (75318b0) covers the Long type and the test io.github.benas.randombeans.randomizers.range.LongRangeRandomizerTest#generatedValueShouldBeWithinSpecifiedRange never fails on my end (I use IntelliJ's feature "Run Test Until Failure") at least with the current snapshot 3.8.0-SNAPSHOT.

Can you please give it a try (see here on how to use the snapshot version) and let me know if you still have the issue? Thank you upfront!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants