Houston, we have a trunk.
[debian/gnuradio] / gr-error-correcting-codes / src / lib / libecc / tests / qa_encoder_convolutional_ic1_ic1.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "encoder_convolutional_ic1_ic1.h"
24 #include <qa_encoder_convolutional_ic1_ic1.h>
25 #include <cppunit/TestAssert.h>
26 #include <string.h>
27 #include <iostream>
28 #include <iomanip>
29 #include <stdio.h>
30
31
32 void
33 qa_encoder_convolutional_ic1_ic1::do_encoder_check
34 (const char** c_in,
35  const char** c_res,
36  int n_output_items,
37  int block_size_bits,
38  int n_code_inputs,
39  int n_code_outputs,
40  const int* code_generators,
41  const int* code_feedback)
42 {
43   std::vector<int> t_code_generators;
44   t_code_generators.assign (n_code_inputs * n_code_outputs, 0);
45   for (int m = 0; m < n_code_inputs * n_code_outputs; m++)
46     t_code_generators[m] = code_generators[m];
47
48   encoder_convolutional_ic1_ic1* t_encoder;
49
50   if (code_feedback) {
51     std::vector<int> t_code_feedback;
52     t_code_feedback.assign (n_code_inputs * n_code_outputs, 0);
53     for (int m = 0; m < n_code_inputs * n_code_outputs; m++)
54       t_code_feedback[m] = code_feedback[m];
55
56     t_encoder = new encoder_convolutional_ic1_ic1
57       (block_size_bits,
58        n_code_inputs,
59        n_code_outputs,
60        t_code_generators,
61        t_code_feedback);
62   } else {
63     t_encoder = new encoder_convolutional_ic1_ic1
64       (block_size_bits,
65        n_code_inputs,
66        n_code_outputs,
67        t_code_generators);
68   }
69
70   char** t_out = new char*[n_code_outputs];
71   for (int m = 0; m < n_code_outputs; m++) {
72     t_out[m] = new char[n_output_items];
73   }
74
75   t_encoder->encode (c_in, (char**) t_out, n_output_items);
76
77   for (int m = 0; m < n_code_outputs; m++) {
78     for (int n = 0; n < n_output_items; n++) {
79       CPPUNIT_ASSERT_EQUAL (c_res[m][n], t_out[m][n]);
80     }
81   }
82
83   delete t_encoder;
84   t_encoder = 0;
85
86   for (int m = 0; m < n_code_outputs; m++) {
87     delete [] t_out[m];
88     t_out[m] = 0;
89   }
90   delete [] t_out;
91   t_out = 0;
92 }
93
94 // TEST 0
95 //
96 // checking for SOAI realization (implicitely)
97 // no feedback, no termination
98
99 const static int t0_code_generator[6] = {1, 0, 5, 0, 1, 6};
100 const static int t0_n_code_inputs = 3;
101 const static int t0_n_code_outputs = 2;
102 const static int t0_n_input_items = 10;
103 const static int t0_n_output_items = 10;
104
105 const static char t0_in_0[t0_n_input_items] =
106   {0, 1, 0, 0, 1, 0, 1, 0, 0, 0};
107 const static char t0_in_1[t0_n_input_items] =
108   {0, 1, 0, 0, 0, 1, 1, 0, 0, 0};
109 const static char t0_in_2[t0_n_input_items] =
110   {0, 0, 1, 1, 1, 1, 1, 0, 0, 0};
111 const static char* t0_in[t0_n_code_inputs] =
112   {t0_in_0, t0_in_1, t0_in_2};
113
114 const static char t0_res_0[t0_n_output_items] =
115   {0, 1, 1, 1, 1, 0, 1, 1, 1, 0};
116 const static char t0_res_1[t0_n_output_items] =
117   {0, 1, 0, 1, 0, 1, 1, 0, 1, 0};
118 const static char* t0_res[t0_n_code_outputs] =
119   {t0_res_0, t0_res_1};
120
121 void
122 qa_encoder_convolutional_ic1_ic1::t0
123 ()
124 {
125   do_encoder_check ((const char**) t0_in, (const char**) t0_res,
126                     t0_n_output_items, 100, t0_n_code_inputs,
127                     t0_n_code_outputs, (const int*) t0_code_generator);
128 }
129
130 // TEST 1
131 //
132 // checking for SIAO realization (implicitely)
133 // no feedback, no termination
134
135 const static int t1_code_generator[6] = {1, 0, 0, 1, 5, 6};
136 const static int t1_n_code_inputs = 2;
137 const static int t1_n_code_outputs = 3;
138 const static int t1_n_input_items = 9;
139 const static int t1_n_output_items = 9;
140
141 const static char t1_in_0[t1_n_input_items] =
142   {0, 1, 1, 1, 0, 0, 0, 1, 0};
143 const static char t1_in_1[t1_n_input_items] =
144   {0, 0, 0, 0, 0, 1, 1, 1, 0};
145 const static char* t1_in[t1_n_code_inputs] =
146   {t1_in_0, t1_in_1};
147
148 const static char t1_res_0[t1_n_output_items] =
149   {0, 1, 1, 1, 0, 0, 0, 1, 0};
150 const static char t1_res_1[t1_n_output_items] =
151   {0, 0, 0, 0, 0, 1, 1, 1, 0};
152 const static char t1_res_2[t1_n_output_items] =
153   {0, 1, 1, 0, 1, 1, 1, 1, 0};
154 const static char* t1_res[t1_n_code_outputs] =
155   {t1_res_0, t1_res_1, t1_res_2};
156
157 void
158 qa_encoder_convolutional_ic1_ic1::t1
159 ()
160 {
161   do_encoder_check ((const char**) t1_in, (const char**) t1_res,
162                     t1_n_output_items, 100, t1_n_code_inputs,
163                     t1_n_code_outputs, (const int*) t1_code_generator);
164 }
165
166 // TEST 2
167 //
168 // checking for SIAO realization (implicitely)
169 // with same feedback, no termination
170
171 const static int t2_code_generator[6] = {1, 0, 0, 1, 5, 6};
172 const static int t2_code_feedback[6] = {0, 0, 0, 0, 7, 7};
173 const static int t2_n_code_inputs = 2;
174 const static int t2_n_code_outputs = 3;
175 const static int t2_n_input_items = 19;
176 const static int t2_n_output_items = 19;
177
178 const static char t2_in_0[t2_n_input_items] =
179   {0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0};
180 const static char t2_in_1[t2_n_input_items] =
181   {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0};
182 const static char* t2_in[t2_n_code_inputs] =
183   {t2_in_0, t2_in_1};
184
185 const static char t2_res_0[t2_n_output_items] =
186   {0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0};
187 const static char t2_res_1[t2_n_output_items] =
188   {0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0};
189 const static char t2_res_2[t2_n_output_items] =
190   {0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0};
191 const static char* t2_res[t2_n_code_outputs] =
192   {t2_res_0, t2_res_1, t2_res_2};
193
194 void
195 qa_encoder_convolutional_ic1_ic1::t2
196 ()
197 {
198   do_encoder_check ((const char**) t2_in, (const char**) t2_res,
199                     t2_n_output_items, 100, t2_n_code_inputs,
200                     t2_n_code_outputs, (const int*) t2_code_generator,
201                     (const int*) t2_code_feedback);
202 }
203
204 // TEST 3
205 //
206 // checking for SOAI realization (implicitely)
207 // with same feedback, no termination
208
209 const static int t3_code_generator[6] = {1, 0, 5, 0, 1, 6};
210 const static int t3_code_feedback[6] = {0, 0, 7, 0, 0, 7};
211 const static int t3_n_code_inputs = 3;
212 const static int t3_n_code_outputs = 2;
213 const static int t3_n_input_items = 17;
214 const static int t3_n_output_items = 17;
215
216 const static char t3_in_0[t3_n_input_items] =
217   {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};
218 const static char t3_in_1[t3_n_input_items] =
219   {0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
220 const static char t3_in_2[t3_n_input_items] =
221   {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0};
222 const static char* t3_in[t3_n_code_inputs] =
223   {t3_in_0, t3_in_1, t3_in_2};
224
225 const static char t3_res_0[t3_n_output_items] =
226   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
227 const static char t3_res_1[t3_n_output_items] =
228   {0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0};
229 const static char* t3_res[t3_n_code_outputs] =
230   {t3_res_0, t3_res_1};
231
232 void
233 qa_encoder_convolutional_ic1_ic1::t3
234 ()
235 {
236   do_encoder_check ((const char**) t3_in, (const char**) t3_res,
237                     t3_n_output_items, 100, t3_n_code_inputs,
238                     t3_n_code_outputs, (const int*) t3_code_generator,
239                     (const int*) t3_code_feedback);
240 }
241
242 // TEST 4
243 //
244 // checking for SIAO realization (implicitely),
245 // with different feedbacks, no termination
246
247 const static int t4_code_generator[6] = {1, 4, 0, 3, 1, 6};
248 const static int t4_code_feedback[6] = {0, 7, 0, 5, 0, 5};
249 const static int t4_n_code_inputs = 2;
250 const static int t4_n_code_outputs = 3;
251 const static int t4_n_input_items = 20;
252 const static int t4_n_output_items = 20;
253
254 const static char t4_in_0[t4_n_input_items] =
255   {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0};
256 const static char t4_in_1[t4_n_input_items] =
257   {0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0};
258 const static char* t4_in[t4_n_code_inputs] =
259   {t4_in_0, t4_in_1};
260
261 const static char t4_res_0[t4_n_output_items] =
262   {0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0};
263 const static char t4_res_1[t4_n_output_items] =
264   {0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0};
265 const static char t4_res_2[t4_n_output_items] =
266   {0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0};
267 const static char* t4_res[t4_n_code_outputs] =
268   {t4_res_0, t4_res_1, t4_res_2};
269
270 void
271 qa_encoder_convolutional_ic1_ic1::t4
272 ()
273 {
274   do_encoder_check ((const char**) t4_in, (const char**) t4_res,
275                     t4_n_output_items, 100, t4_n_code_inputs,
276                     t4_n_code_outputs, (const int*) t4_code_generator,
277                     (const int*) t4_code_feedback);
278 }
279
280 // TEST 5
281 //
282 // checking for SOAI realization (implicitely),
283 // with different feedbacks, no termination
284
285 const static int t5_code_generator[6] = {1, 0, 0, 1, 5, 7};
286 const static int t5_code_feedback[6] = {0, 0, 0, 0, 7, 3};
287 const static int t5_n_code_inputs = 2;
288 const static int t5_n_code_outputs = 3;
289 const static int t5_n_input_items = 19;
290 const static int t5_n_output_items = 19;
291
292 const static char t5_in_0[t5_n_input_items] =
293   {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};
294 const static char t5_in_1[t5_n_input_items] =
295   {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};
296 const static char* t5_in[t5_n_code_inputs] =
297   {t5_in_0, t5_in_1};
298
299 const static char t5_res_0[t5_n_output_items] =
300   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
301 const static char t5_res_1[t5_n_output_items] =
302   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
303 const static char t5_res_2[t5_n_output_items] =
304   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
305 const static char* t5_res[t5_n_code_outputs] =
306   {t5_res_0, t5_res_1, t5_res_2};
307
308 void
309 qa_encoder_convolutional_ic1_ic1::t5
310 ()
311 {
312 #if 0
313   do_encoder_check ((const char**) t5_in, (const char**) t5_res,
314                     t5_n_output_items, 100, t5_n_code_inputs,
315                     t5_n_code_outputs, (const int*) t5_code_generator);
316 #endif
317 }
318
319 // TEST 6
320 //
321 // checking for termination, no feedback
322
323 const static int t6_code_generator[6] = {1, 0, 5, 0, 1, 6};
324 const static int t6_n_code_inputs = 3;
325 const static int t6_n_code_outputs = 2;
326 const static int t6_n_input_items = 6;
327 const static int t6_n_output_items = 8;
328
329 const static char t6_in_0[t6_n_input_items] =
330   {0, 1, 0, 0, 1, 0};
331 const static char t6_in_1[t6_n_input_items] =
332   {0, 1, 0, 0, 0, 0};
333 const static char t6_in_2[t6_n_input_items] =
334   {0, 0, 1, 1, 1, 0};
335 const static char* t6_in[t6_n_code_inputs] =
336   {t6_in_0, t6_in_1, t6_in_2};
337
338 const static char t6_res_0[t6_n_output_items] =
339   {0, 1, 1, 1, 1, 1, 1, 0};
340 const static char t6_res_1[t6_n_output_items] =
341   {0, 1, 0, 1, 0, 0, 1, 0};
342 const static char* t6_res[t6_n_code_outputs] =
343   {t6_res_0, t6_res_1};
344
345 void
346 qa_encoder_convolutional_ic1_ic1::t6
347 ()
348 {
349   do_encoder_check ((const char**) t6_in, (const char**) t6_res,
350                     t6_n_output_items, 5, t6_n_code_inputs,
351                     t6_n_code_outputs, (const int*) t6_code_generator);
352 }
353
354 // TEST 7
355 //
356 // checking for termination, with same feedback
357
358 const static int t7_code_generator[6] = {1, 0, 5, 0, 1, 6};
359 const static int t7_code_feedback[6] = {0, 0, 7, 0, 0, 7};
360 const static int t7_n_code_inputs = 3;
361 const static int t7_n_code_outputs = 2;
362 const static int t7_n_input_items = 17;
363 const static int t7_n_output_items = 17;
364
365 const static char t7_in_0[t7_n_input_items] =
366   {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};
367 const static char t7_in_1[t7_n_input_items] =
368   {0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
369 const static char t7_in_2[t7_n_input_items] =
370   {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0};
371 const static char* t7_in[t7_n_code_inputs] =
372   {t7_in_0, t7_in_1, t7_in_2};
373
374 const static char t7_res_0[t7_n_output_items] =
375   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
376 const static char t7_res_1[t7_n_output_items] =
377   {0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0};
378 const static char* t7_res[t7_n_code_outputs] =
379   {t7_res_0, t7_res_1};
380
381 void
382 qa_encoder_convolutional_ic1_ic1::t7
383 ()
384 {
385 #if 0
386   do_encoder_check ((const char**) t7_in, (const char**) t7_res,
387                     t7_n_output_items, 5, t7_n_code_inputs,
388                     t7_n_code_outputs, (const int*) t7_code_generator,
389                     (const int*) t7_code_feedback);
390 #endif
391 }
392
393 // TEST 8
394 //
395 // checking for termination, with different feedback
396
397 const static int t8_code_generator[6] = {1, 0, 5, 0, 1, 6};
398 const static int t8_code_feedback[6] = {0, 0, 7, 0, 0, 3};
399 const static int t8_n_code_inputs = 3;
400 const static int t8_n_code_outputs = 2;
401 const static int t8_n_input_items = 17;
402 const static int t8_n_output_items = 17;
403
404 const static char t8_in_0[t8_n_input_items] =
405   {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0};
406 const static char t8_in_1[t8_n_input_items] =
407   {0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
408 const static char t8_in_2[t8_n_input_items] =
409   {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0};
410 const static char* t8_in[t8_n_code_inputs] =
411   {t8_in_0, t8_in_1, t8_in_2};
412
413 const static char t8_res_0[t8_n_output_items] =
414   {0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0};
415 const static char t8_res_1[t8_n_output_items] =
416   {0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0};
417 const static char* t8_res[t8_n_code_outputs] =
418   {t8_res_0, t8_res_1};
419
420 void
421 qa_encoder_convolutional_ic1_ic1::t8
422 ()
423 {
424 #if 0
425   do_encoder_check ((const char**) t8_in, (const char**) t8_res,
426                     t8_n_output_items, 5, t8_n_code_inputs,
427                     t8_n_code_outputs, (const int*) t8_code_generator,
428                     (const int*) t8_code_feedback);
429 #endif
430 }