3 # Copyright 2006,2007,2010 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
27 def make_random_int_tuple(L, min, max):
30 result.append(random.randint(min, max))
34 class test_diff_encoder (gr_unittest.TestCase):
37 self.tb = gr.top_block ()
42 def test_diff_encdec_000(self):
45 src_data = make_random_int_tuple(1000, 0, modulus-1)
46 expected_result = src_data
47 src = gr.vector_source_b(src_data)
48 enc = gr.diff_encoder_bb(modulus)
49 dec = gr.diff_decoder_bb(modulus)
50 dst = gr.vector_sink_b()
51 self.tb.connect(src, enc, dec, dst)
52 self.tb.run() # run the graph and wait for it to finish
53 actual_result = dst.data() # fetch the contents of the sink
54 self.assertEqual(expected_result, actual_result)
56 def test_diff_encdec_001(self):
59 src_data = make_random_int_tuple(1000, 0, modulus-1)
60 expected_result = src_data
61 src = gr.vector_source_b(src_data)
62 enc = gr.diff_encoder_bb(modulus)
63 dec = gr.diff_decoder_bb(modulus)
64 dst = gr.vector_sink_b()
65 self.tb.connect(src, enc, dec, dst)
66 self.tb.run() # run the graph and wait for it to finish
67 actual_result = dst.data() # fetch the contents of the sink
68 self.assertEqual(expected_result, actual_result)
70 def test_diff_encdec_002(self):
73 src_data = make_random_int_tuple(40000, 0, modulus-1)
74 expected_result = src_data
75 src = gr.vector_source_b(src_data)
76 enc = gr.diff_encoder_bb(modulus)
77 dec = gr.diff_decoder_bb(modulus)
78 dst = gr.vector_sink_b()
79 self.tb.connect(src, enc, dec, dst)
80 self.tb.run() # run the graph and wait for it to finish
81 actual_result = dst.data() # fetch the contents of the sink
82 self.assertEqual(expected_result, actual_result)
84 if __name__ == '__main__':
85 gr_unittest.run(test_diff_encoder, "test_diff_encoder.xml")