LCOV - code coverage report
Current view: top level - utilities/include/mcrl2/utilities/detail - test_operation.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 15 16 93.8 %
Date: 2020-09-22 00:46:14 Functions: 11 14 78.6 %
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 mcrl2/utilities/detail/test_operation.h
      10             : /// \brief Function for testing operations.
      11             : 
      12             : #ifndef MCRL2_UTILITIES_DETAIL_TEST_OPERATION_H
      13             : #define MCRL2_UTILITIES_DETAIL_TEST_OPERATION_H
      14             : 
      15             : #include <functional>
      16             : #include <iostream>
      17             : #include <string>
      18             : 
      19             : namespace mcrl2
      20             : {
      21             : 
      22             : namespace utilities
      23             : {
      24             : 
      25             : namespace detail
      26             : {
      27             : 
      28             : template <typename T>
      29             : T identity(T t)
      30             : {
      31             :   return t;
      32             : }
      33             : 
      34             : /// \brief Generic function that applies two operations to two objects, and compares the results.
      35             : template <typename Parser, typename Operation1, typename Operation2, typename Compare>
      36         123 : bool test_operation(
      37             :   const std::string& expr1,
      38             :   const std::string& expr2,
      39             :   Parser parse,
      40             :   Compare comp,
      41             :   Operation1 op1,
      42             :   const std::string& opname1,
      43             :   Operation2 op2,
      44             :   const std::string& opname2
      45             : )
      46             : {
      47         246 :   auto x1 = parse(expr1);
      48         246 :   auto x2 = parse(expr2);
      49         246 :   auto f1 = op1(x1);
      50         246 :   auto f2 = op2(x2);
      51         123 :   bool success = comp(f1, f2);
      52         123 :   if (success)
      53             :   {
      54         123 :     std::cout << "--- TEST SUCCEEDED --- " << std::endl;
      55             :   }
      56             :   else
      57             :   {
      58           0 :     std::cout << "--- TEST FAILED --- " << std::endl;
      59             :   }
      60         123 :   std::cout << "x"               << " = " << x1 << std::endl;
      61         123 :   std::cout << "y"               << " = " << x2 << std::endl;
      62         123 :   if (!opname1.empty())
      63             :   {
      64         123 :     std::cout << (opname1 + "(x)") << " = " << f1 << std::endl;
      65             :   }
      66         123 :   if (!opname2.empty())
      67             :   {
      68         123 :     std::cout << (opname2 + "(y)") << " = " << f2 << std::endl;
      69             :   }
      70         246 :   return success;
      71             : }
      72             : 
      73             : /// \brief Generic function that applies an operation to an object, and compares it
      74             : /// with another object.
      75             : template <typename Parser, typename Operation, typename Compare>
      76             : bool test_operation(
      77             :   const std::string& expr1,
      78             :   const std::string& expr2,
      79             :   Parser parse,
      80             :   Compare comp,
      81             :   Operation op,
      82             :   const std::string& opname
      83             : )
      84             : {
      85             :   return test_operation(expr1, expr2, parse, comp, op, opname, [](const auto& T) { return T; }, "");
      86             : }
      87             : 
      88             : } // namespace detail
      89             : 
      90             : } // namespace utilities
      91             : 
      92             : } // namespace mcrl2
      93             : 
      94             : #endif // MCRL2_UTILITIES_DETAIL_TEST_OPERATION_H

Generated by: LCOV version 1.13