LCOV - code coverage report
Current view: top level - src/test - minisketch_tests.cpp (source / functions) Coverage Total Hit
Test: total_coverage.info Lines: 100.0 % 28 28
Test Date: 2026-03-16 05:20:51 Functions: 100.0 % 2 2
Branches: 54.4 % 114 62

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 2021-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 <minisketch.h>
       6                 :             : #include <node/minisketchwrapper.h>
       7                 :             : #include <random.h>
       8                 :             : #include <test/util/common.h>
       9                 :             : #include <test/util/random.h>
      10                 :             : #include <test/util/setup_common.h>
      11                 :             : 
      12                 :             : #include <boost/test/unit_test.hpp>
      13                 :             : 
      14                 :             : #include <utility>
      15                 :             : 
      16                 :             : using node::MakeMinisketch32;
      17                 :             : 
      18                 :             : BOOST_FIXTURE_TEST_SUITE(minisketch_tests, BasicTestingSetup)
      19                 :             : 
      20   [ +  -  +  -  :           7 : BOOST_AUTO_TEST_CASE(minisketch_test)
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  -  +  +  
                      - ]
      21                 :             : {
      22         [ +  + ]:         101 :     for (int i = 0; i < 100; ++i) {
      23                 :         100 :         uint32_t errors = 0 + m_rng.randrange(11);
      24                 :         100 :         uint32_t start_a = 1 + m_rng.randrange(1000000000);
      25                 :         100 :         uint32_t a_not_b = m_rng.randrange(errors + 1);
      26                 :         100 :         uint32_t b_not_a = errors - a_not_b;
      27                 :         100 :         uint32_t both = m_rng.randrange(10000);
      28                 :         100 :         uint32_t end_a = start_a + a_not_b + both;
      29                 :         100 :         uint32_t start_b = start_a + a_not_b;
      30                 :         100 :         uint32_t end_b = start_b + both + b_not_a;
      31                 :             : 
      32                 :         100 :         Minisketch sketch_a = MakeMinisketch32(10);
      33         [ +  + ]:      534262 :         for (uint32_t a = start_a; a < end_a; ++a) sketch_a.Add(a);
      34         [ +  - ]:         100 :         Minisketch sketch_b = MakeMinisketch32(10);
      35         [ +  + ]:      534282 :         for (uint32_t b = start_b; b < end_b; ++b) sketch_b.Add(b);
      36                 :             : 
      37         [ +  - ]:         100 :         Minisketch sketch_ar = MakeMinisketch32(10);
      38         [ +  - ]:         100 :         Minisketch sketch_br = MakeMinisketch32(10);
      39         [ +  - ]:         100 :         sketch_ar.Deserialize(sketch_a.Serialize());
      40         [ +  - ]:         100 :         sketch_br.Deserialize(sketch_b.Serialize());
      41                 :             : 
      42                 :         100 :         Minisketch sketch_c = std::move(sketch_ar);
      43                 :         100 :         sketch_c.Merge(sketch_br);
      44         [ +  - ]:         100 :         auto dec = sketch_c.Decode(errors);
      45   [ +  -  +  - ]:         200 :         BOOST_REQUIRE(dec.has_value());
      46                 :         100 :         auto sols = std::move(*dec);
      47                 :         100 :         std::sort(sols.begin(), sols.end());
      48   [ +  -  +  -  :         331 :         for (uint32_t i = 0; i < a_not_b; ++i) BOOST_CHECK_EQUAL(sols[i], start_a + i);
                   +  + ]
      49   [ +  -  +  -  :         351 :         for (uint32_t i = 0; i < b_not_a; ++i) BOOST_CHECK_EQUAL(sols[i + a_not_b], start_b + both + i);
                   +  + ]
      50   [ +  -  +  -  :         500 :     }
          -  +  +  -  +  
                      - ]
      51                 :           1 : }
      52                 :             : 
      53                 :             : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1