diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-09-25 14:07:34 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-09-25 14:07:34 +0200 |
commit | 2daf526b84a1e746a222668f02578a2fdba0e992 (patch) | |
tree | 2b7e3a1e8fe21ec5809662810bbdd36ac4ebc426 | |
parent | 394573a3605ee7ddfe9659c0f91a994436ece91d (diff) | |
download | ee-python-2daf526b84a1e746a222668f02578a2fdba0e992.tar.gz ee-python-2daf526b84a1e746a222668f02578a2fdba0e992.tar.bz2 ee-python-2daf526b84a1e746a222668f02578a2fdba0e992.tar.xz ee-python-2daf526b84a1e746a222668f02578a2fdba0e992.zip |
o Better implementation of EeVal's __eq__ and __lt__.
-rw-r--r-- | src/ee/__init__.py | 4 | ||||
-rw-r--r-- | test/test_EeVal.py | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/ee/__init__.py b/src/ee/__init__.py index 0450c40..1eb79d0 100644 --- a/src/ee/__init__.py +++ b/src/ee/__init__.py @@ -60,10 +60,10 @@ class EeVal(object): return self._unit def __eq__(self, other): - return ((self._value, self._unit) == (other._value, other._unit)) + return ((self.__float__(), self._unit) == (other.__float__(), other._unit)) def __lt__(self, other): - return ((self._value, self._unit) < (other._value, other._unit)) + return ((self.__float__(), self._unit) < (other.__float__(), other._unit)) def __str__(self): return eng_str(self.__float__(), self._unit) diff --git a/test/test_EeVal.py b/test/test_EeVal.py new file mode 100644 index 0000000..c4254fb --- /dev/null +++ b/test/test_EeVal.py @@ -0,0 +1,9 @@ +from ee import EeVal + +def test_ordering(): + p100 = EeVal('100 p') + n100 = EeVal('100 n') + u1 = EeVal('1u') + assert n100 > p100 + assert p100 < n100 + assert [p100, n100, u1] == sorted([p100, u1, n100]) |