Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_feval.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006,2007 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 3, 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
25 class my_add2_dd(gr.feval_dd):
26     def eval(self, x):
27         return x + 2
28
29 class my_add2_ll(gr.feval_ll):
30     def eval(self, x):
31         return x + 2
32
33 class my_add2_cc(gr.feval_cc):
34     def eval(self, x):
35         return x + (2 - 2j)
36
37 class my_feval(gr.feval):
38     def __init__(self):
39         gr.feval.__init__(self)
40         self.fired = False
41     def eval(self):
42         self.fired = True
43
44 class test_feval(gr_unittest.TestCase):
45
46     def test_dd_1(self):
47         f = my_add2_dd()
48         src_data =        (0.0, 1.0, 2.0, 3.0, 4.0)
49         expected_result = (2.0, 3.0, 4.0, 5.0, 6.0)
50         # this is all in python...
51         actual_result = tuple([f.eval(x) for x in src_data])
52         self.assertEqual(expected_result, actual_result)
53
54     def test_dd_2(self):
55         f = my_add2_dd()
56         src_data =        (0.0, 1.0, 2.0, 3.0, 4.0)
57         expected_result = (2.0, 3.0, 4.0, 5.0, 6.0)
58         # this is python -> C++ -> python and back again...
59         actual_result = tuple([gr.feval_dd_example(f, x) for x in src_data])
60         self.assertEqual(expected_result, actual_result)
61
62         
63     def test_ll_1(self):
64         f = my_add2_ll()
65         src_data =        (0, 1, 2, 3, 4)
66         expected_result = (2, 3, 4, 5, 6)
67         # this is all in python...
68         actual_result = tuple([f.eval(x) for x in src_data])
69         self.assertEqual(expected_result, actual_result)
70
71     def test_ll_2(self):
72         f = my_add2_ll()
73         src_data =        (0, 1, 2, 3, 4)
74         expected_result = (2, 3, 4, 5, 6)
75         # this is python -> C++ -> python and back again...
76         actual_result = tuple([gr.feval_ll_example(f, x) for x in src_data])
77         self.assertEqual(expected_result, actual_result)
78
79
80     def test_cc_1(self):
81         f = my_add2_cc()
82         src_data =        (0+1j, 2+3j, 4+5j, 6+7j)
83         expected_result = (2-1j, 4+1j, 6+3j, 8+5j)
84         # this is all in python...
85         actual_result = tuple([f.eval(x) for x in src_data])
86         self.assertEqual(expected_result, actual_result)
87
88     def test_cc_2(self):
89         f = my_add2_cc()
90         src_data =        (0+1j, 2+3j, 4+5j, 6+7j)
91         expected_result = (2-1j, 4+1j, 6+3j, 8+5j)
92         # this is python -> C++ -> python and back again...
93         actual_result = tuple([gr.feval_cc_example(f, x) for x in src_data])
94         self.assertEqual(expected_result, actual_result)
95         
96     def test_void_1(self):
97         # this is all in python
98         f = my_feval()
99         f.eval()
100         self.assertEqual(True, f.fired)
101
102     def test_void_2(self):
103         # this is python -> C++ -> python and back again
104         f = my_feval()
105         gr.feval_example(f)
106         self.assertEqual(True, f.fired)
107
108
109 if __name__ == '__main__':
110     gr_unittest.main ()