diff --git a/spot/twaalgos/parity.cc b/spot/twaalgos/parity.cc index 3c83e9725..9ad46fc44 100644 --- a/spot/twaalgos/parity.cc +++ b/spot/twaalgos/parity.cc @@ -1,5 +1,5 @@ // -*- coding: utf-8 -*- -// Copyright (C) 2016 Laboratoire de Recherche et Développement +// Copyright (C) 2016, 2018 Laboratoire de Recherche et Développement // de l'Epita (LRDE). // // This file is part of Spot, a model checking library. @@ -62,6 +62,14 @@ namespace spot e.acc.set(0); } } + + [[noreturn]] static void + input_is_not_parity(const char* fun) + { + throw std::runtime_error(std::string(fun) + + "(): input should have " + "parity acceptance"); + } } twa_graph_ptr @@ -78,8 +86,7 @@ namespace spot bool current_max; bool current_odd; if (!aut->acc().is_parity(current_max, current_odd, true)) - throw new std::invalid_argument("change_parity: input must have a parity " - "acceptance."); + input_is_not_parity("change_parity"); auto old_num_sets = aut->num_sets(); bool output_max = true; @@ -160,8 +167,7 @@ namespace spot bool current_max; bool current_odd; if (!aut->acc().is_parity(current_max, current_odd, true)) - throw new std::invalid_argument("cleanup_parity: input " - "must have a parity acceptance."); + input_is_not_parity("cleanup_parity"); auto num_sets = aut->num_sets(); if (num_sets == 0) return aut; @@ -247,8 +253,7 @@ namespace spot bool current_max; bool current_odd; if (!aut->acc().is_parity(current_max, current_odd, true)) - throw new std::invalid_argument("colorize_parity: input " - "must have a parity acceptance."); + input_is_not_parity("colorize_parity"); bool has_empty = false; for (const auto& e: aut->edges()) diff --git a/tests/python/parity.py b/tests/python/parity.py index 0620da329..6a09718cf 100644 --- a/tests/python/parity.py +++ b/tests/python/parity.py @@ -29,3 +29,10 @@ for f in ('FGa', 'GFa & GFb & FGc', 'XXX(a U b)'): a3 = spot.translate(f, 'det').postprocess('parity') assert a3.acc().is_parity() +a = spot.translate('GFa & GFb') +try: + spot.change_parity_here(a, spot.parity_kind_same, spot.parity_style_even) +except RuntimeError as e: + assert 'input should have parity acceptance' in str(e) +else: + exit(2)