python: add __repr__ for rs_pair

* spot/twa/acc.hh: Hide default constructors, so that we can have
keyword arguments on the main constructor.
* python/spot/impl.i: Add __repr__.
* tests/python/setacc.py: Test it.
This commit is contained in:
Alexandre Duret-Lutz 2018-11-01 22:10:25 +01:00
parent 5bb9c87d4c
commit c3b7a691e4
3 changed files with 29 additions and 5 deletions

View file

@ -670,6 +670,29 @@ def state_is_accepting(self, src) -> "bool":
%include <spot/taalgos/minimize.hh> %include <spot/taalgos/minimize.hh>
%extend spot::acc_cond::rs_pair {
std::string __repr__()
{
std::ostringstream os;
os << "spot.rs_pair(fin=[";
char* sep = "";
for (unsigned s: self->fin.sets())
{
os << sep << s;
sep = ", ";
}
os << "], inf=[";
sep = "";
for (unsigned s: self->inf.sets())
{
os << sep << s;
sep = ", ";
}
os << "])";
return os.str();
}
}
%extend spot::trival { %extend spot::trival {
std::string __repr__() std::string __repr__()
{ {

View file

@ -1135,8 +1135,10 @@ namespace spot
/// false in Streett, and true in Rabin. /// false in Streett, and true in Rabin.
struct SPOT_API rs_pair struct SPOT_API rs_pair
{ {
#ifndef SWIG
rs_pair() = default; rs_pair() = default;
rs_pair(const rs_pair&) = default; rs_pair(const rs_pair&) = default;
#endif
rs_pair(acc_cond::mark_t fin, acc_cond::mark_t inf): rs_pair(acc_cond::mark_t fin, acc_cond::mark_t inf):
fin(fin), fin(fin),

View file

@ -50,8 +50,7 @@ assert b == False
assert len(v) == 0 assert len(v) == 0
(b, v) = spot.acc_cond("(Fin(0)|Inf(1))&(Fin(2)|Inf(0))").is_streett_like() (b, v) = spot.acc_cond("(Fin(0)|Inf(1))&(Fin(2)|Inf(0))").is_streett_like()
assert b == True assert b == True
assert len(v) == 2 assert repr(v) == \
assert v[0].fin == [0] '(spot.rs_pair(fin=[0], inf=[1]), spot.rs_pair(fin=[2], inf=[0]))'
assert v[0].inf == [1] v2 = (spot.rs_pair(fin=[0], inf=[1]), spot.rs_pair(fin=[2], inf=[0]))
assert v[1].fin == [2] assert v == v2
assert v[1].inf == [0]