作业要求 | https://edu.cnblogs.com/campus/jssf/infor_computation17-31/homework/10534 |
---|---|
课程目标 | 了解熟悉软件开发过程中的具体步骤,为以后的学习打下基础; 学习不同的测试方法,为以后写出更完美的代码做准备; 学会代码设计和规范。 |
实现目标的方面 | 用python写用类和函数来实现统计红楼梦主要人物统计,并将所写代码进行单元测试,回归测试,效能测试。 |
其他参考文献 | https://www.cnblogs.com/xinz/archive/2011/11/20/2255971.html https://www.cnblogs.com/xinz/archive/2011/08/07/2130332.html https://blog.csdn.net/lbj1260200629/article/details/89600055 https://blog.csdn.net/huilan_same/article/details/52944782 https://www.cnblogs.com/MonC/articles/9744687.html https://blog.csdn.net/LWT000aa/article/details/78735235 https://blog.csdn.net/weixin_43936464/article/details/84779924 |
作业正文 | https://www.cnblogs.com/youmine/p/12635776.html 码云链接https://gitee.com/yang_li_na/masterwork |
作业1
评论链接:
https://www.cnblogs.com/youmine/MyComments.html
作业2 结对编程
队友:
https://www.cnblogs.com/lmengmeng/p/12613590.html
红楼梦人物统计
# 红楼梦人物统计 import jieba import csv import pstats import profile class NameCount(): def getNameTimesSort(self, name_list, txt_path): # 添加jieba分词 mydict = ['琏二奶奶', '凤哥儿', '凤丫头', '宝姑娘', '颦儿', '二姑娘', '三姑娘', '四姑娘', '云妹妹', '蓉大奶奶'] for item in mydict: jieba.add_word(item) #打开并读取txt文件 txt = open('redstone.txt','r',encoding='utf-8').read() # 定义别名列表 bieming = [["王熙凤", "凤丫头", '琏二奶奶', '凤姐', '凤哥儿', '凤辣子','熙凤'],["林妹妹", "黛玉", '林姑娘', '林黛玉'], ["宝钗", '宝姑娘', '宝丫头', '宝姐姐', '薛宝钗'], ['探春', '三姑娘', '贾探春'], ['湘云', '云妹妹', '史湘云'],['迎春', '二姑娘', '贾迎春'],['元春', '大姑娘', '娘娘', '贵妃', '元妃', '贾元春'], ['惜春', '四姑娘', '贾惜春'], ['妙玉'],['巧姐'], ['李纨', '大嫂子'], ['秦可卿', '可卿', '蓉大奶奶']] words = jieba.lcut(txt) counts = {} for word in words: if len(word) == 1: continue else: counts[word] = counts.get(word, 0) + 1 # 计算出场次数(各个别名的合计次数) lst = list() for i in range(12): lt = 0 for item in bieming[i]: lt += counts.get(item, 0) lst.append(lt) items = list() for i in range(12): items.append([name_list[i], lst[i]]) items.sort(key=lambda x: x[1], reverse=True) f = open('红楼梦人物统计.csv', 'w', newline='', encoding='utf-8') csv_writer = csv.writer(f) csv_writer.writerow(['红楼梦人物统计']) csv_writer.writerow(["姓名", "出现次数"]) for i in range(12): word, count = items[i] csv_writer.writerow([word, count]) print("{0:<10}{1:>5}".format(word, count)) f.close() return items if __name__ == '__main__': # 参与统计的人名列表,可修改成自己想要的列表 name_list = ['熙凤', '黛玉', '宝钗', '探春', '湘云', '迎春', '元春', '惜春', '妙玉', '巧姐', '李纨', '可卿'] # txt文件所在路径 txt_path = 'redstone.txt' NameCount().getNameTimesSort(name_list,txt_path)
红楼梦单元测试
import unittest from red2 import * class MyTestCase(unittest.TestCase): def setUp(self): print("测试开始") def test_something(self): name_list = ['熙凤', '黛玉', '宝钗', '探春', '湘云', '迎春', '元春', '惜春', '妙玉', '巧姐', '李纨', '可卿'] txt_path = 'redstone.txt' name_list_count = [1149, 953, 696, 448, 393, 146, 126, 105, 81, 40, 36, 14] items = list() for i in range(12): items.append([name_list[i], name_list_count[i]]) self.assertEqual(items, NameCount().getNameTimesSort(name_list,txt_path)) def tearDown(self): print("测试结束") if __name__ == '__main__': unittest.main()
红楼梦回归测试
page.py块
#-*- coding:utf-8 -*- from selenium import webdriver import time #打开浏览器 path = "C:\\Users\xxx\AppData\Local\Google\Chrome\Application\chromedriver.exe" driver = webdriver.Chrome(executable_path=path) #driver = webdriver.Chrome() #最大化窗口 driver.maximize_window() #打开百度 driver.get("http://www.baidu.com") #休眠一秒 time.sleep(10) #关闭浏览器 driver.close()
suit.py块
# -*- coding:utf-8 -*- import unittest from red2 import * import page import testcase import HTMLTestRunner class MyTestCase(unittest.TestCase): def setUp(self): print("测试开始") def test_something(self): name_list = ['熙凤', '黛玉', '宝钗', '探春', '湘云', '迎春', '元春', '惜春', '妙玉', '巧姐', '李纨', '可卿'] txt_path = 'redstone.txt' name_list_count = [1149, 953, 696, 448, 393, 146, 126, 105, 81, 40, 36, 14] items = list() for i in range(12): items.append([name_list[i], name_list_count[i]]) self.assertEqual(items, NameCount().getNameTimesSort(name_list,txt_path)) def tearDown(self): print("测试结束") if __name__ == '__main__': testunit = unittest.TestSuite() testunit.addTest(MyTestCase('test_something')) filename = 'resultest.html' fp = open(filename, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'红楼梦人物统计', description=u'用例执行') runner.run(testunit) fp.close()
红楼梦效能测试
import pstats import profile from red2 import* if __name__ == '__main__': print("效能测试:") profile.run('NameCount()', 'result') # 直接把分析结果打印到控制台 p = pstats.Stats('result') # 创建Stats对象 p.strip_dirs().sort_stats("call").print_stats() # 按照调用的次数排序 p.strip_dirs().sort_stats("cumulative").print_stats() # 按执行时间次数排序
表格(csv)统计以及人物出场次数的图像
水浒传人物统计和效能测试
# 水浒传人物统计 import jieba import csv import pstats import profile class NameCount(): def getNameTimesSort(self, name_list, txt_path): # 添加jieba分词 mydict = ['及时雨','黑旋风','行者','豹子头','花和尚','智多星','玉麒麟','小旋风','小李广','九纹龙','青面兽','母大虫','母夜叉','王教头','扈三娘','陆虞候'] for item in mydict: jieba.add_word(item) #打开并读取txt文件 txt = open('water.txt','r',encoding='utf-8').read() # 定义别名列表 bieming = [['及时雨','宋江','呼保义','孝义黑三郎','宋公明','宋押司'],['黑旋风','李逵','铁牛'],['武松','武二郎','行者','武行者','武都头'],['豹子头','林冲','林教头'], [ '鲁提辖' ,'鲁达','智深','花和尚','鲁智深'],['智多星','吴用','吴学究','吴加亮','赛诸葛','加亮先生'],['卢俊义','玉麒麟','卢员外'],[ '小旋风','柴进'], ['花荣','小李广'],['九纹龙','史进'],['杨志','杨制使','杨提辖','青面兽'],['顾大嫂','母大虫'],['孙二娘','母夜叉'],['王进','王教头'],['扈三娘','一丈青'],['陆虞候','陆谦']] words = jieba.lcut(txt) counts = {} for word in words: if len(word) == 1: continue else: counts[word] = counts.get(word, 0) + 1 # 计算出场次数(各个别名的合计次数) lst = list() for i in range(16): lt = 0 for item in bieming[i]: lt += counts.get(item, 0) lst.append(lt) items = list() for i in range(16): items.append([name_list[i], lst[i]]) items.sort(key=lambda x: x[1], reverse=True) f = open('水浒传人物统计.csv', 'w', newline='', encoding='utf-8') csv_writer = csv.writer(f) csv_writer.writerow(['水浒传人物统计']) csv_writer.writerow(["姓名", "出现次数"]) for i in range(16): word, count = items[i] csv_writer.writerow([word, count]) print("{0:<10}{1:>5}".format(word, count)) f.close() return items if __name__ == '__main__': # 参与统计的人名列表,可修改成自己想要的列表 name_list = ['宋江','李逵','武松','林冲','鲁智深','吴用','卢俊义','柴进','花荣','史进','杨志','顾大嫂','孙二娘','王进','扈三娘','陆谦'] # txt文件所在路径 txt_path = 'water.txt' NameCount().getNameTimesSort(name_list,txt_path) print("效能测试:") profile.run('NameCount()', 'result') # 直接把分析结果打印到控制台 p = pstats.Stats('result') # 创建Stats对象 p.strip_dirs().sort_stats("call").print_stats() # 按照调用的次数排序 p.strip_dirs().sort_stats("cumulative").print_stats() # 按执行时间次数排序
水浒传单元测试
import unittest from water3 import * class MyTestCase(unittest.TestCase): def setUp(self): print("测试开始") def test_something(self): name_list = ['宋江','李逵','武松','林冲','鲁智深','吴用','卢俊义','柴进','花荣','史进','杨志','顾大嫂','孙二娘','王进','扈三娘','陆谦'] txt_path = 'water.txt' name_list_count = [2765, 1247, 1151, 759, 647, 639, 632, 328, 260, 242, 239, 105, 74, 68, 52, 47] items = list() for i in range(16): items.append([name_list[i], name_list_count[i]]) self.assertEqual(items, NameCount().getNameTimesSort(name_list,txt_path)) def tearDown(self): print("测试结束") if __name__ == '__main__': unittest.main()
水浒传回归测试
suit.py
# -*- coding:utf-8 -*- import unittest from water3 import * import page import testwater import HTMLTestRunner class MyTestCase(unittest.TestCase): def setUp(self): print("测试开始") def test_something(self): name_list = ['宋江','李逵','武松','林冲','鲁智深','吴用','卢俊义','柴进','花荣','史进','杨志','顾大嫂','孙二娘','王进','扈三娘','陆谦'] txt_path = 'water.txt' name_list_count = [2765, 1247, 1151, 759, 647, 639, 632, 328, 260, 242, 239, 105, 74, 68, 52, 47] items = list() for i in range(16): items.append([name_list[i], name_list_count[i]]) self.assertEqual(items, NameCount().getNameTimesSort(name_list,txt_path)) def tearDown(self): print("测试结束") if __name__ == '__main__': testunit = unittest.TestSuite() testunit.addTest(MyTestCase('test_something')) filename = 'resulwater.html' fp = open(filename, 'wb') runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title=u'水浒传人物统计', description=u'用例执行') runner.run(testunit) fp.close()
表格(csv)统计以及水浒传人物出场次数的图像
PSP | Personal Software Process Stages | Time |
---|---|---|
Planning | 计划 | |
·Estimate | ·估计这个任务需要多少时间 | 168h |
Development | 开发 | |
·Analysis | ·需求分析(包括学习新技术) | 6h |
·Design Spec | ·生成设计文档 | 1h |
·Design Review | ·设计复审(和同学审核设计文档) | 1h |
·Design Standard | ·代码规范(为目前的开发制定合适的规范) | 0.5h |
·Design | ·具体设计 | 4h |
·Coding | ·具体编码 | 48h |
·Code Review | ·代码复审 | 24h |
·Test | ·测试(自我测试,修改代码,提交修改) | 72h |
Reporting | 报告 | |
·Test Reportt | ·测试报告 | 1.5h |
·Size Measurement | ·计算工作量 | 0.5h |
·Postmortem&Process Improvement Plan | ·事后总结,并提出过程改进计划 | 0.5h |
合计 | 189h |
总结:本次作业中需要运用python软件来书写,统计人物时要用到jieba库,在回归测试中需要用到webdriver、selenium库、HTMLTestRunner(注意python2和python3之间的区别)。
来源:https://www.cnblogs.com/youmine/p/12635776.html