LCOV - code coverage report
Current view: top level - atermpp/test - aterm_balanced_tree_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 32 32 100.0 %
Date: 2020-09-16 00:45:56 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 aterm_list_test.cpp
      10             : /// \brief Add your file description here.
      11             : 
      12             : #define BOOST_TEST_MODULE aterm_list_test
      13             : #include <boost/test/included/unit_test_framework.hpp>
      14             : 
      15             : #include "mcrl2/atermpp/aterm_io.h"
      16             : #include "mcrl2/atermpp/aterm_balanced_tree.h"
      17             : #include "mcrl2/atermpp/set_operations.h"
      18             : 
      19             : using namespace atermpp;
      20             : 
      21             : struct counter
      22             : {
      23             :   int& m_sum;
      24             : 
      25           2 :   counter(int& sum)
      26           2 :     : m_sum(sum)
      27           2 :   {}
      28             : 
      29          20 :   void operator()(const atermpp::aterm& t) const
      30             :   {
      31          20 :     m_sum += down_cast<aterm_int>(t).value();
      32          20 :   }
      33             : };
      34             : 
      35             : struct increment
      36             : {
      37             :   atermpp::aterm operator()(const atermpp::aterm& t) const
      38             :   {
      39             :     return aterm_int(down_cast<aterm_int>(t).value() + 1);
      40             :   }
      41             : };
      42             : 
      43             : struct func
      44             : {
      45             :   func()
      46             :   {}
      47             : 
      48             :   func(int)
      49             :   {}
      50             : 
      51             :   atermpp::aterm operator()(const atermpp::aterm& x) const
      52             :   {
      53             :     return read_term_from_string("f(" + pp(x) + ")");
      54             :   }
      55             : };
      56             : 
      57           3 : BOOST_AUTO_TEST_CASE(test_aterm_balanced_tree)
      58             : {
      59           2 :   aterm_balanced_tree empty_tree;
      60           1 :   BOOST_CHECK(empty_tree.begin() == empty_tree.end());
      61             : 
      62           2 :   aterm_list q = read_list_from_string("[0,1,2,3,4,5,6,7,8,9]");
      63           2 :   aterm_list r(read_list_from_string("[0,1,2,3,4,6,1,7,8,9]"));
      64           2 :   aterm_balanced_tree qtree(q.begin(),10);
      65           2 :   aterm_balanced_tree rtree(r.begin(),10);
      66             : 
      67             : 
      68           1 :   BOOST_CHECK(qtree.size() == 10);
      69           1 :   BOOST_CHECK(!qtree.empty());
      70             : 
      71          11 :   for (int i = 0; i != 10; ++i)
      72             :   {
      73          10 :     BOOST_CHECK(qtree[i] == aterm_int(i));
      74             :   }
      75             : 
      76           1 :   BOOST_CHECK(std::equal(qtree.begin(), qtree.end(), q.begin()));
      77           1 :   BOOST_CHECK(std::equal(q.begin(), q.end(), qtree.begin()));
      78           1 :   BOOST_CHECK(aterm_balanced_tree(q.begin(), q.size()) == qtree);
      79             : 
      80           1 :   int count = 0;
      81             : 
      82           1 :   std::for_each(qtree.begin(), qtree.end(), counter(count));
      83             : 
      84           1 :   BOOST_CHECK(count == 45);
      85             : 
      86           1 :   count = 0;
      87             : 
      88           1 :   std::for_each(qtree.begin(), qtree.end(), counter(count));
      89             : 
      90           2 :   aterm_balanced_tree qcopy(q.begin(),10);
      91             : 
      92           1 :   qtree.swap(qcopy);
      93             : 
      94           1 :   BOOST_CHECK(std::equal(qtree.begin(), qtree.end(), q.begin()));
      95           1 :   BOOST_CHECK(std::equal(q.begin(), q.end(), qtree.begin()));
      96             : 
      97           1 :   BOOST_CHECK(!std::equal(rtree.begin(), rtree.end(), q.begin()));
      98           1 :   BOOST_CHECK(!std::equal(q.begin(), q.end(), rtree.begin()));
      99           4 : }

Generated by: LCOV version 1.13