mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
added regression testing for BCH with packed bits
This commit is contained in:
parent
691b6b6647
commit
24b4212271
1 changed files with 82 additions and 0 deletions
|
|
@ -11,6 +11,72 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
#include "bose_chaudhuri_hocquenghem_encoder.hh"
|
||||
#include "bose_chaudhuri_hocquenghem_decoder.hh"
|
||||
|
||||
template <typename ENC, typename DEC>
|
||||
void bch_test(ENC *encode, DEC *decode, int trials)
|
||||
{
|
||||
std::random_device rd;
|
||||
std::default_random_engine generator(rd());
|
||||
typedef std::uniform_int_distribution<typename DEC::value_type> distribution;
|
||||
auto rnd_cnt = std::bind(distribution(0, DEC::NR), generator);
|
||||
auto rnd_len = std::bind(distribution(1, ENC::K), generator);
|
||||
auto rnd_val = std::bind(distribution(0, 255), generator);
|
||||
while (--trials) {
|
||||
int data_len = rnd_len();
|
||||
auto rnd_pos = std::bind(distribution(0, data_len + ENC::NP - 1), generator);
|
||||
int D = (data_len + 7) / 8;
|
||||
uint8_t data[D], orig_data[D];
|
||||
for (int i = 0; i < D; ++i)
|
||||
data[i] = orig_data[i] = rnd_val();
|
||||
int P = (ENC::NP + 7) / 8;
|
||||
uint8_t parity[P];
|
||||
(*encode)(data, parity, data_len);
|
||||
for (int i = 0; i < D; ++i)
|
||||
assert(data[i] == orig_data[i]);
|
||||
uint8_t orig_parity[P];
|
||||
for (int i = 0; i < P; ++i)
|
||||
orig_parity[i] = parity[i];
|
||||
int error_count = rnd_cnt() / 2;
|
||||
typename DEC::value_type errors[DEC::NR];
|
||||
for (int i = 0; i < error_count; ++i) {
|
||||
int pos = rnd_pos();
|
||||
for (int j = 0; j < i; ++j) {
|
||||
if (errors[j] == pos) {
|
||||
pos = rnd_pos();
|
||||
j = -1;
|
||||
}
|
||||
}
|
||||
errors[i] = pos;
|
||||
if (pos < data_len)
|
||||
CODE::xor_be_bit(data, pos, 1);
|
||||
else
|
||||
CODE::xor_be_bit(parity, pos-data_len, 1);
|
||||
}
|
||||
int erasures_count = DEC::NR - 2 * error_count;
|
||||
typename DEC::value_type erasures[erasures_count];
|
||||
for (int i = 0; i < erasures_count; ++i) {
|
||||
int pos = rnd_pos();
|
||||
for (int j = 0; j < error_count + i; ++j) {
|
||||
if (errors[j] == pos) {
|
||||
pos = rnd_pos();
|
||||
j = -1;
|
||||
}
|
||||
}
|
||||
errors[error_count + i] = pos;
|
||||
erasures[i] = pos;
|
||||
if (pos < data_len)
|
||||
CODE::xor_be_bit(data, pos, 1);
|
||||
else
|
||||
CODE::xor_be_bit(parity, pos-data_len, 1);
|
||||
}
|
||||
int ret = (*decode)(data, parity, erasures, erasures_count, data_len);
|
||||
assert(ret >= 0);
|
||||
for (int i = 0; i < D; ++i)
|
||||
assert(data[i] == orig_data[i]);
|
||||
for (int i = 0; i < P; ++i)
|
||||
assert(parity[i] == orig_parity[i]);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ENC, typename DEC>
|
||||
void bch_reference_test(ENC *encode, DEC *decode, int trials)
|
||||
{
|
||||
|
|
@ -77,6 +143,22 @@ void bch_reference_test(ENC *encode, DEC *decode, int trials)
|
|||
|
||||
int main()
|
||||
{
|
||||
if (1) {
|
||||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::GaloisField<4, 0b10011, uint8_t> GF;
|
||||
GF instance;
|
||||
CODE::BoseChaudhuriHocquenghemEncoder<15, 5> encoder({0b10011, 0b11111, 0b00111});
|
||||
CODE::BoseChaudhuriHocquenghemDecoder<6, 1, 5, GF> decoder;
|
||||
bch_test(&encoder, &decoder, 1000000);
|
||||
}
|
||||
if (1) {
|
||||
// DVB-S2 FULL BCH(65535, 65343) T=12
|
||||
typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF;
|
||||
GF instance;
|
||||
CODE::BoseChaudhuriHocquenghemEncoder<65535, 65343> encoder({0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, 0b10111010110100111, 0b10011101000101101, 0b10001101011100011});
|
||||
CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 65343, GF> decoder;
|
||||
bch_test(&encoder, &decoder, 100);
|
||||
}
|
||||
if (1) {
|
||||
// NASA INTRO BCH(15, 5) T=3
|
||||
typedef CODE::GaloisField<4, 0b10011, uint8_t> GF;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue