aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-09-25 14:48:05 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-09-25 14:48:05 +0200
commit83ce033d6413b44bc30d52043b138b449b2db3c2 (patch)
tree6b40385f1350c61c8f59d74ee2f57c8eddd6a738
parent2daf526b84a1e746a222668f02578a2fdba0e992 (diff)
downloadee-python-83ce033d6413b44bc30d52043b138b449b2db3c2.tar.gz
ee-python-83ce033d6413b44bc30d52043b138b449b2db3c2.tar.bz2
ee-python-83ce033d6413b44bc30d52043b138b449b2db3c2.tar.xz
ee-python-83ce033d6413b44bc30d52043b138b449b2db3c2.zip
o Making EeVal hashable.
-rw-r--r--src/ee/__init__.py3
-rw-r--r--test/test_EeVal.py7
2 files changed, 10 insertions, 0 deletions
diff --git a/src/ee/__init__.py b/src/ee/__init__.py
index 1eb79d0..d3885c3 100644
--- a/src/ee/__init__.py
+++ b/src/ee/__init__.py
@@ -59,6 +59,9 @@ class EeVal(object):
def unit(self):
return self._unit
+ def __hash__(self):
+ return hash((self.__float__(), self._unit))
+
def __eq__(self, other):
return ((self.__float__(), self._unit) == (other.__float__(), other._unit))
diff --git a/test/test_EeVal.py b/test/test_EeVal.py
index c4254fb..b96e089 100644
--- a/test/test_EeVal.py
+++ b/test/test_EeVal.py
@@ -7,3 +7,10 @@ def test_ordering():
assert n100 > p100
assert p100 < n100
assert [p100, n100, u1] == sorted([p100, u1, n100])
+
+def test_hash():
+ p100 = EeVal('100 p')
+ n100 = EeVal('100 n')
+ u1 = EeVal('1u')
+
+ assert 3 == len(set([p100, p100, n100, u1]))