Python测试驱动编写
2016-03-16 15:33
489 查看
通过gr_modtool会自动生成测试驱动程序的模板,只需要修改模板即可,模板如下:
我们需要做的就是补充test_001_t()函数:构建流图、给出测试数据以及预期结果、运行流图、将实际结果与预期结果I进行比较。修改好的程序如下:
from gnuradio import gr, gr_unittest from gnuradio import blocks import double_diff_swig as double_diff class qa_translate (gr_unittest.TestCase): def setUp (self): self.tb = gr.top_block () def tearDown (self): self.tb = None def test_001_t (self): # set up fg self.tb.run () # check data if __name__ == '__main__': gr_unittest.run(qa_translate, "qa_translate.xml")这里module的名称为double_diff,block的名称为translate。
我们需要做的就是补充test_001_t()函数:构建流图、给出测试数据以及预期结果、运行流图、将实际结果与预期结果I进行比较。修改好的程序如下:
from gnuradio import gr, gr_unittest from gnuradio import blocks import double_diff class qa_translate (gr_unittest.TestCase): def setUp (self): self.tb = gr.top_block () def tearDown (self): self.tb = None def test_001_t (self): src_data=[1,-1,-1,1,1,-1] expected_ampl=(1,1,1,1,1,1) expected_phase=(0,1,1,0,0,1) src=blocks.vector_source_c(src_data) op=double_diff.translate() dst0=blocks.vector_sink_f() dst1=blocks.vector_sink_f() self.tb.connect(src,op) self.tb.connect((op,0),dst0) self.tb.connect((op,1),dst1) # set up fg self.tb.run () # check data result_ampl=dst0.data() result_phase=dst1.data() self.assertEqual(expected_ampl,result_ampl) self.assertEqual(expected_phase,result_phase) if __name__ == '__main__': gr_unittest.run(qa_translate, "qa_translate.xml")运行结果:
相关文章推荐
- python学习6 web开发
- 【算法】-8大排序算法总结-Python
- python面向对象高级编程
- 用numpy里的savetxt()
- python数据持久存储:pickle模块的基本使用
- Parallel Python(PP)并行计算测试
- Python串行运算、并行运算、多线程、多进程对比实验
- Python 高级编程笔记之类别
- Python工程师面试题集合
- 探索Python数据分析(一):NLTK库和文本处理
- 【python】编程学习练习题--3
- 10.python之socket和socketserver
- Python 模块学习:os模块
- 大数据处理之道(十分钟学会Python)
- 将Python脚本打包成可执行文件
- python超大数计算
- python学习5 常用三方模块
- Python 断言assert的使用
- Python学习笔记——数字
- python获取及时可用国外高匿名代理