From c3b7a691e429e8cc42633a60358de7fd033d869d Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 1 Nov 2018 22:10:25 +0100 Subject: [PATCH] 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. --- python/spot/impl.i | 23 +++++++++++++++++++++++ spot/twa/acc.hh | 2 ++ tests/python/setacc.py | 9 ++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/python/spot/impl.i b/python/spot/impl.i index 44a4d008b..a8584ae5e 100644 --- a/python/spot/impl.i +++ b/python/spot/impl.i @@ -670,6 +670,29 @@ def state_is_accepting(self, src) -> "bool": %include +%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 { std::string __repr__() { diff --git a/spot/twa/acc.hh b/spot/twa/acc.hh index 1de4e344e..5949afe23 100644 --- a/spot/twa/acc.hh +++ b/spot/twa/acc.hh @@ -1135,8 +1135,10 @@ namespace spot /// false in Streett, and true in Rabin. struct SPOT_API rs_pair { +#ifndef SWIG rs_pair() = default; rs_pair(const rs_pair&) = default; +#endif rs_pair(acc_cond::mark_t fin, acc_cond::mark_t inf): fin(fin), diff --git a/tests/python/setacc.py b/tests/python/setacc.py index 48a7e66e9..90fe492b3 100644 --- a/tests/python/setacc.py +++ b/tests/python/setacc.py @@ -50,8 +50,7 @@ assert b == False assert len(v) == 0 (b, v) = spot.acc_cond("(Fin(0)|Inf(1))&(Fin(2)|Inf(0))").is_streett_like() assert b == True -assert len(v) == 2 -assert v[0].fin == [0] -assert v[0].inf == [1] -assert v[1].fin == [2] -assert v[1].inf == [0] +assert repr(v) == \ + '(spot.rs_pair(fin=[0], inf=[1]), spot.rs_pair(fin=[2], inf=[0]))' +v2 = (spot.rs_pair(fin=[0], inf=[1]), spot.rs_pair(fin=[2], inf=[0])) +assert v == v2