Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_interleave.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004 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 import math
25
26 class test_interleave (gr_unittest.TestCase):
27
28     def setUp (self):
29         self.fg = gr.flow_graph ()
30
31     def tearDown (self):
32         self.fg = None
33
34     def test_int_001 (self):
35         lenx = 64
36         src0 = gr.vector_source_f (range (0, lenx, 4))
37         src1 = gr.vector_source_f (range (1, lenx, 4))
38         src2 = gr.vector_source_f (range (2, lenx, 4))
39         src3 = gr.vector_source_f (range (3, lenx, 4))
40         op = gr.interleave (gr.sizeof_float)
41         dst = gr.vector_sink_f ()
42
43         self.fg.connect (src0, (op, 0))
44         self.fg.connect (src1, (op, 1))
45         self.fg.connect (src2, (op, 2))
46         self.fg.connect (src3, (op, 3))
47         self.fg.connect (op, dst)
48         self.fg.run ()
49         expected_result = tuple (range (lenx))
50         result_data = dst.data ()
51         self.assertFloatTuplesAlmostEqual (expected_result, result_data)
52
53     def test_deint_001 (self):
54         lenx = 64
55         src = gr.vector_source_f (range (lenx))
56         op = gr.deinterleave (gr.sizeof_float)
57         dst0 = gr.vector_sink_f ()
58         dst1 = gr.vector_sink_f ()
59         dst2 = gr.vector_sink_f ()
60         dst3 = gr.vector_sink_f ()
61
62         self.fg.connect (src, op)
63         self.fg.connect ((op, 0), dst0)
64         self.fg.connect ((op, 1), dst1)
65         self.fg.connect ((op, 2), dst2)
66         self.fg.connect ((op, 3), dst3)
67         self.fg.run ()
68
69         expected_result0 = tuple (range (0, lenx, 4))
70         expected_result1 = tuple (range (1, lenx, 4))
71         expected_result2 = tuple (range (2, lenx, 4))
72         expected_result3 = tuple (range (3, lenx, 4))
73
74         self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ())
75         self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ())
76         self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ())
77         self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
78
79 if __name__ == '__main__':
80     gr_unittest.main ()
81