Updating all python QA programs in gnuradio-core to output XML files.
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_regenerate.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007,2010 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 from gnuradio import gr, gr_unittest
24 import math
25
26 class test_regenerate (gr_unittest.TestCase):
27
28     def setUp (self):
29         self.tb = gr.top_block ()
30
31     def tearDown (self):
32         self.tb = None
33
34     def test_regen1 (self):
35         tb = self.tb
36         
37         data = [0, 0, 0,
38                 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39                 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
40
41         expected_result = (0, 0, 0,
42                            1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
43                            1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
44
45
46         src = gr.vector_source_b(data, False)
47         regen = gr.regenerate_bb(5, 2)
48         dst = gr.vector_sink_b()
49
50         tb.connect (src, regen)
51         tb.connect (regen, dst)
52         tb.run ()
53
54         dst_data = dst.data ()
55         
56         self.assertEqual (expected_result, dst_data)
57
58     def test_regen2 (self):
59         tb = self.tb
60         
61         data = 200*[0,]
62         data[9] = 1
63         data[99] = 1
64
65         expected_result = 200*[0,]
66         expected_result[9]   = 1
67         expected_result[19]  = 1
68         expected_result[29]  = 1
69         expected_result[39]  = 1
70         
71         expected_result[99]  = 1
72         expected_result[109]  = 1
73         expected_result[119]  = 1
74         expected_result[129]  = 1
75
76         src = gr.vector_source_b(data, False)
77         regen = gr.regenerate_bb(10, 3)
78         dst = gr.vector_sink_b()
79
80         tb.connect (src, regen)
81         tb.connect (regen, dst)
82         tb.run ()
83
84         dst_data = dst.data ()
85         
86         self.assertEqual (tuple(expected_result), dst_data)
87
88
89 if __name__ == '__main__':
90     gr_unittest.run(test_regenerate, "test_regenerate.xml")