Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_argmax.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007 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
27 class test_sig_source (gr_unittest.TestCase):
28
29     def setUp (self):
30         self.tb = gr.top_block ()
31
32
33     def tearDown (self):
34         self.tb = None
35
36
37     def test_001(self):
38         tb = self.tb
39
40         src1_data = (0,0.2,-0.3,0,12,0)
41         src2_data = (0,0.0,3.0,0,10,0)
42         src3_data = (0,0.0,3.0,0,1,0)
43
44         src1 = gr.vector_source_f (src1_data)
45         s2v1 = gr.stream_to_vector(gr.sizeof_float, len(src1_data))
46         tb.connect( src1, s2v1 )
47
48         src2 = gr.vector_source_f (src2_data)
49         s2v2 = gr.stream_to_vector(gr.sizeof_float, len(src1_data))
50         tb.connect( src2, s2v2 )
51
52         src3 = gr.vector_source_f (src3_data)
53         s2v3 = gr.stream_to_vector(gr.sizeof_float, len(src1_data))
54         tb.connect( src3, s2v3 )
55
56         dst1 = gr.vector_sink_s ()
57         dst2 = gr.vector_sink_s ()
58         argmax = gr.argmax_fs (len(src1_data))
59
60         tb.connect (s2v1, (argmax, 0))
61         tb.connect (s2v2, (argmax, 1))
62         tb.connect (s2v3, (argmax, 2))
63
64         tb.connect ((argmax,0), dst1)
65         tb.connect ((argmax,1), dst2)
66
67         tb.run ()
68         index = dst1.data ()
69         source = dst2.data ()
70         self.assertEqual ( index, (4,))
71         self.assertEqual ( source, (0,))
72
73
74
75 if __name__ == '__main__':
76     gr_unittest.main ()
77