diff --git a/src/main.cpp b/src/main.cpp index 4018dca5f..f52fb530e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,7 +150,10 @@ The valid values are: "__int__", [](Undefined const& x) -> size_t { return static_cast(x); }) .def("__chr__", - [](Undefined const& x) -> char { return static_cast(x); }); + [](Undefined const& x) -> char { return static_cast(x); }) + .def("__hash__", [](Undefined const& op) -> int { + return std::hash{}(static_cast(op)); + }); m.attr("UNDEFINED") = UNDEFINED; @@ -158,7 +161,7 @@ The valid values are: m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = static_cast(LIBSEMIGROUPS_EIGEN_ENABLED); #else - m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false; + m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false; #endif #ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED @@ -253,7 +256,7 @@ The valid values are: #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; #else - m.attr("__version__") = "dev"; + m.attr("__version__") = "dev"; #endif //////////////////////////////////////////////////////////////////////// @@ -351,8 +354,12 @@ default. return lhop == rhop; }, py::is_operator()) - .def("to_int", [](PositiveInfinity const& x) -> int64_t { - return static_cast(x); + .def("to_int", + [](PositiveInfinity const& x) -> int64_t { + return static_cast(x); + }) + .def("__hash__", [](PositiveInfinity const& op) -> int { + return std::hash{}(static_cast(op)); }); m.attr("POSITIVE_INFINITY") = POSITIVE_INFINITY; @@ -395,8 +402,12 @@ default. return lhop == rhop; }, py::is_operator()) - .def("to_int", [](NegativeInfinity const& x) -> int64_t { - return static_cast(x); + .def("to_int", + [](NegativeInfinity const& x) -> int64_t { + return static_cast(x); + }) + .def("__hash__", [](NegativeInfinity const& op) -> int { + return std::hash{}(static_cast(op)); }); m.attr("NEGATIVE_INFINITY") = NEGATIVE_INFINITY; @@ -444,7 +455,10 @@ default. [](LimitMax const& rhs, int64_t lhs) { return lhs - rhs; }, py::is_operator()) .def("to_int", - [](LimitMax const& x) -> int { return static_cast(x); }); + [](LimitMax const& x) -> int { return static_cast(x); }) + .def("__hash__", [](LimitMax const& op) -> int { + return std::hash{}(static_cast(op)); + }); m.attr("LIMIT_MAX") = LIMIT_MAX; diff --git a/tests/test_constants.py b/tests/test_constants.py index 68aebf171..b8fa8c00f 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -41,6 +41,9 @@ def test_UNDEFINED(): # pylint: disable=invalid-name assert not UNDEFINED > UNDEFINED assert not UNDEFINED < UNDEFINED + d = {UNDEFINED: 0} + assert UNDEFINED in d + def test_POSITIVE_INFINITY(): # pylint: disable=invalid-name """ @@ -79,6 +82,9 @@ def test_POSITIVE_INFINITY(): # pylint: disable=invalid-name assert POSITIVE_INFINITY > 100 assert POSITIVE_INFINITY > NEGATIVE_INFINITY + d = {POSITIVE_INFINITY: 0} + assert POSITIVE_INFINITY in d + def test_NEGATIVE_INFINITY(): # pylint: disable=invalid-name """ @@ -117,6 +123,9 @@ def test_NEGATIVE_INFINITY(): # pylint: disable=invalid-name assert not NEGATIVE_INFINITY > 100 assert not NEGATIVE_INFINITY > POSITIVE_INFINITY + d = {NEGATIVE_INFINITY: 0} + assert NEGATIVE_INFINITY in d + def test_LIMIT_MAX(): # pylint: disable=invalid-name """ @@ -151,3 +160,6 @@ def test_LIMIT_MAX(): # pylint: disable=invalid-name assert 100 < LIMIT_MAX assert not 0 > LIMIT_MAX assert not 100 > LIMIT_MAX + + d = {LIMIT_MAX: 0} + assert LIMIT_MAX in d