diff options
-rw-r--r-- | src/ee/__init__.py | 12 | ||||
-rw-r--r-- | test/test_EeVal.py | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/ee/__init__.py b/src/ee/__init__.py index 7f228f8..aa2c109 100644 --- a/src/ee/__init__.py +++ b/src/ee/__init__.py @@ -86,7 +86,17 @@ class EeVal(object): return math.isclose(self.__float__(), other.__float__()) and self._unit == other._unit def __lt__(self, other): - return ((self.__float__(), self._unit) < (other.__float__(), other._unit)) +# return ((self.__float__(), self._unit) < (other.__float__(), other._unit)) + + x = self.__float__() < other.__float__() + if x != 0: + return x + if self._unit is None and other._unit is None: + return 0 + if self._unit is not None and other._unit is not None: + return self._unit < other._unit + + return 1 if self.unit is not None else -1 def __str__(self): return eng_str(self.__float__(), self._unit) diff --git a/test/test_EeVal.py b/test/test_EeVal.py index 840be30..0c21133 100644 --- a/test/test_EeVal.py +++ b/test/test_EeVal.py @@ -49,9 +49,11 @@ def test_units(s, str_value, unit): def test_ordering(): p100 = EeVal('100 p') n100 = EeVal('100 n') + n100F = EeVal('100 n F') u1 = EeVal('1u') assert n100 > p100 assert p100 < n100 + assert n100F < u1 assert [p100, n100, u1] == sorted([p100, u1, n100]) def test_hash(): |