LCOV - code coverage report
Current view: top level - bes/test - find_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 87 87 100.0 %
Date: 2019-09-14 00:54:39 Functions: 14 14 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             : #define BOOST_TEST_MODULE find_test
      13             : #include "mcrl2/bes/find.h"
      14             : #include "mcrl2/bes/parse.h"
      15             : #include <algorithm>
      16             : #include <boost/test/included/unit_test_framework.hpp>
      17             : #include <iterator>
      18             : #include <set>
      19             : #include <vector>
      20             : 
      21             : using namespace mcrl2;
      22             : using namespace mcrl2::bes;
      23             : 
      24             : template <typename Container, typename OutputIterator>
      25           3 : void my_find_variables(Container const& container, OutputIterator o)
      26             : {
      27           3 :   bes::detail::make_find_boolean_variables_traverser<bes::boolean_expression_traverser>(o).apply(container);
      28           3 : }
      29             : 
      30             : struct my_compare_variable
      31             : {
      32             :   const boolean_variable& m_variable;
      33             : 
      34             :   my_compare_variable(const boolean_variable& t)
      35             :     : m_variable(t)
      36             :   {}
      37             : 
      38             :   /// \brief Function call operator
      39             :   /// \param t A term
      40             :   /// \return The function result
      41             :   template <typename Variable>
      42             :   bool operator()(const Variable& t) const
      43             :   {
      44             :     return m_variable == t;
      45             :   }
      46             : 
      47             : };
      48             : 
      49             : template <typename Container>
      50           3 : std::set<boolean_variable> my_find_variables(Container const& container)
      51             : {
      52           3 :   std::set<boolean_variable> result;
      53           3 :   my_find_variables(container, std::inserter(result, result.end()));
      54           3 :   return result;
      55             : }
      56             : 
      57           1 : void test_my_search()
      58             : {
      59             :   std::string bes1 =
      60             :     "pbes              \n"
      61             :     "                  \n"
      62             :     "nu X1 = X2 && X1; \n"
      63             :     "mu X2 = X1 || X2; \n"
      64             :     "                  \n"
      65           2 :     "init X1;          \n"
      66             :     ;
      67           2 :   boolean_equation_system b;
      68           2 :   std::stringstream from(bes1);
      69           1 :   from >> b;
      70             : 
      71           2 :   std::set<boolean_variable> v;
      72             : 
      73           1 :   BOOST_CHECK(search_boolean_variable(b, boolean_variable("X1")));
      74           1 :   BOOST_CHECK(search_boolean_variable(b, boolean_variable("X2")));
      75           1 :   BOOST_CHECK(!search_boolean_variable(b, boolean_variable("X3")));
      76             : 
      77           2 :   boolean_equation eq = b.equations().front();
      78           1 :   BOOST_CHECK(search_boolean_variable(eq, boolean_variable("X1")));
      79           1 :   BOOST_CHECK(search_boolean_variable(eq, boolean_variable("X2")));
      80           1 :   BOOST_CHECK(!search_boolean_variable(eq, boolean_variable("X3")));
      81             : 
      82           2 :   boolean_expression x = eq.formula();
      83           1 :   BOOST_CHECK(search_boolean_variable(x, boolean_variable("X1")));
      84           1 :   BOOST_CHECK(search_boolean_variable(x, boolean_variable("X2")));
      85           1 :   BOOST_CHECK(!search_boolean_variable(x, boolean_variable("X3")));
      86             : 
      87           1 : }
      88             : 
      89           1 : void test_my_find()
      90             : {
      91             :   std::string bes1 =
      92             :     "pbes              \n"
      93             :     "                  \n"
      94             :     "nu X1 = X2 && X1; \n"
      95             :     "mu X2 = X1 || X2; \n"
      96             :     "                  \n"
      97           2 :     "init X1;          \n"
      98             :     ;
      99           2 :   boolean_equation_system b;
     100           2 :   std::stringstream from(bes1);
     101           1 :   from >> b;
     102             : 
     103           2 :   std::set<boolean_variable> v;
     104             : 
     105             :   //--- find_boolean_variables ---//
     106           1 :   v = my_find_variables(b);
     107           1 :   BOOST_CHECK(v.size() == 2);
     108           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     109           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     110             : 
     111           2 :   boolean_equation eq = b.equations().front();
     112           1 :   v = my_find_variables(eq);
     113           1 :   BOOST_CHECK(v.size() == 2);
     114           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     115           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     116             : 
     117           2 :   boolean_expression x = eq.formula();
     118           1 :   v = my_find_variables(x);
     119           1 :   BOOST_CHECK(v.size() == 2);
     120           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     121           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     122             : 
     123           1 : }
     124             : 
     125           1 : void test_find()
     126             : {
     127             :   std::string bes1 =
     128             :     "pbes              \n"
     129             :     "                  \n"
     130             :     "nu X1 = X2 && X1; \n"
     131             :     "mu X2 = X1 || X2; \n"
     132             :     "                  \n"
     133           2 :     "init X1;          \n"
     134             :     ;
     135           2 :   boolean_equation_system b;
     136           2 :   std::stringstream from(bes1);
     137           1 :   from >> b;
     138             : 
     139           2 :   std::set<boolean_variable> v;
     140             : 
     141             :   //--- find_boolean_variables ---//
     142           1 :   v = find_boolean_variables(b);
     143           1 :   BOOST_CHECK(v.size() == 2);
     144           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     145           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     146             : 
     147           2 :   boolean_equation eq = b.equations().front();
     148           1 :   v = find_boolean_variables(eq);
     149           1 :   BOOST_CHECK(v.size() == 2);
     150           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     151           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     152             : 
     153           2 :   boolean_expression x = eq.formula();
     154           1 :   v = find_boolean_variables(x);
     155           1 :   BOOST_CHECK(v.size() == 2);
     156           1 :   BOOST_CHECK(v.find(boolean_variable("X1")) != v.end());
     157           1 :   BOOST_CHECK(v.find(boolean_variable("X2")) != v.end());
     158             : 
     159           1 : }
     160             : 
     161           1 : void test_bnd_occ()
     162             : {
     163             :   std::string bes1 =
     164             :     "pbes              \n"
     165             :     "                  \n"
     166             :     "nu X1 = X2 && X1; \n"
     167             :     "mu X2 = X1 || X2; \n"
     168             :     "                  \n"
     169           2 :     "init X1;          \n"
     170             :     ;
     171           2 :   boolean_equation_system b;
     172           2 :   std::stringstream from(bes1);
     173           1 :   from >> b;
     174             : 
     175           2 :   std::set<boolean_variable> bnd = b.binding_variables();
     176           1 :   BOOST_CHECK(bnd.size() == 2);
     177           1 :   BOOST_CHECK(bnd.find(boolean_variable("X1")) != bnd.end());
     178           1 :   BOOST_CHECK(bnd.find(boolean_variable("X2")) != bnd.end());
     179             : 
     180           2 :   std::set<boolean_variable> occ = b.occurring_variables();
     181           1 :   BOOST_CHECK(occ.size() == 2);
     182           1 :   BOOST_CHECK(occ.find(boolean_variable("X1")) != occ.end());
     183           1 :   BOOST_CHECK(occ.find(boolean_variable("X2")) != occ.end());
     184             : 
     185           1 : }
     186             : 
     187           3 : BOOST_AUTO_TEST_CASE(test_main)
     188             : {
     189           1 :   test_my_find();
     190           1 :   test_find();
     191           1 :   test_my_search();
     192           1 :   test_bnd_occ();
     193           4 : }

Generated by: LCOV version 1.12