Merge commit 'v3.3.0' into upstream
[debian/gnuradio] / gr-atsc / src / lib / qa_convolutional_interleaver.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 3, 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., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #include <cppunit/TestAssert.h>
24 #include <qa_convolutional_interleaver.h>
25
26 void
27 qa_convolutional_interleaver::t0 ()
28 {
29   static int input[16] = {
30      1,  2,  3,  4,
31      5,  6,  7,  8,
32      9, 10, 11, 12,
33     13, 14, 15, 16
34   };
35
36   static int output[16] = {
37      1,  0, 0, 0,
38      5,  2, 0, 0,
39      9,  6, 3, 0,
40     13, 10, 7, 4
41   };
42
43   // test interleaver
44   intl = new convolutional_interleaver<int>(true, 4, 1);
45
46   for (int i = 0; i < 16; i++)
47     CPPUNIT_ASSERT_EQUAL (output[i], intl->transform (input[i]));
48 }
49
50 void
51 qa_convolutional_interleaver::t1 ()
52 {
53   static int input[16] = {
54      1,  0, 0, 0,
55      5,  2, 0, 0,
56      9,  6, 3, 0,
57     13, 10, 7, 4
58   };
59
60   static int output[16] = {
61      0,  0, 0, 0,
62      0,  0, 0, 0,
63      0,  0, 0, 0,
64      1,  2, 3, 4
65   };
66
67   // test deinterleaver
68   intl = new convolutional_interleaver<int>(false, 4, 1);
69
70   for (int i = 0; i < 16; i++)
71     CPPUNIT_ASSERT_EQUAL (output[i], intl->transform (input[i]));
72 }
73
74 void
75 qa_convolutional_interleaver::t2 ()
76 {
77   intl = new convolutional_interleaver<int>(true, 4, 1);
78   deintl = new convolutional_interleaver<int>(false, 4, 1);
79
80   int   icount = 6000;
81   int   dcount = 6000;
82   
83   int   end_to_end_delay = intl->end_to_end_delay ();
84   for (int i = 0; i < end_to_end_delay; i++){
85     CPPUNIT_ASSERT_EQUAL (0, deintl->transform (intl->transform (icount++)));
86   }
87
88   for (int i = 0; i < 3 * end_to_end_delay; i++){
89     CPPUNIT_ASSERT_EQUAL (dcount++, deintl->transform (intl->transform (icount++)));
90   }
91 }
92
93 void
94 qa_convolutional_interleaver::t3 ()
95 {
96   intl = new convolutional_interleaver<int>(true, 4, 2);
97   deintl = new convolutional_interleaver<int>(false, 4, 2);
98
99   int   icount = 6000;
100   int   dcount = 6000;
101   
102   int   end_to_end_delay = intl->end_to_end_delay ();
103   for (int i = 0; i < end_to_end_delay; i++){
104     CPPUNIT_ASSERT_EQUAL (0, deintl->transform (intl->transform (icount++)));
105   }
106
107   for (int i = 0; i < 3 * end_to_end_delay; i++){
108     CPPUNIT_ASSERT_EQUAL (dcount++, deintl->transform (intl->transform (icount++)));
109   }
110 }
111
112 void
113 qa_convolutional_interleaver::t4 ()
114 {
115   intl = new convolutional_interleaver<int>(true, 52, 4);
116   deintl = new convolutional_interleaver<int>(false, 52, 4);
117
118   int   icount = 6000;
119   int   dcount = 6000;
120   
121   int   end_to_end_delay = intl->end_to_end_delay ();
122   CPPUNIT_ASSERT_EQUAL (10608, end_to_end_delay);
123   
124   for (int i = 0; i < end_to_end_delay; i++){
125     CPPUNIT_ASSERT_EQUAL (0, deintl->transform (intl->transform (icount++)));
126   }
127
128   for (int i = 0; i < 3 * end_to_end_delay; i++){
129     CPPUNIT_ASSERT_EQUAL (dcount++, deintl->transform (intl->transform (icount++)));
130   }
131 }