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-02-13 00:44:47 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 std;
      20             : using namespace atermpp;
      21             : 
      22             : struct counter
      23             : {
      24             :   int& m_sum;
      25             : 
      26           2 :   counter(int& sum)
      27           2 :     : m_sum(sum)
      28           2 :   {}
      29             : 
      30          20 :   void operator()(const atermpp::aterm& t) const
      31             :   {
      32          20 :     m_sum += down_cast<aterm_int>(t).value();
      33          20 :   }
      34             : };
      35             : 
      36             : struct increment
      37             : {
      38             :   atermpp::aterm operator()(const atermpp::aterm& t) const
      39             :   {
      40             :     return aterm_int(down_cast<aterm_int>(t).value() + 1);
      41             :   }
      42             : };
      43             : 
      44             : struct func
      45             : {
      46             :   func()
      47             :   {}
      48             : 
      49             :   func(int)
      50             :   {}
      51             : 
      52             :   atermpp::aterm operator()(const atermpp::aterm& x) const
      53             :   {
      54             :     return read_term_from_string("f(" + pp(x) + ")");
      55             :   }
      56             : };
      57             : 
      58           3 : BOOST_AUTO_TEST_CASE(test_aterm_balanced_tree)
      59             : {
      60           2 :   aterm_balanced_tree empty_tree;
      61           1 :   BOOST_CHECK(empty_tree.begin() == empty_tree.end());
      62             : 
      63           2 :   aterm_list q = read_list_from_string("[0,1,2,3,4,5,6,7,8,9]");
      64           2 :   aterm_list r(read_list_from_string("[0,1,2,3,4,6,1,7,8,9]"));
      65           2 :   aterm_balanced_tree qtree(q.begin(),10);
      66           2 :   aterm_balanced_tree rtree(r.begin(),10);
      67             : 
      68             : 
      69           1 :   BOOST_CHECK(qtree.size() == 10);
      70           1 :   BOOST_CHECK(!qtree.empty());
      71             : 
      72          11 :   for (int i = 0; i != 10; ++i)
      73             :   {
      74          10 :     BOOST_CHECK(qtree[i] == aterm_int(i));
      75             :   }
      76             : 
      77           1 :   BOOST_CHECK(std::equal(qtree.begin(), qtree.end(), q.begin()));
      78           1 :   BOOST_CHECK(std::equal(q.begin(), q.end(), qtree.begin()));
      79           1 :   BOOST_CHECK(aterm_balanced_tree(q.begin(), q.size()) == qtree);
      80             : 
      81           1 :   int count = 0;
      82             : 
      83           1 :   std::for_each(qtree.begin(), qtree.end(), counter(count));
      84             : 
      85           1 :   BOOST_CHECK(count == 45);
      86             : 
      87           1 :   count = 0;
      88             : 
      89           1 :   std::for_each(qtree.begin(), qtree.end(), counter(count));
      90             : 
      91           2 :   aterm_balanced_tree qcopy(q.begin(),10);
      92             : 
      93           1 :   qtree.swap(qcopy);
      94             : 
      95           1 :   BOOST_CHECK(std::equal(qtree.begin(), qtree.end(), q.begin()));
      96           1 :   BOOST_CHECK(std::equal(q.begin(), q.end(), qtree.begin()));
      97             : 
      98           1 :   BOOST_CHECK(!std::equal(rtree.begin(), rtree.end(), q.begin()));
      99           1 :   BOOST_CHECK(!std::equal(q.begin(), q.end(), rtree.begin()));
     100           4 : }

Generated by: LCOV version 1.13