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

Update Javadocs of range randomizers about range boundaries #419

Closed
calinafox opened this issue May 30, 2020 · 1 comment
Closed

Update Javadocs of range randomizers about range boundaries #419

calinafox opened this issue May 30, 2020 · 1 comment
Milestone

Comments

@calinafox
Copy link

calinafox commented May 30, 2020

Version: 4.2.0

Steps to reproduce:

  1. Set limit interval for LocalDateRangeRandomizer as [today-1, today+1]
  2. Generate data on a large scale: e.g. 500.000 records
  3. Validate that upper interval limit: today+1 is added in the generated list

Actual Results:
The upper interval limit: today+1 is not added in the generated list

Expected Results:
The upper interval limit: today+1 should be added in the generated list

Test example:

import org.jeasy.random.EasyRandomParameters;
import org.jeasy.random.randomizers.range.LocalDateRangeRandomizer;
import org.junit.Assert;
import org.junit.Test;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class LocalDateRandomizerTest {
    EasyRandomParameters easyRandomParameters;
    LocalDate minDate;
    LocalDate maxDate;
    LocalDate date;
    final int SEARCH_INTERVAL = 500000;

    @Test
    public void testLocalDateRandomizerLimits() {

        easyRandomParameters = new EasyRandomParameters();
        minDate = LocalDate.now().minusDays(1);
        maxDate = LocalDate.now().plusDays(1);

        LocalDateRangeRandomizer randomizer = new LocalDateRangeRandomizer(minDate,maxDate);

        List<LocalDate> localDates = new ArrayList<>();

        for (int i = 0; i < SEARCH_INTERVAL; i++) {
            date = randomizer.getRandomValue();
            localDates.add(date);
        }

        Assert.assertTrue("Upper limit interval can not be found in the generated list", localDates.contains(maxDate));

    }
}

Test Results:
Results: java.lang.AssertionError: Upper limit interval can not be found in the generated list

@fmbenhassine fmbenhassine added this to the 4.3.0 milestone Oct 16, 2020
@fmbenhassine
Copy link
Member

Thank you for opening this issue, which is actually a documentation issue. The min is inclusive and the max is exclusive (Easy Random uses a formula similar to ThreadLocalRandom.current().nextDouble(min, max) where the max is exclusive). I updated the javadocs accordingly.

@fmbenhassine fmbenhassine changed the title LocalDateRangeRandomizer- upper limit not being added in the random generated list Update Javadocs of range randomizers about range boundaries Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants