diff --git a/python/evalica/test_evalica.py b/python/evalica/test_evalica.py index 3f4343d..d1875ba 100644 --- a/python/evalica/test_evalica.py +++ b/python/evalica/test_evalica.py @@ -35,6 +35,10 @@ def test_exports() -> None: assert hasattr(evalica, attr), f"missing attribute: {attr}" +def test_winner_hashable() -> None: + assert len(evalica.WINNERS) == len(set(evalica.WINNERS)) + + def test_winner_pickle() -> None: for w in evalica.WINNERS: dumped = pickle.dumps(w) diff --git a/src/python.rs b/src/python.rs index 196e9d3..4205453 100644 --- a/src/python.rs +++ b/src/python.rs @@ -17,6 +17,11 @@ impl Winner { Winner::Ignore } + fn __hash__(&self) -> u64 { + let value: u8 = self.clone().into(); + value.into() + } + fn __getstate__(&self) -> PyResult { Ok(self.clone().into()) }