mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
added tests for Simplex and Hadamard encoders
This commit is contained in:
parent
003d3bbd4f
commit
759ca4b896
2 changed files with 136 additions and 0 deletions
68
tests/hadamard_encoder_test.cc
Normal file
68
tests/hadamard_encoder_test.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Test for the augmented Hadamard codes encoder
|
||||||
|
|
||||||
|
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include "hadamard_encoder.hh"
|
||||||
|
|
||||||
|
template <int K>
|
||||||
|
void hadamard_test()
|
||||||
|
{
|
||||||
|
CODE::HadamardEncoder<K> encode;
|
||||||
|
const int W = 1 << K;
|
||||||
|
const int N = 1 << (K - 1);
|
||||||
|
const int D = 1 << (K - 2);
|
||||||
|
int hist[N+1] = { 0 };
|
||||||
|
for (int j = 0; j < W; ++j) {
|
||||||
|
int8_t cj[N];
|
||||||
|
encode(cj, j);
|
||||||
|
for (int i = j + 1; i < W; ++i) {
|
||||||
|
int8_t ci[N];
|
||||||
|
encode(ci, i);
|
||||||
|
int d = 0;
|
||||||
|
for (int n = 0; n < N; ++n)
|
||||||
|
d += ci[n] != cj[n];
|
||||||
|
++hist[d];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "Hadamard(" << N << ", " << K << ", " << D << ") hist:";
|
||||||
|
for (int i = 0; i < N + 1; ++i)
|
||||||
|
if (hist[i])
|
||||||
|
std::cout << " " << i << ":" << hist[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
int d = 0;
|
||||||
|
while (!hist[d])
|
||||||
|
++d;
|
||||||
|
assert(d == D);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<2>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<3>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<4>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<5>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<6>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<7>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
hadamard_test<8>();
|
||||||
|
}
|
||||||
|
std::cerr << "Hadamard encoder test passed!" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
68
tests/simplex_encoder_test.cc
Normal file
68
tests/simplex_encoder_test.cc
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Test for the Simplex codes encoder
|
||||||
|
|
||||||
|
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include "simplex_encoder.hh"
|
||||||
|
|
||||||
|
template <int K>
|
||||||
|
void simplex_test()
|
||||||
|
{
|
||||||
|
CODE::SimplexEncoder<K> encode;
|
||||||
|
const int W = 1 << K;
|
||||||
|
const int N = (1 << K) - 1;
|
||||||
|
const int D = 1 << (K - 1);
|
||||||
|
int hist[N+1] = { 0 };
|
||||||
|
for (int j = 0; j < W; ++j) {
|
||||||
|
int8_t cj[N];
|
||||||
|
encode(cj, j);
|
||||||
|
for (int i = j + 1; i < W; ++i) {
|
||||||
|
int8_t ci[N];
|
||||||
|
encode(ci, i);
|
||||||
|
int d = 0;
|
||||||
|
for (int n = 0; n < N; ++n)
|
||||||
|
d += ci[n] != cj[n];
|
||||||
|
++hist[d];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "Simplex(" << N << ", " << K << ", " << D << ") hist:";
|
||||||
|
for (int i = 0; i < N + 1; ++i)
|
||||||
|
if (hist[i])
|
||||||
|
std::cout << " " << i << ":" << hist[i];
|
||||||
|
std::cout << std::endl;
|
||||||
|
int d = 0;
|
||||||
|
while (!hist[d])
|
||||||
|
++d;
|
||||||
|
assert(d == D);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (1) {
|
||||||
|
simplex_test<2>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<3>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<4>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<5>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<6>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<7>();
|
||||||
|
}
|
||||||
|
if (1) {
|
||||||
|
simplex_test<8>();
|
||||||
|
}
|
||||||
|
std::cerr << "Simplex encoder test passed!" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue