Skip to content

Commit

Permalink
Removes testing helper method from encoder_advanced.hpp (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasbaliuka authored May 2, 2024
1 parent 8677201 commit 79908eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
40 changes: 13 additions & 27 deletions src/encoder_advanced.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,25 @@

#include "autogen_ldpc_QC.hpp"

void noise_bitstring_inplace(auto &src, double err_prob, unsigned int seed = 0) {
std::mt19937_64 rng{seed}; // hard-coded seed for testing purposes.

std::bernoulli_distribution distribution(err_prob);

for (std::size_t i = 0; i < src.size(); i++) {
if (distribution(rng)) {
src[i] = !src[i];
} else {
src[i] = src[i];
namespace LDPC4QKD {
template<std::size_t N>
constexpr auto bits_needed() {
auto n = N;
std::size_t number_of_bits{0ul};
while (n > 0) {
n >>= 1;
number_of_bits++;
}
return number_of_bits;
}
}

template<std::size_t N>
constexpr auto bits_needed() {
auto n = N;
std::size_t number_of_bits{0ul};
while (n > 0) {
n >>= 1;
number_of_bits++;
}
return number_of_bits;
}

template<std::size_t N>
using smallest_type = std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint8_t), std::uint8_t,
std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint16_t), std::uint16_t,
std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint32_t), std::uint32_t, std::uint64_t>>>;
template<std::size_t N>
using smallest_type = std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint8_t), std::uint8_t,
std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint16_t), std::uint16_t,
std::conditional_t<bits_needed<N>() <= 8 * sizeof(std::uint32_t), std::uint32_t, std::uint64_t>>>;


namespace LDPC4QKD {

template<typename Bit1, typename Bit2>
constexpr bool xor_as_bools(Bit1 lhs, Bit2 rhs) {
return (static_cast<bool>(lhs) != static_cast<bool>(rhs));
Expand Down
18 changes: 17 additions & 1 deletion tests/test_encoder_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@

using namespace LDPC4QKD;

namespace {
void noise_bitstring_inplace(auto &src, double err_prob, unsigned int seed = 0) {
std::mt19937_64 rng{seed}; // hard-coded seed for testing purposes.

std::bernoulli_distribution distribution(err_prob);

for (std::size_t i = 0; i < src.size(); i++) {
if (distribution(rng)) {
src[i] = !src[i];
} else {
src[i] = src[i];
}
}
}
}

TEST(test_encoder_advanced, basic_example) {
std::cout << "hello\n";
unsigned seed = 42; // seed for PRNG
Expand All @@ -40,7 +56,7 @@ TEST(test_encoder_advanced, basic_example) {
// Use the non-generic version of `encode_with`:
std::cout << "Syndrome of runtime known size " << syndrome_vec.size() << std::endl;
for (auto v: syndrome_vec) {
std::cout << static_cast<int>(v) << ' '; // print syndrome bits
std::cout << static_cast<int>(v) << ' '; // print syndrome bits
}
std::cout << std::endl;
}
Expand Down

0 comments on commit 79908eb

Please sign in to comment.