diff options
author | Tom Rondeau | 2012-01-28 15:11:50 -0500 |
---|---|---|
committer | Tom Rondeau | 2012-01-28 15:11:50 -0500 |
commit | c9a420645f16f5c28fdcf05c1c09b9a91b95e640 (patch) | |
tree | 717d1ac50119ad8f78c3f43c099445d2709622f3 | |
parent | 7943c197eccdb16e6c42af5544b9cb34a089b360 (diff) | |
download | gnuradio-c9a420645f16f5c28fdcf05c1c09b9a91b95e640.tar.gz gnuradio-c9a420645f16f5c28fdcf05c1c09b9a91b95e640.tar.bz2 gnuradio-c9a420645f16f5c28fdcf05c1c09b9a91b95e640.zip |
core: QA codes for float_to_X and short_to_X (note: float_to_int needs work).
5 files changed, 197 insertions, 4 deletions
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py index 45df71d0a..ecdd36228 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_char.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2011 Free Software Foundation, Inc. +# Copyright 2011,2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -59,6 +59,24 @@ class test_float_to_char (gr_unittest.TestCase): self.assertEqual(expected_result, result_data) + def test_003(self): + + scale = 2 + vlen = 3 + src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) + expected_result = [0, 2, 4, 6, 8, 11, 254, 252, 250] + src = gr.vector_source_f(src_data) + s2v = gr.stream_to_vector(gr.sizeof_float, vlen) + op = gr.float_to_char(vlen, scale) + v2s = gr.vector_to_stream(gr.sizeof_char, vlen) + dst = gr.vector_sink_b() + + self.tb.connect(src, s2v, op, v2s, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_float_to_char, "test_float_to_char.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py index 4cc3d0056..559f90f05 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_int.py @@ -33,7 +33,6 @@ class test_float_to_int (gr_unittest.TestCase): def test_001(self): src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3, -4.4, -5.5) - expected_result = [int(round(s)) for s in src_data] ### Volk results expected_result = [0, 1, 2, 3, 4, 6, -1, -2, -3, -4, -5] @@ -53,7 +52,7 @@ class test_float_to_int (gr_unittest.TestCase): src_data = ( 2146400000, 2147483647, -2146400000, -2147483648 ) expected_result = [ 2146400000, 2146400000, - -2146400000, -2146400000 ] + -2146400000, -2147483648 ] src = gr.vector_source_f(src_data) op = gr.float_to_int() dst = gr.vector_sink_i() @@ -64,6 +63,25 @@ class test_float_to_int (gr_unittest.TestCase): self.assertEqual(expected_result, result_data) + + def test_003(self): + + scale = 2 + vlen = 3 + src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) + expected_result = [0, 2, 4, 7, 9, 11, -2, -4, -6,] + src = gr.vector_source_f(src_data) + s2v = gr.stream_to_vector(gr.sizeof_float, vlen) + op = gr.float_to_int(vlen, scale) + v2s = gr.vector_to_stream(gr.sizeof_int, vlen) + dst = gr.vector_sink_i() + + self.tb.connect(src, s2v, op, v2s, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_float_to_int, "test_float_to_int.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py index aa26668c8..926f1c08b 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_float_to_short.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2011 Free Software Foundation, Inc. +# Copyright 2011,2012 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -66,6 +66,24 @@ class test_float_to_short (gr_unittest.TestCase): self.assertEqual(expected_result, result_data) + def test_003(self): + + scale = 2 + vlen = 3 + src_data = (0.0, 1.1, 2.2, 3.3, 4.4, 5.5, -1.1, -2.2, -3.3) + expected_result = [0, 2, 4, 7, 9, 11, -2, -4, -6] + src = gr.vector_source_f(src_data) + s2v = gr.stream_to_vector(gr.sizeof_float, vlen) + op = gr.float_to_short(vlen, scale) + v2s = gr.vector_to_stream(gr.sizeof_short, vlen) + dst = gr.vector_sink_s() + + self.tb.connect(src, s2v, op, v2s, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + if __name__ == '__main__': gr_unittest.run(test_float_to_short, "test_float_to_short.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py new file mode 100755 index 000000000..6a95fa01d --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_char.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# +# Copyright 2011,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import ctypes + +class test_short_to_char (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + + src_data = range(0, 32767, 32767/127) + src_data = [int(s) for s in src_data] + expected_result = range(0, 128) + src = gr.vector_source_s(src_data) + op = gr.short_to_char() + dst = gr.vector_sink_b() + + self.tb.connect(src, op, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + + def test_002(self): + + vlen = 3 + src_data = range(0, 32400, 32767/127) + src_data = [int(s) for s in src_data] + expected_result = range(0, 126) + src = gr.vector_source_s(src_data) + s2v = gr.stream_to_vector(gr.sizeof_short, vlen) + op = gr.short_to_char(vlen) + v2s = gr.vector_to_stream(gr.sizeof_char, vlen) + dst = gr.vector_sink_b() + + self.tb.connect(src, s2v, op, v2s, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_short_to_char, "test_short_to_char.xml") + diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py new file mode 100755 index 000000000..8f331b495 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_short_to_float.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# +# Copyright 2011,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import ctypes + +class test_short_to_float (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + + src_data = (0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5) + expected_result = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, + -1.0, -2.0, -3.0, -4.0, -5.0] + + src = gr.vector_source_s(src_data) + op = gr.short_to_float() + dst = gr.vector_sink_f() + + self.tb.connect(src, op, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + + def test_002(self): + + vlen = 3 + src_data = (0, 1, 2, 3, 4, 5, -1, -2, -3) + expected_result = [0.0, 1.0, 2.0, 3.0, 4.0, + 5.0, -1.0, -2.0, -3.0] + src = gr.vector_source_s(src_data) + s2v = gr.stream_to_vector(gr.sizeof_short, vlen) + op = gr.short_to_float(vlen) + v2s = gr.vector_to_stream(gr.sizeof_float, vlen) + dst = gr.vector_sink_f() + + self.tb.connect(src, s2v, op, v2s, dst) + self.tb.run() + result_data = list(dst.data()) + + self.assertEqual(expected_result, result_data) + +if __name__ == '__main__': + gr_unittest.run(test_short_to_float, "test_short_to_float.xml") + |