# Spot is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Spot is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import spot a = spot.acc_cond(5) a.set_acceptance(spot.acc_code('parity min odd 5')) assert (a.is_parity() == [True, False, True]) a.set_acceptance('parity max even 5') assert (a.is_parity() == [True, True, False]) a.set_acceptance('generalized-Buchi 5') assert (a.is_parity()[0] == False) assert (a.is_parity(True)[0] == False) a.set_acceptance('Inf(4) | (Fin(3)&Inf(2)) | (Fin(3)&Fin(1)&Inf(0))') assert (a.is_parity()[0] == False) assert (a.is_parity(True) == [True, True, False]) assert a.maybe_accepting([1, 2, 3], [0, 4]).is_true() assert a.maybe_accepting([0], []).is_true() assert a.maybe_accepting([0], [3]).is_false() assert a.maybe_accepting([0, 3], []).is_maybe()
# Test some function that must return exceptions on error. Doing # so is mostly a way to improve the coverage report. import spot import buddy def report_missing_exception(): raise RuntimeError("missing exception") aut = spot.translate('GFa & GFb & GFc') aut.set_acceptance(spot.acc_cond("parity min even 4")) try: spot.iar(aut) except RuntimeError as e: assert 'iar() expects Rabin-like or Streett-like input' in str(e) else: report_missing_exception() alt = spot.dualize(spot.translate('FGa | FGb')) try: spot.tgba_determinize(alt) except RuntimeError as e: assert 'tgba_determinize() does not support alternation' in str(e) else: report_missing_exception()
a = spot.make_twa_graph(spot._bdd_dict) a.set_acceptance(0, spot.acc_code("t")) assert (a.prop_state_acc() == True) a.set_acceptance(1, spot.acc_code("Fin(0)")) assert (a.prop_state_acc() == spot.trival.maybe()) # Some tests for used_inf_fin_sets(), which return a pair of mark_t. (inf, fin) = a.get_acceptance().used_inf_fin_sets() assert inf == [] assert fin == [0] (inf, fin) = spot.acc_code("(Fin(0)|Inf(1))&Fin(2)&Inf(0)").used_inf_fin_sets() assert inf == [0, 1] assert fin == [0, 2] # is_rabin_like() returns (bool, [(inf, fin), ...]) (b, v) = spot.acc_cond("(Fin(0)&Inf(1))|(Fin(2)&Inf(0))").is_rabin_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] (b, v) = spot.acc_cond("(Fin(0)|Inf(1))&(Fin(2)|Inf(0))").is_rabin_like() 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 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
def test_rabin(acc, expected_rabin_like, expected_pairs): test_rs(acc, 'rabin', expected_rabin_like, expected_pairs) o_acc = spot.acc_cond(acc.get_acceptance().complement()) test_rs(o_acc, 'streett', expected_rabin_like, switch_pairs(expected_pairs))
def test_streett(acc, expected_streett_like, expected_pairs): test_rs(acc, 'streett', expected_streett_like, expected_pairs) o_acc = spot.acc_cond(acc.get_acceptance().complement()) test_rs(o_acc, 'rabin', expected_streett_like, switch_pairs(expected_pairs)) def test_rabin(acc, expected_rabin_like, expected_pairs): test_rs(acc, 'rabin', expected_rabin_like, expected_pairs) o_acc = spot.acc_cond(acc.get_acceptance().complement()) test_rs(o_acc, 'streett', expected_rabin_like, switch_pairs(expected_pairs)) acc = spot.acc_cond(spot.acc_code('Fin(0)')) test_streett(acc, True, [spot.rs_pair(m0, mall)]) acc = spot.acc_cond(spot.acc_code('Fin(0)|Inf(1)')) test_streett(acc, True, [spot.rs_pair(m0, m1)]) acc = spot.acc_cond(spot.acc_code('(Fin(0)|Inf(1))&(Fin(2)|Inf(3))')) test_streett(acc, True, [spot.rs_pair(m0, m1), spot.rs_pair(m2, m3)]) acc = spot.acc_cond(spot.acc_code('(Fin(0)|Inf(1))&(Inf(3)|Fin(2))')) test_streett(acc, True, [spot.rs_pair(m0, m1), spot.rs_pair(m2, m3)]) acc = spot.acc_cond(spot.acc_code('(Fin(0)|Inf(1))&(Fin(3)|Inf(2))')) test_streett(acc, True, [spot.rs_pair(m0, m1), spot.rs_pair(m3, m2)]) acc = spot.acc_cond(spot.acc_code('(Fin(0)|Inf(1))&(Fin(0)|Inf(2))'))
# Spot is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # Spot is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import spot a = spot.acc_cond(5) a.set_acceptance(spot.acc_code('parity min odd 5')) assert(a.is_parity() == [True, False, True]) a.set_acceptance('parity max even 5') assert(a.is_parity() == [True, True, False]) a.set_acceptance('generalized-Buchi 5') assert(a.is_parity()[0] == False) assert(a.is_parity(True)[0] == False) a.set_acceptance('Inf(4) | (Fin(3)&Inf(2)) | (Fin(3)&Fin(1)&Inf(0))') assert(a.is_parity()[0] == False) assert(a.is_parity(True) == [True, True, False]) assert a.maybe_accepting([1, 2, 3], [0, 4]).is_true() assert a.maybe_accepting([0], []).is_true() assert a.maybe_accepting([0], [3]).is_false() assert a.maybe_accepting([0, 3], []).is_maybe()
def generic_emptiness2(aut): old_a = spot.acc_cond(aut.acc()) res = generic_emptiness2_rec(aut) # Restore the original acceptance condition aut.set_acceptance(old_a) return res