-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathshort_bch_code_decoder_test.cc
72 lines (68 loc) · 2.18 KB
/
short_bch_code_decoder_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Test for the short BCH codes decoder
Copyright 2020 Ahmet Inan <inan@aicodix.de>
*/
#include <cassert>
#include <random>
#include <iostream>
#include <functional>
#include "short_bch_code_decoder.hh"
int main()
{
std::random_device rd;
std::default_random_engine generator(rd());
if (1) {
// Perfect binary Golay code using x^11+x^9+x^7+x^6+x^5+x+1
const int N = 23, K = 12, T = 3, POLY = 0b101011100011;
CODE::ShortBCHCodeDecoder<N, K, POLY, T> decode;
int target = 0b10101101101111011111001;
int damaged = target;
typedef std::uniform_int_distribution<int> distribution;
auto epos = std::bind(distribution(0, N-1), generator);
for (int i = 0; i < T; ++i)
damaged ^= 1 << epos();
int recovered = decode(damaged);
assert(recovered == target);
}
if (1) {
// Perfect binary Golay code using x^11+x^10+x^6+x^5+x^4+x^2+1
const int N = 23, K = 12, T = 3, POLY = 0b110001110101;
CODE::ShortBCHCodeDecoder<N, K, POLY, T> decode;
int target = 0b10101101101100100010101;
int damaged = target;
typedef std::uniform_int_distribution<int> distribution;
auto epos = std::bind(distribution(0, N-1), generator);
for (int i = 0; i < T; ++i)
damaged ^= 1 << epos();
int recovered = decode(damaged);
assert(recovered == target);
}
if (1) {
// NASA INTRO BCH(15, 5) T=3
const int N = 15, K = 5, T = 3, POLY = 0b10100110111;
CODE::ShortBCHCodeDecoder<N, K, POLY, T> decode;
int target = 0b110010001111010;
int damaged = target;
typedef std::uniform_int_distribution<int> distribution;
auto epos = std::bind(distribution(0, N-1), generator);
for (int i = 0; i < T; ++i)
damaged ^= 1 << epos();
int recovered = decode(damaged);
assert(recovered == target);
}
if (1) {
// BCH(31, 16) T=3
const int N = 31, K = 16, T = 3, POLY = 0b1000111110101111;
CODE::ShortBCHCodeDecoder<N, K, POLY, T> decode;
int target = 970576025;
int damaged = target;
typedef std::uniform_int_distribution<int> distribution;
auto epos = std::bind(distribution(0, N-1), generator);
for (int i = 0; i < T; ++i)
damaged ^= 1 << epos();
int recovered = decode(damaged);
assert(recovered == target);
}
std::cerr << "Short BCH code decoder test passed!" << std::endl;
return 0;
}