Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_mute.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004,2005 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., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 from gnuradio import gr, gr_unittest
24
25 class test_head (gr_unittest.TestCase):
26
27     def setUp (self):
28         self.fg = gr.flow_graph ()
29
30     def tearDown (self):
31         self.fg = None
32
33     def help_ii (self, src_data, exp_data, op):
34         for s in zip (range (len (src_data)), src_data):
35             src = gr.vector_source_i (s[1])
36             self.fg.connect (src, (op, s[0]))
37         dst = gr.vector_sink_i ()
38         self.fg.connect (op, dst)
39         self.fg.run ()
40         result_data = dst.data ()
41         self.assertEqual (exp_data, result_data)
42
43     def help_ff (self, src_data, exp_data, op):
44         for s in zip (range (len (src_data)), src_data):
45             src = gr.vector_source_f (s[1])
46             self.fg.connect (src, (op, s[0]))
47         dst = gr.vector_sink_f ()
48         self.fg.connect (op, dst)
49         self.fg.run ()
50         result_data = dst.data ()
51         self.assertEqual (exp_data, result_data)
52
53     def help_cc (self, src_data, exp_data, op):
54         for s in zip (range (len (src_data)), src_data):
55             src = gr.vector_source_c (s[1])
56             self.fg.connect (src, (op, s[0]))
57         dst = gr.vector_sink_c ()
58         self.fg.connect (op, dst)
59         self.fg.run ()
60         result_data = dst.data ()
61         self.assertEqual (exp_data, result_data)
62
63     def test_unmute_ii(self):
64         src_data = (1, 2, 3, 4, 5)
65         expected_result = (1, 2, 3, 4, 5)
66         op = gr.mute_ii (False)
67         self.help_ii ((src_data,), expected_result, op)
68
69     def test_mute_ii(self):
70         src_data = (1, 2, 3, 4, 5)
71         expected_result = (0, 0, 0, 0, 0)
72         op = gr.mute_ii (True)
73         self.help_ii ((src_data,), expected_result, op)
74
75     def test_unmute_cc (self):
76         src_data = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
77         expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
78         op = gr.mute_cc (False)
79         self.help_cc ((src_data,), expected_result, op)
80
81     def test_unmute_cc (self):
82         src_data = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
83         expected_result = (0+0j, 0+0j, 0+0j, 0+0j, 0+0j)
84         op = gr.mute_cc (True)
85         self.help_cc ((src_data,), expected_result, op)
86
87
88 if __name__ == '__main__':
89     gr_unittest.main ()