Skip to content

Commit

Permalink
Merge pull request #202 from OpenBioSim/backport_201
Browse files Browse the repository at this point in the history
Backport fix from PR #201
  • Loading branch information
lohedges authored Nov 13, 2023
2 parents 6d8cb2b + 8f3309c commit 56dca87
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
20 changes: 0 additions & 20 deletions python/BioSimSpace/Sandpit/Exscientia/Types/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,26 +388,6 @@ def __eq__(self, other):
else:
return False

def __ne__(self, other):
"""Not equals to operator."""

# Compare to another object of the same type.
if type(other) is type(self):
return _math.isclose(
self._to_default_unit().value(),
other._to_default_unit().value(),
)

# Compare with a string.
elif isinstance(other, str):
return not _math.isclose(
self._to_default_unit().value(),
self._from_string(other)._to_default_unit().value(),
)

else:
return True

def __ge__(self, other):
"""Greater than or equal to operator."""

Expand Down
20 changes: 0 additions & 20 deletions python/BioSimSpace/Types/_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,26 +388,6 @@ def __eq__(self, other):
else:
return False

def __ne__(self, other):
"""Not equals to operator."""

# Compare to another object of the same type.
if type(other) is type(self):
return _math.isclose(
self._to_default_unit().value(),
other._to_default_unit().value(),
)

# Compare with a string.
elif isinstance(other, str):
return not _math.isclose(
self._to_default_unit().value(),
self._from_string(other)._to_default_unit().value(),
)

else:
return True

def __ge__(self, other):
"""Greater than or equal to operator."""

Expand Down
18 changes: 18 additions & 0 deletions tests/Sandpit/Exscientia/Types/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,21 @@ def test_container_mul(Type):

# Assert we have a container of the original type.
assert all(isinstance(x, Type) for x in container)


@pytest.mark.parametrize("Type", types)
def test_operators(Type):
"""Test equality/inequality operators."""

t0 = Type(1.0, Type._default_unit)
t1 = Type(2.0, Type._default_unit)
t2 = Type(3.0, Type._default_unit)

assert t0 == t0
assert t0 <= t0
assert t0 >= t0
assert t0 != t1
assert t0 < t1
assert t1 > t0
assert t1 < t2
assert t2 > t1
18 changes: 18 additions & 0 deletions tests/Types/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,21 @@ def test_container_mul(Type):

# Assert we have a container of the original type.
assert all(isinstance(x, Type) for x in container)


@pytest.mark.parametrize("Type", types)
def test_operators(Type):
"""Test equality/inequality operators."""

t0 = Type(1.0, Type._default_unit)
t1 = Type(2.0, Type._default_unit)
t2 = Type(3.0, Type._default_unit)

assert t0 == t0
assert t0 <= t0
assert t0 >= t0
assert t0 != t1
assert t0 < t1
assert t1 > t0
assert t1 < t2
assert t2 > t1

0 comments on commit 56dca87

Please sign in to comment.