reimplement __hash__ with tuple; closes #1

This commit is contained in:
Luciano Ramalho committed 2019-12-18 19:22:49 -03:00
1 parent 59818e0500
commit a1d6c125bf
4 files changed
+9 -160

No files matched your search

+3 -3
View File
@@ -79,8 +79,8 @@ Tests of hashing:
>>> v1 = Vector2d(3, 4)
>>> v2 = Vector2d(3.1, 4.2)
>>> hash(v1), hash(v2)
(7, 384307168202284039)
>>> hash(v1) != hash(v2)
True
>>> len(set([v1, v2]))
2
@@ -122,7 +122,7 @@ class Vector2d:
return tuple(self) == tuple(other)
def __hash__(self):
return hash(self.x) ^ hash(self.y)
return hash((self.x, self.y))
def __abs__(self):
return math.hypot(self.x, self.y)
+3 -3
View File
@@ -81,8 +81,8 @@ Tests of hashing:
>>> v1 = Vector2d(3, 4)
>>> v2 = Vector2d(3.1, 4.2)
>>> hash(v1), hash(v2)
(7, 384307168202284039)
>>> hash(v1) != hash(v2)
True
>>> len(set([v1, v2]))
2
@@ -131,7 +131,7 @@ class Vector2d:
# BEGIN VECTOR_V3_HASH
def __hash__(self):
return hash(self.x) ^ hash(self.y)
return hash((self.x, self.y))
# END VECTOR_V3_HASH
def __abs__(self):
+3 -3
View File
@@ -78,8 +78,8 @@ Tests of hashing:
>>> v1 = Vector2d(3, 4)
>>> v2 = Vector2d(3.1, 4.2)
>>> hash(v1), hash(v2)
(7, 384307168202284039)
>>> hash(v1) != hash(v2)
True
>>> len(set([v1, v2]))
2
@@ -129,7 +129,7 @@ class Vector2d:
return tuple(self) == tuple(other)
def __hash__(self):
return hash(self.x) ^ hash(self.y)
return hash((self.x, self.y))
def __abs__(self):
return math.hypot(self.x, self.y)