3 # Copyright 2004,2007,2008 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
25 class test_head (gr_unittest.TestCase):
28 self.tb = gr.top_block ()
33 def help_ss (self, src_data, exp_data, op):
34 for s in zip (range (len (src_data)), src_data):
35 src = gr.vector_source_s (s[1])
36 self.tb.connect (src, (op, s[0]))
37 dst = gr.vector_sink_s ()
38 self.tb.connect (op, dst)
40 result_data = dst.data ()
41 self.assertEqual (exp_data, result_data)
43 def help_bb (self, src_data, exp_data, op):
44 for s in zip (range (len (src_data)), src_data):
45 src = gr.vector_source_b (s[1])
46 self.tb.connect (src, (op, s[0]))
47 dst = gr.vector_sink_b ()
48 self.tb.connect (op, dst)
50 result_data = dst.data ()
51 self.assertEqual (exp_data, result_data)
53 def help_ii (self, src_data, exp_data, op):
54 for s in zip (range (len (src_data)), src_data):
55 src = gr.vector_source_i (s[1])
56 self.tb.connect (src, (op, s[0]))
57 dst = gr.vector_sink_i ()
58 self.tb.connect (op, dst)
60 result_data = dst.data ()
61 self.assertEqual (exp_data, result_data)
63 def test_xor_ss (self):
64 src1_data = (1, 2, 3, 0x5004, 0x1150)
65 src2_data = (8, 2, 1 , 0x0508, 0x1105)
66 expected_result = (9, 0, 2, 0x550C, 0x0055)
68 self.help_ss ((src1_data, src2_data),
71 def test_xor_bb (self):
72 src1_data = (1, 2, 3, 4, 0x50)
73 src2_data = (8, 2, 1 , 8, 0x05)
74 expected_result = (9, 0, 2, 0xC, 0x55)
76 self.help_bb ((src1_data, src2_data),
80 def test_xor_ii (self):
81 src1_data = (1, 2, 3, 0x5000004, 0x11000050)
82 src2_data = (8, 2, 1 , 0x0500008, 0x11000005)
83 expected_result = (9, 0, 2, 0x550000C, 0x00000055)
85 self.help_ii ((src1_data, src2_data),
88 def test_and_ss (self):
89 src1_data = (1, 2, 3, 0x5004, 0x1150)
90 src2_data = (8, 2, 1 , 0x0508, 0x1105)
91 expected_result = (0, 2, 1, 0x0000, 0x1100)
93 self.help_ss ((src1_data, src2_data),
96 def test_and_bb (self):
97 src1_data = (1, 2, 2, 3, 0x04, 0x50)
98 src2_data = (8, 2, 2, 1, 0x08, 0x05)
99 src3_data = (8, 2, 1, 1, 0x08, 0x05)
100 expected_result = (0, 2, 0, 1, 0x00, 0x00)
102 self.help_bb ((src1_data, src2_data, src3_data),
105 def test_and_ii (self):
106 src1_data = (1, 2, 3, 0x50005004, 0x11001150)
107 src2_data = (8, 2, 1 , 0x05000508, 0x11001105)
108 expected_result = (0, 2, 1, 0x00000000, 0x11001100)
110 self.help_ii ((src1_data, src2_data),
113 def test_or_ss (self):
114 src1_data = (1, 2, 3, 0x5004, 0x1150)
115 src2_data = (8, 2, 1 , 0x0508, 0x1105)
116 expected_result = (9, 2, 3, 0x550C, 0x1155)
118 self.help_ss ((src1_data, src2_data),
121 def test_or_bb (self):
122 src1_data = (1, 2, 2, 3, 0x04, 0x50)
123 src2_data = (8, 2, 2, 1 , 0x08, 0x05)
124 src3_data = (8, 2, 1, 1 , 0x08, 0x05)
125 expected_result = (9, 2, 3, 3, 0x0C, 0x55)
127 self.help_bb ((src1_data, src2_data, src3_data),
130 def test_or_ii (self):
131 src1_data = (1, 2, 3, 0x50005004, 0x11001150)
132 src2_data = (8, 2, 1 , 0x05000508, 0x11001105)
133 expected_result = (9, 2, 3, 0x5500550C, 0x11001155)
135 self.help_ii ((src1_data, src2_data),
138 def test_not_ss (self):
139 src1_data = (1, 2, 3, 0x5004, 0x1150)
140 expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150)
142 self.help_ss ((((src1_data),)),
145 def test_not_bb (self):
146 src1_data = (1, 2, 2, 3, 0x04, 0x50)
147 expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF)
149 self.help_bb (((src1_data), ),
152 def test_not_ii (self):
153 src1_data = (1, 2, 3, 0x50005004, 0x11001150)
154 expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150)
156 self.help_ii (((src1_data),),
161 if __name__ == '__main__':