构建执法--第四次作业《结对编程》

《构建执法》--第四次作业(结对编程)

博客开头

作业要求 https://www.cnblogs.com/harry240/p/11524113.html
Github地址: https://github.com/Panghu98/WordCount.git
结对伙伴博客: https://www.cnblogs.com/humblezx/p/11670349.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

程序流程图

u7Uc1f.png

设计思路

  • 第一步进行参数的读取(判断文件是否合法)

  • 其次进行文件读取操作,将文件中的字符通过正则表达式筛选出合格的单词并统计换行符,字符的数量

  • 根据输入的参数输入将结果排序

  • 将结果输出到控制台和指定的文件当中


核心代码

  • 文件读取转化为字符串

    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().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);




**小结**:整体代码比较简洁,函数调用关系很明确,对单词筛选的关键在于正则表达式的灵活使用.整体只是用了一个类,类的调用关系如下.

![uxk5qI.png](https://s2.ax1x.com/2019/10/13/uxk5qI.png)







**代码规范**:[代码规范要求博客](https://blog.csdn.net/VS18703761631/article/details/94615734 )



## 单元测试

> 因为直接的函数不方便测试,所以这里单独复制了一个类,功能和`WordCount`这个类功能一致

- **CountWord**

[![ux8LWj.png](https://s2.ax1x.com/2019/10/13/ux8LWj.png)](https://imgchr.com/i/ux8LWj)

- **Print**
[![ux8bFg.png](https://s2.ax1x.com/2019/10/13/ux8bFg.png)](https://imgchr.com/i/ux8bFg)

- **ReadText**

[![ux8qYQ.png](https://s2.ax1x.com/2019/10/13/ux8qYQ.png)](https://imgchr.com/i/ux8qYQ)

- **综合结果**
[![ux87TS.png](https://s2.ax1x.com/2019/10/13/ux87TS.png)](https://imgchr.com/i/ux87TS)



-----

## 性能测试

- 控制台

<img src="https://s2.ax1x.com/2019/10/13/uxw0lF.png" alt="uxw0lF.png" style="zoom:50%;" />

- CPU监控图

                          <img src="https://s2.ax1x.com/2019/10/13/uxCM0f.png" alt="uxCM0f.png" style="zoom:40%;" />    

- 热路径

![ux0Smj.png](https://s2.ax1x.com/2019/10/13/ux0Smj.png)



- 输出结果

![ux0wNt.png](https://s2.ax1x.com/2019/10/13/ux0wNt.png)

> **小结**:经过性能测试我们发现整体性能效果不错,可能也是因为主要是使用的正则表达式,想要修改的复杂度也是挺高的.



----



## 个人总结

从自己的角度而言,感觉这个项目比较小,不能很好的体现出1+1 > 2 ,也只能是说1 +1 略大于 2,主要是很多的工作单元比较小,两个人完成反而晓得有点臃肿,但是相对来说在一定程度上减小了自己的工作量,也是在一定程度上改善了共同的代码质量,感觉结对编程还是很有意思,可以向别人分享自己的想法,同时也要学会了解别人的开发.这其中也有一个适应的过程,毕竟每个人都有自己的风格,如何是的团队利益最大化,才是需要考虑的大问题.



<img src="https://s2.ax1x.com/2019/10/13/uxBYGV.jpg" alt="uxBYGV.jpg" style="zoom:50%;" />
posted on 2019-10-13 21:48  叫我胖虎大人  阅读(140)  评论(3编辑  收藏  举报