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

Inconsistent nanosecond precision between LocalTimeRangeRandomizer and LocalDateTimeRangeRandomizer #414

Closed
Haixing-Hu opened this issue May 7, 2020 · 2 comments
Labels
Milestone

Comments

@Haixing-Hu
Copy link

While the LocalDateTimeRandomizer, LocalTimeRandomizer, and LocalTimeRangeRandomizer generate date time values with the precision of seconds. Therefore the LocalDateTimeRangeRandomizer should also generate a LocalDateTime with the precision of seconds.

The following test cases will show the problem.


  @Test
  public void testEasyRandom() {
    EasyRandom random = new EasyRandom();
    final LocalDateTime datetime = random.nextObject(LocalDateTime.class);
    assertEquals(0, datetime.getNano());   // this will fail
  }

  @Test
  public void testLocalTimeRandomizer() {
    LocalDateTimeRandomizer randomizer = new LocalDateTimeRandomizer();
    final LocalDateTime datetime = randomizer.getRandomValue();
    assertEquals(0, datetime.getNano());   // this will pass
  }

  @Test
  public void testLocalTimeRangeRandomizer() {
    EasyRandomParameters parameters = new EasyRandomParameters();
    EasyRandomParameters.Range<LocalDate> dateRange = parameters.getDateRange();
    LocalDate minDate = dateRange.getMin();
    LocalDate maxDate = dateRange.getMax();
    EasyRandomParameters.Range<LocalTime> timeRange = parameters.getTimeRange();
    LocalTime minTime = timeRange.getMin();
    LocalTime maxTime = timeRange.getMax();
    LocalDateTimeRangeRandomizer randomizer = new LocalDateTimeRangeRandomizer(of(minDate, minTime), of(maxDate, maxTime));
    final LocalDateTime datetime = randomizer.getRandomValue();
    assertEquals(0, datetime.getNano());  // this will fail
  }

@fmbenhassine
Copy link
Member

Thank you for opening this issue. This is indeed inconsistent. However, instead of removing the nanosecond precision from LocalDateTimeRangeRandomizer, I would add this precision in LocalTimeRandomizer and LocalTimeRangeRandomizer.

I think it is better to make things more precise than less precise. Do you agree? If yes, please update #415 accordingly.

@fmbenhassine fmbenhassine added this to the 4.3.0 milestone Oct 22, 2020
@fmbenhassine fmbenhassine changed the title LocalDateTimeRangeRandomizer generates a random LocalDateTime with the precision of nanoseconds Inconsistent nanosecond precision between LocalTimeRangeRandomizer and LocalDateTimeRangeRandomizer Oct 22, 2020
@fmbenhassine
Copy link
Member

This has been fixed by adding nano-second precision to LocalTimeRandomizer and LocalTimeRangeRandomizer instead of removing this precision from LocalDateTimeRangeRandomizer. Thank you for raising this inconsistency!

This issue was closed.
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

2 participants