3 # Copyright 2004,2007 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
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)
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.
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.
23 from gnuradio import gr, gr_unittest
26 class test_interleave (gr_unittest.TestCase):
29 self.tb = gr.top_block ()
34 def test_int_001 (self):
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 ()
43 self.tb.connect (src0, (op, 0))
44 self.tb.connect (src1, (op, 1))
45 self.tb.connect (src2, (op, 2))
46 self.tb.connect (src3, (op, 3))
47 self.tb.connect (op, dst)
49 expected_result = tuple (range (lenx))
50 result_data = dst.data ()
51 self.assertFloatTuplesAlmostEqual (expected_result, result_data)
53 def test_deint_001 (self):
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 ()
62 self.tb.connect (src, op)
63 self.tb.connect ((op, 0), dst0)
64 self.tb.connect ((op, 1), dst1)
65 self.tb.connect ((op, 2), dst2)
66 self.tb.connect ((op, 3), dst3)
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))
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 ())
79 if __name__ == '__main__':