Răsfoiți Sursa

fix _PolygonalCircuit.__hash__()

Fabian Peter Hammerle 5 ani în urmă
părinte
comite
931b91a25b

+ 2 - 1
freesurfer_surface/__init__.py

@@ -90,7 +90,8 @@ class _PolygonalCircuit:
         return self._normalize().vertex_indices == other._normalize().vertex_indices
 
     def __hash__(self) -> int:
-        return hash(self._vertex_indices)
+        # pylint: disable=protected-access
+        return hash(self._normalize()._vertex_indices)
 
 
 class _LineSegment(_PolygonalCircuit):

+ 7 - 0
tests/test_line_segment.py

@@ -0,0 +1,7 @@
+from freesurfer_surface import _LineSegment
+
+
+def test_eq():
+    assert _LineSegment((67018, 67019)) == _LineSegment((67018, 67019))
+    assert _LineSegment((67018, 67019)) == _LineSegment((67019, 67018))
+    assert _LineSegment((67019, 67018)) == _LineSegment((67018, 67019))

+ 9 - 0
tests/test_polygonal_circuit.py

@@ -25,3 +25,12 @@ def test_eq():
     assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 1, 4))
     assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((0, 4, 2))
     assert not _PolygonalCircuit((0, 1, 2)) == _PolygonalCircuit((4, 1, 2))
+
+
+def test_hash():
+    assert hash(_PolygonalCircuit((0, 1, 2))) == hash(_PolygonalCircuit((0, 1, 2)))
+    assert hash(_PolygonalCircuit((0, 1, 2))) == hash(_PolygonalCircuit((1, 2, 0)))
+    assert hash(_PolygonalCircuit((0, 1, 2))) == hash(_PolygonalCircuit((2, 0, 1)))
+    assert hash(_PolygonalCircuit((0, 1, 2))) != hash(_PolygonalCircuit((0, 1, 4)))
+    assert hash(_PolygonalCircuit((0, 1, 2))) != hash(_PolygonalCircuit((0, 4, 2)))
+    assert hash(_PolygonalCircuit((0, 1, 2))) != hash(_PolygonalCircuit((4, 1, 2)))