Skip to content

Commit d8dd494

Browse files
Sims: check that Sims1/2 is initialised before add SimsRefinerIdeals
1 parent 02ba3dd commit d8dd494

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/sims.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ by :py:meth:`~Sims1.pruners`.
270270
ss.def(
271271
"add_pruner",
272272
[](SimsSettings_& self, SimsRefinerIdeals const& func) -> Subclass& {
273+
if (self.presentation().alphabet().empty()
274+
&& self.presentation().rules.empty()) {
275+
throw pybind11::value_error(
276+
"the 1st argument (Sims1/2) must be initialised with "
277+
"a non-empty presentation before calling this function");
278+
}
279+
// Can't add this check to libsemigroups itself because it is a
280+
// template.
281+
if (func.presentation() != self.presentation()) {
282+
throw pybind11::value_error(
283+
"the 2nd argument (SimsRefinerIdeals) must be initialised with "
284+
"the same presentation as the 1st argument (Sims1/2)");
285+
}
273286
return self.add_pruner(func);
274287
},
275288
py::arg("pruner"),

tests/test_sims.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,14 @@ def test_sims_refiner_ideals_return_policy():
579579
p.rules = ["a" * 5, "a", "b" * 4, "b", "ab", "ba"]
580580
q = to(p, rtype=(Presentation, list[int]))
581581
assert sri.init(q) is sri
582+
583+
584+
def test_sims_refiner_ideals_uninit():
585+
s = Sims2(word=list[int])
586+
sri = SimsRefinerIdeals(word=list[int])
587+
with pytest.raises(ValueError):
588+
s.add_pruner(sri)
589+
p = Presentation([0, 1])
590+
s.presentation(p)
591+
with pytest.raises(ValueError):
592+
s.add_pruner(sri)

0 commit comments

Comments
 (0)