python功能测试
来源:互联网 发布:skype mac 旧版本 编辑:程序博客网 时间:2024/06/01 09:59
功能函数:
文件名removeSame.py
def remove_shared(L1, L2): """ (list list) Remove items from L1 that are in both L1 and L2. >>> list_1 = [1, 2, 3, 4, 5, 6] >>> list_2 = [2, 4, 5, 7] >>> remove_shared(list_1, list_2) >>> list_1 [1, 3, 6] >>> list_2 [2, 4, 5, 7] """ for v in L2: if v in L1: L1.remove(v)if __name__ == '__main__': import doctest doctest.testmod()
测试函数:
文件名test_removeSame.py
import unittestimport removeSameclass TestRemoveShared(unittest.TestCase): #要以unittest.TestCase作为基类 """Tests for function duplicates.remove_shared.""" def test_general_case(self):"""Test remove_shared where there are items that
appear in both lists, and items that appear in
only one or the other list. """
list_1 = [1, 2, 3, 4, 5, 6]
list_2 = [2, 4, 5, 7]
list_1_expected = [1, 3, 6]
list_2_expected = [2, 4, 5, 7]
removeSame.remove_shared(list_1, list_2)
self.assertEqual(list_1, list_1_expected)
self.assertEqual(list_2, list_2_expected)
def test_general_case2(self): """ Test remove_shared where there are items that appear in both lists, and items that appear in only one or the other list. """ list_1 = [1, 2, 3, 4, 5, 6] list_2 = [2, 4, 5, 7] list_1_expected = [1, 3, 6] list_2_expected = [2, 4, 5, 7] removeSame.remove_shared(list_1, list_2) self.assertEqual(list_1, list_1_expected) self.assertEqual(list_2, list_2_expected)if __name__ == '__main__':
unittest.main(exit=False)
阅读全文
0 0
- python功能测试
- Python UnitTest 框架执行功能自动化测试
- 使用python来做第一个简单的功能测试
- 测试 功能
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- 功能测试
- sdsad
- 关于百度地图点聚合的问题
- ExtJs常用控件属性
- bzoj1914 Triangle Counting 数三角形【极角排序】
- DB2
- python功能测试
- 大数据案例二详解 基于大数据技术的全国高速公路通行数据 动态监测平台建设
- 水仙花数
- 数组灌水问题
- Android 端外推送到底有多烦?
- Thrift 客户端 JAVA
- spark 单词统计
- Git教程
- android项目从零开始 TextView setTextColor等背景选择器设置失败问题