You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
Haixing-Hu
pushed a commit
to Haixing-Hu/easy-random
that referenced
this issue
May 7, 2020
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
changed the title
LocalDateTimeRangeRandomizer generates a random LocalDateTime with the precision of nanoseconds
Inconsistent nanosecond precision between LocalTimeRangeRandomizer and LocalDateTimeRangeRandomizer
Oct 22, 2020
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!
While the
LocalDateTimeRandomizer
,LocalTimeRandomizer
, andLocalTimeRangeRandomizer
generate date time values with the precision of seconds. Therefore theLocalDateTimeRangeRandomizer
should also generate aLocalDateTime
with the precision of seconds.The following test cases will show the problem.
The text was updated successfully, but these errors were encountered: