Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)