Commit cd661801 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

word: throw an exception when printing an empty word

Fixes #146.

* spot/twaalgos/word.cc: Here.
* tests/python/word.ipynb: Add a test case.
parent 7e2e4df1
...@@ -93,6 +93,8 @@ namespace spot ...@@ -93,6 +93,8 @@ namespace spot
std::ostream& std::ostream&
operator<<(std::ostream& os, const twa_word& w) operator<<(std::ostream& os, const twa_word& w)
{ {
if (w.cycle.empty())
throw std::runtime_error("a twa_word may not have an empty cycle");
auto d = w.get_dict(); auto d = w.get_dict();
if (!w.prefix.empty()) if (!w.prefix.empty())
for (auto& i: w.prefix) for (auto& i: w.prefix)
...@@ -100,7 +102,6 @@ namespace spot ...@@ -100,7 +102,6 @@ namespace spot
bdd_print_formula(os, d, i); bdd_print_formula(os, d, i);
os << "; "; os << "; ";
} }
assert(!w.cycle.empty());
bool notfirst = false; bool notfirst = false;
os << "cycle{"; os << "cycle{";
for (auto& i: w.cycle) for (auto& i: w.cycle)
......
{ {
"metadata": { "metadata": {
"name": "", "name": "",
"signature": "sha256:a4f8f6e783c38abbf8cce75fb3eb8d9344ece79c11ad5c58556df2db3e40d6a2" "signature": "sha256:261c16336ba5deefb7e9ebe705cc5c24f1cbba8622030874d2719f5045289c53"
}, },
"nbformat": 3, "nbformat": 3,
"nbformat_minor": 0, "nbformat_minor": 0,
...@@ -139,7 +139,7 @@ ...@@ -139,7 +139,7 @@
"</svg>\n" "</svg>\n"
], ],
"text": [ "text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fcdb40da870> >" "<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa33c302870> >"
] ]
} }
], ],
...@@ -454,7 +454,7 @@ ...@@ -454,7 +454,7 @@
"</svg>\n" "</svg>\n"
], ],
"text": [ "text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fcdb40da8d0> >" "<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa33c3028d0> >"
] ]
} }
], ],
...@@ -546,6 +546,42 @@ ...@@ -546,6 +546,42 @@
} }
], ],
"prompt_number": 15 "prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Creating an empty word is OK...\n",
"w = spot.twa_word(spot._bdd_dict)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# ... as long as this word is not printed.\n",
"print(w)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "a twa_word may not have an empty cycle",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-17-971829bb8f5f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# ... as long as this word is not printed.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/home/adl/git/spot/python/spot/impl.py\u001b[0m in \u001b[0;36m__str__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 3511\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3512\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__str__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;34m\"std::string\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3513\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_impl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtwa_word___str__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3514\u001b[0m \u001b[0mtwa_word_swigregister\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_impl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtwa_word_swigregister\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3515\u001b[0m \u001b[0mtwa_word_swigregister\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtwa_word\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mRuntimeError\u001b[0m: a twa_word may not have an empty cycle"
]
}
],
"prompt_number": 17
} }
], ],
"metadata": {} "metadata": {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment