From 050740aec87f1721a35feea6ababac2a7cc513f4 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Wed, 25 Feb 2026 09:40:04 +0000 Subject: [PATCH] Sims: check that Sims1/2 is initialised before add SimsRefinerIdeals --- src/sims.cpp | 13 +++++++++++++ tests/test_sims.py | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/sims.cpp b/src/sims.cpp index df87d03a..d1c03875 100644 --- a/src/sims.cpp +++ b/src/sims.cpp @@ -270,6 +270,19 @@ by :py:meth:`~Sims1.pruners`. ss.def( "add_pruner", [](SimsSettings_& self, SimsRefinerIdeals const& func) -> Subclass& { + if (self.presentation().alphabet().empty() + && self.presentation().rules.empty()) { + throw pybind11::value_error( + "the 1st argument (Sims1/2) must be initialised with " + "a non-empty presentation before calling this function"); + } + // Can't add this check to libsemigroups itself because it is a + // template. + if (func.presentation() != self.presentation()) { + throw pybind11::value_error( + "the 2nd argument (SimsRefinerIdeals) must be initialised with " + "the same presentation as the 1st argument (Sims1/2)"); + } return self.add_pruner(func); }, py::arg("pruner"), diff --git a/tests/test_sims.py b/tests/test_sims.py index 62172efa..6344ebf9 100644 --- a/tests/test_sims.py +++ b/tests/test_sims.py @@ -579,3 +579,14 @@ def test_sims_refiner_ideals_return_policy(): p.rules = ["a" * 5, "a", "b" * 4, "b", "ab", "ba"] q = to(p, rtype=(Presentation, list[int])) assert sri.init(q) is sri + + +def test_sims_refiner_ideals_uninit(): + s = Sims2(word=list[int]) + sri = SimsRefinerIdeals(word=list[int]) + with pytest.raises(ValueError): + s.add_pruner(sri) + p = Presentation([0, 1]) + s.presentation(p) + with pytest.raises(ValueError): + s.add_pruner(sri)