LCOV - code coverage report
Current view: top level - lts/test - probabilistic_arbitrary_precision_fraction_test.cpp (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 33 33 100.0 %
Date: 2020-02-19 00:44:21 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Jan Friso Groote
       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 big_numbers_test.cpp
      10             : /// \brief Test whether the class bbilistic_arbitrary_precision_fraction works properly.
      11             : 
      12             : #define BOOST_TEST_MODULE probabilistic_arbitrary_precision_fraction_test
      13             : #include <boost/test/included/unit_test_framework.hpp>
      14             : #include "mcrl2/lts/probabilistic_arbitrary_precision_fraction.h"
      15             : 
      16             : using namespace mcrl2;
      17             : using namespace mcrl2::lts;
      18             : 
      19           8 : void test_divide_multiply(const std::string& xs, const std::string& ys)
      20             : { 
      21           8 :   std::cerr << "Check multiply " << xs << " and " << ys << "\n";
      22          16 :   const probabilistic_arbitrary_precision_fraction x(xs,ys);
      23             : 
      24          16 :   probabilistic_arbitrary_precision_fraction one("1","1");
      25             : 
      26           8 :   if (x>(one-one))
      27             :   {
      28          14 :     probabilistic_arbitrary_precision_fraction y=x/x;
      29           7 :     BOOST_CHECK(y==one);
      30             : 
      31           7 :     y=one-x;
      32           7 :     std::cerr << "LHS: " << x*y << "\n";
      33           7 :     std::cerr << "RHS: " << y*x << "\n";
      34           7 :     BOOST_CHECK(x*y==y*x);
      35             :   }
      36           8 : }
      37             : 
      38          16 : void test_gcd(const std::string& xs)
      39             : {
      40          16 :   std::cerr << "GCD " << xs << "\n";
      41          32 :   utilities::big_natural_number n1(xs);
      42             : 
      43          16 :   BOOST_CHECK(probabilistic_arbitrary_precision_fraction::greatest_common_divisor(n1,n1)==n1);
      44          16 :   BOOST_CHECK(probabilistic_arbitrary_precision_fraction::greatest_common_divisor(n1+n1,n1)==n1);
      45          16 : }
      46             : 
      47           8 : void test(const std::string& xs, const std::string& ys)
      48             : {
      49           8 :   test_gcd(xs);
      50           8 :   test_gcd(ys);
      51           8 :   test_divide_multiply(xs,ys);
      52           8 : }
      53             : 
      54           3 : BOOST_AUTO_TEST_CASE(cumulative_tests)
      55             : {
      56           1 :   test("12","14");
      57           1 :   test("15","90");
      58           1 :   test("0","90");
      59           1 :   test("1","123987498734298734987");
      60           1 :   test("12000000000000000000123","1400000000000000000021498639574985789345798");
      61           1 :   test("12000000000000000000123","1400000000000000000021498639574985789345798");
      62           1 :   test("349857349587453098713409835719348571930857","34908657984275902384759029877987987979878978475908345");
      63           1 :   test("34985430320129384710938471039561390847109398734601956601293846019285609853607349587453098713409835719348571930857",
      64             :        "34985431223981954640133634673587613874569183765329875682716348576138476108576387546187658127653201876510287356021876530287165023817650187635081237650812376501876350871236501287365012873650182735610237560000000000000000000000000320129384710938471039561390847109398734601956601293846019285609853607349587453098713409835719348571930857");
      65           4 : }
      66             : 

Generated by: LCOV version 1.13