Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_feval.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006 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 2, 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
38 class test_feval(gr_unittest.TestCase):
39
40     def test_dd_1(self):
41         f = my_add2_dd()
42         src_data =        (0.0, 1.0, 2.0, 3.0, 4.0)
43         expected_result = (2.0, 3.0, 4.0, 5.0, 6.0)
44         # this is all in python...
45         actual_result = tuple([f.eval(x) for x in src_data])
46         self.assertEqual(expected_result, actual_result)
47
48     def test_dd_2(self):
49         f = my_add2_dd()
50         src_data =        (0.0, 1.0, 2.0, 3.0, 4.0)
51         expected_result = (2.0, 3.0, 4.0, 5.0, 6.0)
52         # this is python -> C++ -> python and back again...
53         actual_result = tuple([gr.feval_dd_example(f, x) for x in src_data])
54         self.assertEqual(expected_result, actual_result)
55
56         
57     def test_ll_1(self):
58         f = my_add2_ll()
59         src_data =        (0, 1, 2, 3, 4)
60         expected_result = (2, 3, 4, 5, 6)
61         # this is all in python...
62         actual_result = tuple([f.eval(x) for x in src_data])
63         self.assertEqual(expected_result, actual_result)
64
65     def test_ll_2(self):
66         f = my_add2_ll()
67         src_data =        (0, 1, 2, 3, 4)
68         expected_result = (2, 3, 4, 5, 6)
69         # this is python -> C++ -> python and back again...
70         actual_result = tuple([gr.feval_ll_example(f, x) for x in src_data])
71         self.assertEqual(expected_result, actual_result)
72
73
74     def test_cc_1(self):
75         f = my_add2_cc()
76         src_data =        (0+1j, 2+3j, 4+5j, 6+7j)
77         expected_result = (2-1j, 4+1j, 6+3j, 8+5j)
78         # this is all in python...
79         actual_result = tuple([f.eval(x) for x in src_data])
80         self.assertEqual(expected_result, actual_result)
81
82     def test_cc_2(self):
83         f = my_add2_cc()
84         src_data =        (0+1j, 2+3j, 4+5j, 6+7j)
85         expected_result = (2-1j, 4+1j, 6+3j, 8+5j)
86         # this is python -> C++ -> python and back again...
87         actual_result = tuple([gr.feval_cc_example(f, x) for x in src_data])
88         self.assertEqual(expected_result, actual_result)
89         
90
91 if __name__ == '__main__':
92     gr_unittest.main ()