Skip to content

Commit

Permalink
Remove assertion to ensure FiniteDateRange difference
Browse files Browse the repository at this point in the history
  • Loading branch information
raulruizgarcia committed Aug 5, 2024
1 parent f49dec0 commit a13ddbf
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
88 changes: 87 additions & 1 deletion tests/test_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def test_respects_other_range_boundaries(self, other):

def test_doesnt_extend_union(self):
"""
A union of ranges should be longer than the sum of it's parts.
A union of ranges should not be longer than the sum of it's parts.
"""
# This is a weird test to include, it is added because this feels like an
# obvious risk with the implementation I have used.
Expand All @@ -886,6 +886,92 @@ def test_finite_range(self):

assert 3 in subject

class TestDifference:
def test_range_sets_overlap(self):
range_set = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 1),
end=datetime.date(2024, 10, 31),
)
]
)
other = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 1),
end=datetime.date(2024, 10, 15),
)
]
)
difference = range_set.difference(other)

assert difference == ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 15),
end=datetime.date(2024, 10, 31),
)
]
)

def test_range_sets_overlap_multiple_ranges(self):
range_set = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 1),
end=datetime.date(2024, 10, 31),
),
ranges.FiniteDateRange(
start=datetime.date(2024, 11, 1),
end=datetime.date(2024, 11, 30),
),
]
)
other = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 15),
end=datetime.date(2024, 11, 15),
)
]
)

difference = range_set.difference(other)

assert difference == ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 10, 1),
end=datetime.date(2024, 10, 15),
),
ranges.FiniteDateRange(
start=datetime.date(2024, 11, 15),
end=datetime.date(2024, 11, 30),
),
]
)

def test_difference_does_not_overlap(self):
range_set = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 1, 1),
end=datetime.date(2024, 1, 31),
)
]
)
other = ranges.RangeSet(
[
ranges.FiniteDateRange(
start=datetime.date(2024, 3, 1),
end=datetime.date(2024, 3, 31),
)
]
)
difference = range_set.difference(other)
assert difference == range_set


class TestAsFiniteDatetimePeriods:
def test_converts(self):
Expand Down
1 change: 0 additions & 1 deletion xocto/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ def intersection(self, other: Range[datetime.date]) -> Optional["FiniteDateRange
if base_intersection is None:
return None

assert base_intersection.boundaries == RangeBoundaries.INCLUSIVE_INCLUSIVE
return FiniteDateRange(base_intersection.start, base_intersection.end)

def union(self, other: Range[datetime.date]) -> Optional["FiniteDateRange"]:
Expand Down

0 comments on commit a13ddbf

Please sign in to comment.