《构建执法》--第四次作业(结对编程)
《构建执法》--第四次作业(结对编程)
博客开头
作业要求 | https://www.cnblogs.com/harry240/p/11524113.html |
---|---|
Github地址: | https://github.com/Panghu98/WordCount.git |
结对伙伴博客: | https://www.cnblogs.com/panghu98/p/11668573.html |
PSP表格
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 20 | 25 |
·Estimate | · 估计这个任务需要多少时间 | 360 | 420 |
Development | 开发 | 270 | 300 |
· Analysis | · 需求分析 (包括学习新技术) | 20 | 20 |
· Design Spec | · 生成设计文档 | 30 | 30 |
· Design Review | · 设计复审 (和同事审核设计文档) | 30 | 30 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 | 20 |
· Design | · 具体设计 | 30 | 30 |
· Coding | · 具体编码 | 240 | 300 |
· Code Review | · 代码复审 | 30 | 30 |
· Test | · 测试(自我测试,修改代码,提交修改 | 60 | 60 |
Reporting | 报告 | 30 | 40 |
· Test Report | · 测试报告 | 30 | 30 |
· Size Measurement | · 计算工作量 | 20 | 20 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 30 | 30 |
合计 | 1210 | 1375 |
程序流程图
设计思路
-
第一步进行参数的读取(判断文件是否合法)
-
其次进行文件读取操作,将文件中的字符通过正则表达式筛选出合格的单词并统计换行符,字符的数量
-
根据输入的参数输入将结果排序
-
将结果输出到控制台和指定的文件当中
核心代码
-
-
文件读取转化为字符串
text = System.IO.File.ReadAllText(@"C:\Users\dengg\Desktop\"+textName);
-
获取字符串中字符的数量
MatchCollection charCount = Regex.Matches(text, @"(.|\n)");
-
行数统计
MatchCollection lineCount = Regex.Matches(text, @"(\n)");
-
单词数量统计
MatchCollection wordCount = Regex.Matches(text.ToLower(), @"(\b[A-z]{4,}\w*\b)");
-
排序函数
var arr = wordCount.Cast<Match>().Select(m => m.Value).ToArray().GroupBy(t => t.Trim()).Select(t => new { count = t.Count(), key = t.Key }).OrderBy(t => -t.count).ThenBy(t => t.key).ToArray(); //打印 Console.WriteLine("请输入排名限制数:"); int num = int.Parse(Console.ReadLine()); Console.WriteLine("获取排名前" + num); string str = "总字符数: " + (charCount.Count - lineCount.Count).ToString() + "\r\n" + "总词数: " + wordCount.Count + "\r\n" + "总行数: " + (lineCount.Count + 1) + "\r\n"; for (int i = 0; i < (arr.Length > num ? num : arr.Length); i++) str += arr[i].key + ":" + arr[i].count + "\r\n";
-
输出函数
using (StreamWriter sw = new StreamWriter(@"C:\Users\dengg\Desktop\"+outputFile)) sw.WriteLine(str); Console.WriteLine(str);
小结:由于程序比较简单,借助于c#强大的类库,实现整个程序只用了12行代码,但为了程序的扩展性、可测试性,还是将代码拆分成几个部分
代码规范: https://blog.csdn.net/VS18703761631/article/details/94615734
单元测试
因为直接的函数不方便测试,所以这里单独复制了一个类,功能和
WordCount
这个类功能一致
- CountWord
性能测试
- 控制台
- CPU监控图
-
热路径
-
输出结果
小结:经过性能测试我们发现整体性能效果不错,可能也是因为主要是使用的正则表达式,想要修改的复杂度也是挺高的.
个人总结
个人认为,这个程序比较简单,功能也不复杂,借助于c#的正则表达式和和一些处理泛型的api,完成全部功能只用了几行代码,但是为了单(wan)元(cheng)测(zuo)试(ye),和性能分析,最后将代码分行拆分成不同的模块,这次项目并没有让我体验到结对编程,反而更像是分工合作完成任务,所以1+1=?这个问题我还是难以回答,最后希望老师在以后结对编程的作业中能够选一些复杂的项目,好像学生充分体验到结对编程的特点
![uxBYGV.jpg](https://s2.ax1x.com/2019/10/13/uxBYGV.jpg)