3 # Copyright 2004 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_sig_source (gr_unittest.TestCase):
29 self.fg = gr.flow_graph ()
34 def test_const_f (self):
36 expected_result = (1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5)
37 src1 = gr.sig_source_f (1e6, gr.GR_CONST_WAVE, 0, 1.5)
38 op = gr.head (gr.sizeof_float, 10)
39 dst1 = gr.vector_sink_f ()
43 dst_data = dst1.data ()
44 self.assertEqual (expected_result, dst_data)
46 def test_const_i (self):
48 expected_result = (1, 1, 1, 1)
49 src1 = gr.sig_source_i (1e6, gr.GR_CONST_WAVE, 0, 1)
50 op = gr.head (gr.sizeof_int, 4)
51 dst1 = gr.vector_sink_i ()
55 dst_data = dst1.data ()
56 self.assertEqual (expected_result, dst_data)
58 def test_sine_f (self):
60 sqrt2 = math.sqrt(2) / 2
61 expected_result = (0, sqrt2, 1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0)
62 src1 = gr.sig_source_f (8, gr.GR_SIN_WAVE, 1.0, 1.0)
63 op = gr.head (gr.sizeof_float, 9)
64 dst1 = gr.vector_sink_f ()
68 dst_data = dst1.data ()
69 self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
71 def test_cosine_f (self):
73 sqrt2 = math.sqrt(2) / 2
74 expected_result = (1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0, sqrt2, 1)
75 src1 = gr.sig_source_f (8, gr.GR_COS_WAVE, 1.0, 1.0)
76 op = gr.head (gr.sizeof_float, 9)
77 dst1 = gr.vector_sink_f ()
81 dst_data = dst1.data ()
82 self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 5)
84 if __name__ == '__main__':