LCOV - code coverage report
Current view: top level - src/test - feefrac_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 52 52
Test Date: 2024-11-04 05:10:19 Functions: 100.0 % 2 2
Branches: 50.0 % 142 71

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2024-present The Bitcoin Core developers
       2                 :             : // Distributed under the MIT software license, see the accompanying
       3                 :             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :             : 
       5                 :             : #include <util/feefrac.h>
       6                 :             : #include <random.h>
       7                 :             : 
       8                 :             : #include <boost/test/unit_test.hpp>
       9                 :             : 
      10                 :             : BOOST_AUTO_TEST_SUITE(feefrac_tests)
      11                 :             : 
      12   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(feefrac_operators)
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
      13                 :             : {
      14                 :           1 :     FeeFrac p1{1000, 100}, p2{500, 300};
      15                 :           1 :     FeeFrac sum{1500, 400};
      16                 :           1 :     FeeFrac diff{500, -200};
      17                 :           1 :     FeeFrac empty{0, 0};
      18                 :           1 :     [[maybe_unused]] FeeFrac zero_fee{0, 1}; // zero-fee allowed
      19                 :             : 
      20   [ +  -  +  - ]:           3 :     BOOST_CHECK(empty == FeeFrac{}); // same as no-args
      21                 :             : 
      22         [ +  - ]:           2 :     BOOST_CHECK(p1 == p1);
      23   [ +  -  +  - ]:           3 :     BOOST_CHECK(p1 + p2 == sum);
      24   [ +  -  +  - ]:           3 :     BOOST_CHECK(p1 - p2 == diff);
      25                 :             : 
      26                 :           1 :     FeeFrac p3{2000, 200};
      27   [ -  +  +  - ]:           3 :     BOOST_CHECK(p1 != p3); // feefracs only equal if both fee and size are same
      28   [ -  +  +  - ]:           3 :     BOOST_CHECK(p2 != p3);
      29                 :             : 
      30                 :           1 :     FeeFrac p4{3000, 300};
      31   [ +  -  +  - ]:           3 :     BOOST_CHECK(p1 == p4-p3);
      32   [ +  -  +  - ]:           3 :     BOOST_CHECK(p1 + p3 == p4);
      33                 :             : 
      34                 :             :     // Fee-rate comparison
      35         [ +  - ]:           2 :     BOOST_CHECK(p1 > p2);
      36         [ +  - ]:           2 :     BOOST_CHECK(p1 >= p2);
      37         [ +  - ]:           2 :     BOOST_CHECK(p1 >= p4-p3);
      38         [ +  - ]:           2 :     BOOST_CHECK(!(p1 >> p3)); // not strictly better
      39         [ +  - ]:           1 :     BOOST_CHECK(p1 >> p2); // strictly greater feerate
      40                 :             : 
      41         [ +  - ]:           2 :     BOOST_CHECK(p2 < p1);
      42         [ +  - ]:           2 :     BOOST_CHECK(p2 <= p1);
      43         [ +  - ]:           2 :     BOOST_CHECK(p1 <= p4-p3);
      44         [ +  - ]:           2 :     BOOST_CHECK(!(p3 << p1)); // not strictly worse
      45         [ +  - ]:           2 :     BOOST_CHECK(p2 << p1); // strictly lower feerate
      46                 :             : 
      47                 :             :     // "empty" comparisons
      48         [ +  - ]:           2 :     BOOST_CHECK(!(p1 >> empty)); // << will always result in false
      49         [ +  - ]:           2 :     BOOST_CHECK(!(p1 << empty));
      50         [ +  - ]:           2 :     BOOST_CHECK(!(empty >> empty));
      51         [ +  - ]:           2 :     BOOST_CHECK(!(empty << empty));
      52                 :             : 
      53                 :             :     // empty is always bigger than everything else
      54         [ +  - ]:           2 :     BOOST_CHECK(empty > p1);
      55         [ +  - ]:           2 :     BOOST_CHECK(empty > p2);
      56         [ +  - ]:           2 :     BOOST_CHECK(empty > p3);
      57         [ +  - ]:           2 :     BOOST_CHECK(empty >= p1);
      58         [ +  - ]:           2 :     BOOST_CHECK(empty >= p2);
      59         [ +  - ]:           2 :     BOOST_CHECK(empty >= p3);
      60                 :             : 
      61                 :             :     // check "max" values for comparison
      62                 :           1 :     FeeFrac oversized_1{4611686000000, 4000000};
      63                 :           1 :     FeeFrac oversized_2{184467440000000, 100000};
      64                 :             : 
      65         [ +  - ]:           2 :     BOOST_CHECK(oversized_1 < oversized_2);
      66         [ +  - ]:           2 :     BOOST_CHECK(oversized_1 <= oversized_2);
      67         [ +  - ]:           2 :     BOOST_CHECK(oversized_1 << oversized_2);
      68   [ -  +  +  - ]:           3 :     BOOST_CHECK(oversized_1 != oversized_2);
      69                 :             : 
      70                 :             :     // Tests paths that use double arithmetic
      71                 :           1 :     FeeFrac busted{(static_cast<int64_t>(INT32_MAX)) + 1, INT32_MAX};
      72         [ +  - ]:           2 :     BOOST_CHECK(!(busted < busted));
      73                 :             : 
      74                 :           1 :     FeeFrac max_fee{2100000000000000, INT32_MAX};
      75         [ +  - ]:           2 :     BOOST_CHECK(!(max_fee < max_fee));
      76         [ +  - ]:           2 :     BOOST_CHECK(!(max_fee > max_fee));
      77         [ +  - ]:           2 :     BOOST_CHECK(max_fee <= max_fee);
      78         [ +  - ]:           2 :     BOOST_CHECK(max_fee >= max_fee);
      79                 :             : 
      80                 :           1 :     FeeFrac max_fee2{1, 1};
      81         [ +  - ]:           2 :     BOOST_CHECK(max_fee >= max_fee2);
      82                 :             : 
      83                 :           1 : }
      84                 :             : 
      85                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1