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

Add spec helper for generating (non-)overlapping spans #29

Open
izzergh opened this issue Feb 26, 2021 · 0 comments
Open

Add spec helper for generating (non-)overlapping spans #29

izzergh opened this issue Feb 26, 2021 · 0 comments

Comments

@izzergh
Copy link
Contributor

izzergh commented Feb 26, 2021

e.g.

context "span_overlap_count == 0" do

The above spec is skipped because it is not fully implemented and its functionality is essentially tested in the no overlap validator spec. BUT in AAS proper and in the systems that use it, it is common to require an overlapping span and non-overlapping span to compare with. It is done slightly differently just about everywhere.

AAS could add a helper method for specs (can't think of a non-spec use case right now) that would look like:

overlapping_span_for(span, type = :right, amount = 1)

span is an array of two dates, type is :left, :right, :inner, or :outer, and amount is any number of days (0 for "inclusive" overlap) up to the number of days the input span spans. For example,

span = [Date.new(1, 1, 2000), Date.new(2, 1, 2000)]

overlapping_span_for(span)
# => [<1/31/2000>, <2/2/2000>]

overlapping_span_for(span, type: :outer, amount: 30)
# => [<12/2/1999>, <3/2/2000>]
        |--------| <- span
    |------| <- left overlap
          |----| <- inner overlap
              |---------| <- right overlap
    |----------------| <- outer overlap

It may also be useful to add an option for a negative amount, i.e. not overlapping. Or perhaps another method entirely, to avoid confusion. I suppose it would be equivalent to...

def non_overlapping_span_for(span, type = :right, amount = 1)
  fail ArgumentError(whatever) unless [:right, :left].include? type

  fail ArgumentError(whatever) unless amount.positive? # I think "positive" comes from ActiveSupport

  overlapping_span_for(span, type, amount: -amount)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant