Class: Hegel::Generators::DatesGenerator

Inherits:
Hegel::Generator show all
Defined in:
lib/hegel/generators.rb,
sig/hegel.rbs

Overview

Hegel::Syntax::Methods#dates. A proleptic Gregorian calendar Date in [min_value, max_value], defaulting to the conventional full range (year 1 through year 9999) when either bound is omitted -- hegel-rust's own src/test_case.rs names this full_ranges::MIN_DATE/MAX_DATE, "what Hypothesis's dates() spans".

Opens no span: hegel_generate_date makes exactly one native call to produce its own value, and the header's own comment on HEGEL_LABEL_REGEX ("callers normally never open this span themselves. Likewise for the other engine-side compound draws below") covers HEGEL_LABEL_DATE too, since it sits below REGEX in that same list -- the same one-native-call, no-span-of-our-own reasoning UuidsGenerator's own comment already gives for HEGEL_LABEL_UUID.

Constant Summary collapse

MIN_DATE =

Returns:

  • (Object)
Date.new(1, 1, 1)
MAX_DATE =

Returns:

  • (Object)
Date.new(9999, 12, 31)

Instance Method Summary collapse

Methods inherited from Hegel::Generator

#filter, #map

Constructor Details

#initialize(min_value:, max_value:) ⇒ DatesGenerator

Returns a new instance of DatesGenerator.

Parameters:

  • min_value: (Object)
  • max_value: (Object)


620
621
622
623
624
# File 'lib/hegel/generators.rb', line 620

def initialize(min_value:, max_value:)
  super()
  @min_value = min_value
  @max_value = max_value
end

Instance Method Details

#do_draw(tc) ⇒ Object

Parameters:

  • tc (Object)

Returns:

  • (Object)

Raises:



626
627
628
629
630
631
632
633
634
635
# File 'lib/hegel/generators.rb', line 626

def do_draw(tc)
  min_value = @min_value || MIN_DATE
  max_value = @max_value || MAX_DATE
  raise Hegel::Error, "dates: max_value < min_value" if max_value < min_value

  year, month, day = tc.generate_date(
    [min_value.year, min_value.month, min_value.day], [max_value.year, max_value.month, max_value.day]
  )
  Date.new(year, month, day)
end