Further comparison operations and test implemented

This commit is contained in:
Fabian Joswig 2021-10-18 13:07:33 +01:00
parent 8d7a5daafa
commit 0c83f7a607
2 changed files with 16 additions and 0 deletions

View file

@ -485,9 +485,21 @@ class Obs:
def __lt__(self, other):
return self.value < other
def __le__(self, other):
return self.value <= other
def __gt__(self, other):
return self.value > other
def __ge__(self, other):
return self.value >= other
def __eq__(self, other):
return (self - other).is_zero()
def __ne__(self, other):
return not (self - other).is_zero()
# Overload math operations
def __add__(self, y):
if isinstance(y, Obs):

View file

@ -26,6 +26,10 @@ def test_comparison():
test_obs2 = pe.pseudo_Obs(value2, 0.1, 't')
assert (value1 > value2) == (test_obs1 > test_obs2)
assert (value1 < value2) == (test_obs1 < test_obs2)
assert (value1 >= value2) == (test_obs1 >= test_obs2)
assert (value1 <= value2) == (test_obs1 <= test_obs2)
assert test_obs1 == test_obs1
assert test_obs1 != test_obs2
def test_function_overloading():