1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
// Author(s): Jeroen Keiren
// Copyright: see the accompanying file COPYING or copy at
// https://svn.win.tue.nl/trac/MCRL2/browser/trunk/COPYING
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
/// \file binary_test.cpp
/// \brief Some simple tests for the binary algorithm.
#include <iostream>
#include <string>
#include <boost/test/included/unit_test_framework.hpp>
#include "mcrl2/utilities/test_utilities.h"
#include "mcrl2/lps/specification.h"
#include "mcrl2/lps/binary.h"
#include "mcrl2/lps/linearise.h"
#include "mcrl2/lps/detail/test_input.h"
using namespace mcrl2;
using namespace mcrl2::data;
using namespace mcrl2::lps;
using mcrl2::utilities::collect_after_test_case;
BOOST_GLOBAL_FIXTURE(collect_after_test_case)
///All process parameters of sort D should have been translated to
///parameters of sort Bool. This leaves only parameters of sort Bool and Pos.
BOOST_AUTO_TEST_CASE(case_1)
{
const std::string text(
"sort D = struct d1|d2;\n"
"act a;\n"
"proc P(e:D) = sum d:D . a . P(d);\n"
"init P(d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
variable_list parameters1 = s1.process().process_parameters();
int bool_param_count = 0;
for (variable_list::iterator i = parameters1.begin(); i != parameters1.end(); ++i)
{
BOOST_CHECK_EQUAL(i->sort(), sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 1);
}
/*
* Sort D has got 8 constructors, which can therefore be encoded exactly in
* a vector of 3 boolean variables. This means that all combinations of the
* boolean variables encode a constructor.
* Process parameter e should be replaced by a vector of boolean variables,
* and should be replaced in nextstate.
* The initial state should be altered accordingly.
*/
BOOST_AUTO_TEST_CASE(case_2)
{
const std::string text(
"sort D = struct d1|d2|d3|d4|d5|d6|d7|d8;\n"
"act a;\n"
"proc P(e:D) = sum d:D . a . P(d);\n"
"init P(d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
int bool_param_count = 0;
for (variable_list::iterator i = s1.process().process_parameters().begin();
i != s1.process().process_parameters().end();
++i)
{
BOOST_CHECK_EQUAL(i->sort(), sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 3);
}
/*
* Sort D has got 7 constructors, which can therefore be encoded in
* a vector of 3 boolean variables. This means that there is one combination
* of the boolean variables that does not encode a constructor.
* Process parameter e should be replaced by a vector of boolean variables,
* and should be replaced in nextstate.
* The initial state should be altered accordingly.
*/
BOOST_AUTO_TEST_CASE(case_3)
{
const std::string text(
"sort D = struct d1|d2|d3|d4|d5|d6|d7;\n"
"act a;\n"
"proc P(e:D) = sum d:D . a . P(d);\n"
"init P(d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
int bool_param_count = 0;
for (variable_list::iterator i = s1.process().process_parameters().begin();
i != s1.process().process_parameters().end();
++i)
{
BOOST_CHECK_EQUAL(i->sort(), sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 3);
}
/*
* Sort D has got 2 constructors, and should be encoded into one boolean
* variable. Process parameter e should be replaced by a single boolean variable
* and the action a(e) and the initial state should be altered accordingly.
*
* Note there is parameter of sort Pos because of linearisation.
*/
BOOST_AUTO_TEST_CASE(case_4)
{
const std::string text(
"sort D = struct d1|d2;\n"
"act a,b:D;\n"
"proc P(e:D) = sum d:D . a(e) . b(d) . P(d);\n"
"init P(d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
int bool_param_count = 0;
for (variable_list::iterator i = s1.process().process_parameters().begin();
i != s1.process().process_parameters().end();
++i)
{
BOOST_CHECK(i->sort() == sort_pos::pos() || i->sort() == sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 2);
}
/*
* Sort D has got 9 constructors, therefore it should be encoded in
* a vector of 4 boolean variables. Note that this does leave a lot of
* combinations of booleans that are not used (7 to be precise).
* Process parameter e should be replaced by a vector of boolean variables,
* and should be replaced in nextstate.
* The initial state should be altered accordingly.
*/
BOOST_AUTO_TEST_CASE(case_5)
{
const std::string text(
"sort D = struct d1|d2|d3|d4|d5|d6|d7|d8|d9;\n"
"act a;\n"
"proc P(e:D) = sum d:D . a . P(d);\n"
"init P(d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
int bool_param_count = 0;
for (variable_list::iterator i = s1.process().process_parameters().begin();
i != s1.process().process_parameters().end();
++i)
{
BOOST_CHECK_EQUAL(i->sort(), sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 4);
}
/*
* Sort D is a sort with 4 constructors. It is a recursive construct of two
* constructors parameterized with sort E, which is in turn a sort which has
* got two simple constructors.
* Sort D can be coded in a vector of 2 boolean variables, in which all
* combinations are used.
* Process parameter e should be replaced by a vector of boolean variables,
* and should be replaced in nextstate.
* The initial state should be altered accordingly.
*/
BOOST_AUTO_TEST_CASE(case_6)
{
const std::string text(
"sort D = struct d1(E) | d2(E);\n"
" E = struct e1 | e2;\n"
"act a;\n"
"proc P(e:D) = sum d:D . a . P(d);\n"
"init P(d1(e1));\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
int bool_param_count = 0;
for (variable_list::iterator i = s1.process().process_parameters().begin();
i != s1.process().process_parameters().end();
++i)
{
BOOST_CHECK_EQUAL(i->sort(), sort_bool::bool_());
if (i->sort() == sort_bool::bool_())
{
++bool_param_count;
}
}
BOOST_CHECK_EQUAL(bool_param_count, 2);
}
// This test case shows a bug where apparently d1 and d2 are mapped to the
// same boolean value. Test case was provided by Jan Friso Groote along with
// bug 623.
BOOST_AUTO_TEST_CASE(bug_623)
{
const std::string text(
"sort D;\n"
"cons d1,d2:D;\n"
"act a:D#D;\n"
"proc X(e1,e2:D) = a(e1,e2) . X(d1,d2);\n"
"init X(d2,d1);\n"
);
specification s0 = linearise(text);
rewriter r(s0.data());
specification s1 = s0;
binary_algorithm<rewriter>(s1, r).run();
action_summand_vector summands1 = s1.process().action_summands();
for (action_summand_vector::const_iterator i = summands1.begin(); i != summands1.end(); ++i)
{
data_expression_list next_state = i->next_state(s1.process().process_parameters());
BOOST_CHECK_EQUAL(next_state.size(), 2);
BOOST_CHECK_NE(*next_state.begin(), *(++next_state.begin()));
std::clog << "erroneous next state " << data::pp(next_state) << std::endl;
}
}
BOOST_AUTO_TEST_CASE(abp)
{
specification spec = linearise(lps::detail::ABP_SPECIFICATION());
std::clog << "--- before ---\n" << lps::pp(spec) << std::endl;
rewriter r(spec.data());
binary_algorithm<rewriter>(spec, r).run();
std::clog << "--- after ---\n" << lps::pp(spec) << std::endl;
BOOST_CHECK(is_well_typed(spec));
}
boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[])
{
return 0;
}
|