Skip to content

Commit

Permalink
Fix union of adjacent ranges with upper_inc=True
Browse files Browse the repository at this point in the history
* Closes #11
* Includes a test case
* Changelog updated, version bumped
  • Loading branch information
MichiK authored and runfalk committed Jul 23, 2018
1 parent 1bab1c5 commit b2d83c5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ first `0.1` release does not properly adhere to this. Unless explicitly stated,
changes are made by `Andreas Runfalk <https://github.com/runfalk>`_.


Version 1.0.2
-------------
Released on 20th July, 2018

- Fixed :meth:`~spans.types.Range.union` when ``upper_inc`` is set to ``True``
(`bug #11 <https://github.com/runfalk/spans/issues/11>`_,
`Michael Krahe <https://github.com/der-michik>`_)


Version 1.0.1
-------------
Released on 31st January, 2018
Expand Down
2 changes: 1 addition & 1 deletion spans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""


__version__ = "1.0.1"
__version__ = "1.0.2"


__all__ = [
Expand Down
3 changes: 2 additions & 1 deletion spans/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ def union(self, other):
else:
a, b = other, self

if a.upper <= b.lower and not a.adjacent(b):
if (a.upper < b.lower or a.upper == b.lower and not
a.upper_inc and not b.lower_inc) and not a.adjacent(b):
raise ValueError("Ranges must be either adjacent or overlapping")

# a.lower is guaranteed to be the lower bound, but either a.upper or
Expand Down
10 changes: 10 additions & 0 deletions tests/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,13 @@ def test_bug10_missing_slots_in_cls_hierarchy(cls):
if c is object:
continue
assert hasattr(c, "__slots__")

def test_bug11_valid_union_call_detected_as_invalid():
"""
`Bug #11 <https://github.com/runfalk/spans/issues/11>`_
"""
start, middle, end = 0.0, 1.0, 2.0
a = floatrange(start, middle, upper_inc=True)
b = floatrange(middle, end)

assert a.union(b) == floatrange(start, end)

0 comments on commit b2d83c5

Please sign in to comment.