From 4ccdcb4a5bb64021833db0e9aab2c0d9083299a2 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 12 Sep 2024 17:28:17 +0200 Subject: [PATCH] tests: rewrite the syntimpl test * tests/core/syntimpl.cc: Rewrite to test multiple formulas at once, and test them with three different implication checks. * tests/core/syntimpl.test: Adjust the test to execute syntimpl only once. --- tests/core/syntimpl.cc | 113 ++++++++++++++++------------------ tests/core/syntimpl.test | 127 ++++++++++++++++++--------------------- 2 files changed, 109 insertions(+), 131 deletions(-) diff --git a/tests/core/syntimpl.cc b/tests/core/syntimpl.cc index 65995898a..329c3e01d 100644 --- a/tests/core/syntimpl.cc +++ b/tests/core/syntimpl.cc @@ -18,85 +18,74 @@ #include "config.h" #include +#include +#include #include #include +#include #include -#include -#include #include +#include +#include static void syntax(char* prog) { - std::cerr << prog << " formula1 formula2?\n"; + std::cerr << prog << " file\n"; exit(2); } int main(int argc, char** argv) { - if (argc < 4) + if (argc != 2) syntax(argv[0]); - - int opt = atoi(argv[1]); - int exit_return = 0; - - { - auto ftmp1 = spot::parse_infix_psl(argv[2]); - - if (ftmp1.format_errors(std::cerr)) + std::ifstream input(argv[1]); + if (!input) + { + std::cerr << "failed to open " << argv[1] << '\n'; return 2; + } - auto ftmp2 = spot::parse_infix_psl(argv[3]); + spot::tl_simplifier* c = new spot::tl_simplifier; + std::string s; + unsigned line = 0; + while (std::getline(input, s)) + { + ++line; + std::cerr << line << ": " << s << '\n'; + if (s[0] == '#') // Skip comments + continue; - if (ftmp2.format_errors(std::cerr)) - return 2; - - spot::formula f1 = spot::negative_normal_form(ftmp1.f); - spot::formula f2 = spot::negative_normal_form(ftmp2.f); - - std::string f1s = spot::str_psl(f1); - std::string f2s = spot::str_psl(f2); - - spot::tl_simplifier* c = new spot::tl_simplifier; - - switch (opt) - { - case 0: - std::cout << "Test f1 < f2" << std::endl; - if (c->syntactic_implication(f1, f2)) - { - std::cout << f1s << " < " << f2s << '\n'; - exit_return = 1; - } - break; - - case 1: - std::cout << "Test !f1 < f2" << std::endl; - if (c->syntactic_implication_neg(f1, f2, false)) - { - std::cout << "!(" << f1s << ") < " << f2s << '\n'; - exit_return = 1; - } - break; - - case 2: - std::cout << "Test f1 < !f2" << std::endl; - if (c->syntactic_implication_neg(f1, f2, true)) - { - std::cout << f1s << " < !(" << f2s << ")\n"; - exit_return = 1; - } - break; - default: - break; - } - - f1.dump(std::cout) << '\n'; - f2.dump(std::cout) << '\n'; - - delete c; - } + spot::formula f[2]; + std::istringstream ss(s); + for (unsigned i = 0; i < 2; ++i) + { + std::string form; + if (!std::getline(ss, form, ',')) + { + std::cerr << "missing first formula\n"; + exit(2); + } + std::string tmp; + while (form.size() > 0 && form.back() == '\\' + && std::getline(ss, tmp, ',')) + { + form.back() = ','; + form += tmp; + } + auto pf = spot::parse_infix_psl(form); + if (pf.format_errors(std::cerr)) + return 2; + f[i] = spot::negative_normal_form(pf.f); + } + // ignore the rest of the line + std::cout << spot::str_psl(f[0]) << ',' << spot::str_psl(f[1]) << ',' + << c->syntactic_implication(f[0], f[1]) << ',' + << c->syntactic_implication_neg(f[0], f[1], false) << ',' + << c->syntactic_implication_neg(f[0], f[1], true) << '\n'; + } + delete c; assert(spot::fnode::instances_check()); - return exit_return; + return 0; } diff --git a/tests/core/syntimpl.test b/tests/core/syntimpl.test index 663672c4c..413b01802 100755 --- a/tests/core/syntimpl.test +++ b/tests/core/syntimpl.test @@ -22,74 +22,63 @@ . ./defs || exit 1 -# -#GFa && GFb && FG(!a && !b) -run 1 ../syntimpl 0 'a' 'a | b' -run 1 ../syntimpl 0 'F(a)' 'F(a | b)' -run 1 ../syntimpl 0 'G(a)' 'G(a | b)' -run 1 ../syntimpl 0 'GF(a)' 'GF(a | b)' -run 1 ../syntimpl 0 'GF(a)' '!FG(!a && !b)' -run 1 ../syntimpl 0 'Xa' 'X(b U a)' -run 1 ../syntimpl 0 'XXa' 'XX(b U a)' +cat >input < output +diff input output