Skip to content

Commit

Permalink
Remove redundant __ne__ operator. [closes #200]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Nov 10, 2023
1 parent 7b77a26 commit e58a9c8
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_equality(Type):
"""Test equality 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_equality(Type):
"""Test equality 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 e58a9c8

Please sign in to comment.