LCOV - code coverage report
Current view: top level - data/test - identifier_generator_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 54 54 100.0 %
Date: 2024-04-19 03:43:27 Functions: 6 6 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 identifier_generator_test.cpp
      10             : /// \brief Test for identifier generators.
      11             : 
      12             : #define BOOST_TEST_MODULE identifier_generator_test
      13             : #include <boost/test/included/unit_test.hpp>
      14             : 
      15             : #include "mcrl2/data/xyz_identifier_generator.h"
      16             : 
      17             : using namespace mcrl2;
      18             : using namespace mcrl2::data;
      19             : 
      20             : inline
      21          25 : core::identifier_string str(const std::string& s)
      22             : {
      23          25 :   return core::identifier_string(s);
      24             : }
      25             : 
      26           1 : void set_identifier_generator_test()
      27             : {
      28           1 :   set_identifier_generator generator;
      29           1 :   generator.add_identifier(str("c0"));
      30           1 :   core::identifier_string s;
      31             : 
      32           1 :   s = generator("c");
      33           1 :   BOOST_CHECK(s == str("c"));
      34             : 
      35           1 :   s = generator("c");
      36           1 :   BOOST_CHECK(s == str("c1"));
      37           1 :   BOOST_CHECK(generator.has_identifier(str("c1")));
      38             : 
      39           1 :   generator.remove_identifier(str("c1"));
      40           1 :   BOOST_CHECK(!generator.has_identifier(str("c1")));
      41             : 
      42           1 :   s = generator("c", false);
      43           1 :   BOOST_CHECK(s == str("c2"));
      44           1 :   BOOST_CHECK(!generator.has_identifier(str("c2")));
      45           1 : }
      46             : 
      47           1 : void multiset_identifier_generator_test()
      48             : {
      49           1 :   multiset_identifier_generator generator;
      50           1 :   generator.add_identifier(str("c0"));
      51           1 :   core::identifier_string s;
      52             : 
      53           1 :   s = generator("c");
      54           1 :   BOOST_CHECK(s == str("c"));
      55             : 
      56           1 :   s = generator("c");
      57           1 :   BOOST_CHECK(s == str("c1"));
      58           1 :   BOOST_CHECK(generator.has_identifier(str("c1")));
      59             : 
      60           1 :   generator.add_identifier(str("c1"));
      61           1 :   generator.remove_identifier(str("c1"));
      62           1 :   BOOST_CHECK(generator.has_identifier(str("c1")));
      63           1 :   generator.remove_identifier(str("c1"));
      64           1 :   BOOST_CHECK(!generator.has_identifier(str("c1")));
      65             : 
      66           1 :   s = generator("c", false);
      67           1 :   BOOST_CHECK(s == str("c2"));
      68           1 :   BOOST_CHECK(!generator.has_identifier(str("c2")));
      69           1 : }
      70             : 
      71           1 : void xyz_identifier_generator_test()
      72             : {
      73           1 :   xyz_identifier_generator generator;
      74           1 :   generator.add_identifier(str("X"));
      75           1 :   generator.add_identifier(str("Y0"));
      76           1 :   core::identifier_string s;
      77             : 
      78           1 :   s = generator("X");
      79           1 :   BOOST_CHECK(s == str("Y"));
      80             : 
      81           1 :   s = generator("X");
      82           1 :   BOOST_CHECK(s == str("Z"));
      83             : 
      84           1 :   s = generator("X");
      85           1 :   BOOST_CHECK(s == str("X0"));
      86             : 
      87           1 :   s = generator("X");
      88           1 :   BOOST_CHECK(s == str("Z0"));
      89           1 : }
      90             : 
      91           2 : BOOST_AUTO_TEST_CASE(test_main)
      92             : {
      93           1 :   set_identifier_generator_test();
      94           1 :   multiset_identifier_generator_test();
      95           1 :   xyz_identifier_generator_test();
      96           1 : }

Generated by: LCOV version 1.14