duration function

Arbitrary<Duration> duration({
  1. Duration min = Duration.zero,
  2. Duration? max,
})

Returns an arbitrary that generates Duration values.

The generated durations will be between min and max (inclusive).

If min and max are not provided, durations will range from Duration.zero to approximately 365 days.

Example:

property('durations are within bounds', () {
  forAll(duration(min: Duration(seconds: 1), max: Duration(hours: 1)), (d) {
    expect(d.inSeconds, greaterThanOrEqualTo(1));
    expect(d.inHours, lessThanOrEqualTo(1));
  });
});

Implementation

Arbitrary<Duration> duration({
  Duration min = Duration.zero,
  Duration? max,
}) {
  final maxDuration = max ?? const Duration(days: 365);
  return DurationArbitrary(
    minMicroseconds: min.inMicroseconds,
    maxMicroseconds: maxDuration.inMicroseconds,
  );
}