LCOV - code coverage report
Current view: top level - lps/test - remove_parameters_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 37 37 100.0 %
Date: 2020-02-21 00:44:40 Functions: 7 7 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 remove_parameters_test.cpp
      10             : /// \brief Add your file description here.
      11             : 
      12             : #define BOOST_TEST_MODULE remove_parameters_test
      13             : #include "mcrl2/lps/detail/lps_algorithm.h"
      14             : #include "mcrl2/lps/detail/specification_property_map.h"
      15             : #include "mcrl2/lps/detail/test_input.h"
      16             : #include "mcrl2/lps/linearise.h"
      17             : #include "mcrl2/lps/parse.h"
      18             : 
      19             : #include <boost/test/included/unit_test_framework.hpp>
      20             : 
      21             : using namespace mcrl2;
      22             : using namespace mcrl2::data;
      23             : using namespace mcrl2::lps;
      24             : 
      25           1 : std::string SPEC =
      26             :   "act  action: Nat;         \n"
      27             :   "                          \n"
      28             :   "proc P(s: Pos, i: Nat) =  \n"
      29             :   "       (s == 2) ->        \n"
      30             :   "         action(3) .      \n"
      31             :   "         P(1, 4)          \n"
      32             :   "     + (s == 1) ->        \n"
      33             :   "         action(4) .      \n"
      34             :   "         P(2, 4)          \n"
      35             :   "     + true ->            \n"
      36             :   "         delta;           \n"
      37             :   "                          \n"
      38             :   "init P(1, 0);             \n"
      39             :   ;
      40             : 
      41           1 : void test_remove_parameters()
      42             : {
      43           2 :   specification spec = parse_linear_process_specification(SPEC);
      44             : 
      45             :   // remove parameters
      46           2 :   std::set<data::variable> to_be_removed;
      47           1 :   to_be_removed.insert(variable("s", sort_pos::pos()));
      48           1 :   to_be_removed.insert(variable("i", sort_nat::nat()));
      49             : 
      50             :   // check the result
      51           2 :   std::string expected_result = "process_parameter_names =";
      52           2 :   lps::detail::specification_property_map<> info(spec);
      53             : 
      54           2 :   specification spec2 = parse_linear_process_specification(SPEC);
      55           1 :   remove_parameters(spec2, to_be_removed);
      56           2 :   lps::detail::specification_property_map<> info2(spec2);
      57           1 :   BOOST_CHECK(data::detail::compare_property_maps("test_remove_parameters", info2, expected_result));
      58           1 : }
      59             : 
      60           1 : void test_instantiate_free_variables()
      61             : {
      62           2 :   specification spec = remove_stochastic_operators(linearise(lps::detail::ABP_SPECIFICATION()));
      63           1 :   lps::detail::lps_algorithm<> algorithm(spec);
      64           1 :   algorithm.instantiate_free_variables();
      65           1 : }
      66             : 
      67           1 : void test_remove_rundant_assignments()
      68             : {
      69             :   std::string lpsspec_text =
      70             :     "act  a;\n"
      71             :     "proc P(x: Nat) = a.P(x = x);\n"
      72           2 :     "init P(0);"
      73             :   ;
      74             :   std::string expected_result_text =
      75             :     "act  a;\n"
      76             :     "proc P(x: Nat) = a.P();\n"
      77           2 :     "init P(0);"
      78             :   ;
      79             : 
      80           2 :   specification result = parse_linear_process_specification(lpsspec_text);
      81           1 :   remove_redundant_assignments(result);
      82           2 :   specification expected_result = parse_linear_process_specification(expected_result_text);
      83           1 :   BOOST_CHECK(result == expected_result);
      84             : 
      85           1 :   lpsspec_text =
      86             :     "act  a;\n"
      87             :     "proc P(x: Nat) = sum x: Nat. a.P(x = x);\n"
      88             :     "init P(0);"
      89             :   ;
      90           1 :   expected_result_text =
      91             :     "act  a;\n"
      92             :     "proc P(x: Nat) = sum x: Nat. a.P(x = x);\n"
      93             :     "init P(0);"
      94             :   ;
      95           1 :   result = parse_linear_process_specification(lpsspec_text);
      96           1 :   remove_redundant_assignments(result);
      97           1 :   expected_result = parse_linear_process_specification(expected_result_text);
      98           1 :   BOOST_CHECK(result == expected_result);
      99           1 : }
     100             : 
     101           3 : BOOST_AUTO_TEST_CASE(test_main)
     102             : {
     103           1 :   test_remove_parameters();
     104           1 :   test_instantiate_free_variables();
     105           1 :   test_remove_rundant_assignments();
     106           4 : }

Generated by: LCOV version 1.13