LCOV - code coverage report
Current view: top level - bes/test - find_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 88 88 100.0 %
Date: 2019-06-19 00:50:04 Functions: 13 13 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file find_test.cpp
      10             : /// \brief Test for find functions.
      11             : 
      12             : #include "mcrl2/bes/find.h"
      13             : #include "mcrl2/bes/parse.h"
      14             : #include <algorithm>
      15             : #include <boost/test/minimal.hpp>
      16             : #include <iterator>
      17             : #include <set>
      18             : #include <vector>
      19             : 
      20             : using namespace mcrl2;
      21             : using namespace mcrl2::bes;
      22             : 
      23             : template <typename Container, typename OutputIterator>
      24           3 : void my_find_variables(Container const& container, OutputIterator o)
      25             : {
      26           3 :   bes::detail::make_find_boolean_variables_traverser<bes::boolean_expression_traverser>(o).apply(container);
      27           3 : }
      28             : 
      29             : struct my_compare_variable
      30             : {
      31             :   const boolean_variable& m_variable;
      32             : 
      33             :   my_compare_variable(const boolean_variable& t)
      34             :     : m_variable(t)
      35             :   {}
      36             : 
      37             :   /// \brief Function call operator
      38             :   /// \param t A term
      39             :   /// \return The function result
      40             :   template <typename Variable>
      41             :   bool operator()(const Variable& t) const
      42             :   {
      43             :     return m_variable == t;
      44             :   }
      45             : 
      46             : };
      47             : 
      48             : template <typename Container>
      49           3 : std::set<boolean_variable> my_find_variables(Container const& container)
      50             : {
      51           3 :   std::set<boolean_variable> result;
      52           3 :   my_find_variables(container, std::inserter(result, result.end()));
      53           3 :   return result;
      54             : }
      55             : 
      56           1 : void test_my_search()
      57             : {
      58             :   std::string bes1 =
      59             :     "pbes              \n"
      60             :     "                  \n"
      61             :     "nu X1 = X2 && X1; \n"
      62             :     "mu X2 = X1 || X2; \n"
      63             :     "                  \n"
      64           2 :     "init X1;          \n"
      65             :     ;
      66           2 :   boolean_equation_system b;
      67           2 :   std::stringstream from(bes1);
      68           1 :   from >> b;
      69             : 
      70           2 :   std::set<boolean_variable> v;
      71             : 
      72           1 :   BOOST_CHECK(search_boolean_variable(b, boolean_variable("X1")));
      73           1 :   BOOST_CHECK(search_boolean_variable(b, boolean_variable("X2")));
      74           1 :   BOOST_CHECK(!search_boolean_variable(b, boolean_variable("X3")));
      75             : 
      76           2 :   boolean_equation eq = b.equations().front();
      77           1 :   BOOST_CHECK(search_boolean_variable(eq, boolean_variable("X1")));
      78           1 :   BOOST_CHECK(search_boolean_variable(eq, boolean_variable("X2")));
      79           1 :   BOOST_CHECK(!search_boolean_variable(eq, boolean_variable("X3")));
      80             : 
      81           2 :   boolean_expression x = eq.formula();
      82           1 :   BOOST_CHECK(search_boolean_variable(x, boolean_variable("X1")));
      83           1 :   BOOST_CHECK(search_boolean_variable(x, boolean_variable("X2")));
      84           1 :   BOOST_CHECK(!search_boolean_variable(x, boolean_variable("X3")));
      85             : 
      86           1 : }
      87             : 
      88           1 : void test_my_find()
      89             : {
      90             :   std::string bes1 =
      91             :     "pbes              \n"
      92             :     "                  \n"
      93             :     "nu X1 = X2 && X1; \n"
      94             :     "mu X2 = X1 || X2; \n"
      95             :     "                  \n"
      96           2 :     "init X1;          \n"
      97             :     ;
      98           2 :   boolean_equation_system b;
      99           2 :   std::stringstream from(bes1);
     100           1 :   from >> b;
     101             : 
     102           2 :   std::set<boolean_variable> v;
     103             : 
     104             :   //--- find_boolean_variables ---//
     105           1 :   v = my_find_variables(b);
     106           1 :   BOOST_CHECK(v.size() == 2);
     107           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     108           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     109             : 
     110           2 :   boolean_equation eq = b.equations().front();
     111           1 :   v = my_find_variables(eq);
     112           1 :   BOOST_CHECK(v.size() == 2);
     113           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     114           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     115             : 
     116           2 :   boolean_expression x = eq.formula();
     117           1 :   v = my_find_variables(x);
     118           1 :   BOOST_CHECK(v.size() == 2);
     119           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     120           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     121             : 
     122           1 : }
     123             : 
     124           1 : void test_find()
     125             : {
     126             :   std::string bes1 =
     127             :     "pbes              \n"
     128             :     "                  \n"
     129             :     "nu X1 = X2 && X1; \n"
     130             :     "mu X2 = X1 || X2; \n"
     131             :     "                  \n"
     132           2 :     "init X1;          \n"
     133             :     ;
     134           2 :   boolean_equation_system b;
     135           2 :   std::stringstream from(bes1);
     136           1 :   from >> b;
     137             : 
     138           2 :   std::set<boolean_variable> v;
     139             : 
     140             :   //--- find_boolean_variables ---//
     141           1 :   v = find_boolean_variables(b);
     142           1 :   BOOST_CHECK(v.size() == 2);
     143           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     144           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     145             : 
     146           2 :   boolean_equation eq = b.equations().front();
     147           1 :   v = find_boolean_variables(eq);
     148           1 :   BOOST_CHECK(v.size() == 2);
     149           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     150           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     151             : 
     152           2 :   boolean_expression x = eq.formula();
     153           1 :   v = find_boolean_variables(x);
     154           1 :   BOOST_CHECK(v.size() == 2);
     155           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     156           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     157             : 
     158           1 : }
     159             : 
     160           1 : void test_bnd_occ()
     161             : {
     162             :   std::string bes1 =
     163             :     "pbes              \n"
     164             :     "                  \n"
     165             :     "nu X1 = X2 && X1; \n"
     166             :     "mu X2 = X1 || X2; \n"
     167             :     "                  \n"
     168           2 :     "init X1;          \n"
     169             :     ;
     170           2 :   boolean_equation_system b;
     171           2 :   std::stringstream from(bes1);
     172           1 :   from >> b;
     173             : 
     174           2 :   std::set<boolean_variable> bnd = b.binding_variables();
     175           1 :   BOOST_CHECK(bnd.size() == 2);
     176           1 :   BOOST_CHECK(bnd.find(boolean_variable("X1")) != bnd.end());
     177           1 :   BOOST_CHECK(bnd.find(boolean_variable("X2")) != bnd.end());
     178             : 
     179           2 :   std::set<boolean_variable> occ = b.occurring_variables();
     180           1 :   BOOST_CHECK(occ.size() == 2);
     181           1 :   BOOST_CHECK(occ.find(boolean_variable("X1")) != occ.end());
     182           1 :   BOOST_CHECK(occ.find(boolean_variable("X2")) != occ.end());
     183             : 
     184           1 : }
     185             : 
     186           1 : int test_main(int argc, char* argv[])
     187             : {
     188           1 :   test_my_find();
     189           1 :   test_find();
     190           1 :   test_my_search();
     191           1 :   test_bnd_occ();
     192             : 
     193           1 :   return EXIT_SUCCESS;
     194           3 : }

Generated by: LCOV version 1.12